protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.Parameter != null)
            {
                WeatherView = e.Parameter as WeatherNowViewModel;
            }
        }
示例#2
0
        public static WeatherDetailsFragment NewInstance(WeatherNowViewModel weatherViewModel)
        {
            WeatherDetailsFragment fragment = new WeatherDetailsFragment();

            if (weatherViewModel != null)
            {
                fragment.weatherView = weatherViewModel;
            }
            return(fragment);
        }
        public static WeatherAlertsFragment NewInstance(LocationData location, WeatherNowViewModel weatherViewModel)
        {
            var fragment = new WeatherAlertsFragment();

            if (location != null && weatherViewModel != null)
            {
                fragment.location    = location;
                fragment.weatherView = weatherViewModel;
            }
            return(fragment);
        }
示例#4
0
        public WeatherNow()
        {
            this.InitializeComponent();
            NavigationCacheMode           = NavigationCacheMode.Enabled;
            Application.Current.Resuming += WeatherNow_Resuming;

            wm          = WeatherManager.GetInstance();
            WeatherView = new WeatherNowViewModel();
            StackControl.SizeChanged += StackControl_SizeChanged;
            DetailsPanel.SizeChanged += DetailsPanel_SizeChanged;
            MainViewer.SizeChanged   += MainViewer_SizeChanged;
            MainViewer.ViewChanged   += MainViewer_ViewChanged;

            HeaderLeft.Click  += delegate { ScrollTxtPanel(false); };
            HeaderRight.Click += delegate { ScrollTxtPanel(true); };

            // Additional Details (Extras)
            ForecastSwitch.Visibility      = Visibility.Collapsed;
            TextForecastPanel.Visibility   = Visibility.Collapsed;
            HourlyForecastPanel.Visibility = Visibility.Collapsed;
            PrecipitationPanel.Visibility  = Visibility.Collapsed;

            geolocal = new Geolocator()
            {
                DesiredAccuracyInMeters = 5000, ReportInterval = 900000, MovementThreshold = 1600
            };

            // CommandBar
            CommandBarLabel = App.ResLoader.GetString("Nav_WeatherNow/Text");
            PrimaryCommands = new List <ICommandBarElement>()
            {
                new AppBarButton()
                {
                    Icon       = new SymbolIcon(Symbol.Pin),
                    Label      = App.ResLoader.GetString("Label_Pin/Text"),
                    Tag        = "pin",
                    Visibility = Visibility.Collapsed
                },
                new AppBarButton()
                {
                    Icon  = new SymbolIcon(Symbol.Refresh),
                    Label = App.ResLoader.GetString("Button_Refresh/Label"),
                    Tag   = "refresh"
                }
            };
            GetRefreshBtn().Click += RefreshButton_Click;
            GetPinBtn().Click     += PinButton_Click;
        }
示例#5
0
        public static WeatherListFragment NewInstance(WeatherListType weatherType, WeatherNowViewModel weatherViewModel)
        {
            WeatherListFragment fragment = new WeatherListFragment();

            if (weatherViewModel != null)
            {
                fragment.weatherView = weatherViewModel;
            }

            Bundle args = new Bundle();

            args.PutInt("WeatherListType", (int)weatherType);
            fragment.Arguments = args;

            return(fragment);
        }
示例#6
0
        public void UpdateNavDrawerItems(WeatherNowViewModel weatherNowView)
        {
            WeatherNowView = weatherNowView;

            IEnumerable <NavDrawerItem> items = navDrawerItems;

            if (weatherNowView.Extras.Alerts.Count == 0)
            {
                items = items.Where(item => item.TitleString != Resource.String.title_fragment_alerts);
            }
            if (weatherNowView.Extras.HourlyForecast.Count == 0)
            {
                items = items.Where(item => item.TitleString != Resource.String.label_hourlyforecast);
            }

            navItems = items.ToList();
            NotifyDataSetChanged();
        }
        private async Task Initialize()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                AppCompatActivity?.RunOnUiThread(() =>
                {
                    AppCompatActivity?.Window.SetStatusBarColor(
                        new Color(ContextCompat.GetColor(AppCompatActivity, Resource.Color.colorPrimaryDark)));
                });
            }

            if (weatherView == null)
            {
                if (location == null)
                {
                    location = Settings.HomeData;
                }

                var weather = await Settings.GetWeatherData(location.query);

                if (weather != null)
                {
                    weather.weather_alerts = await Settings.GetWeatherAlertData(location.query);
                }

                weatherView = new WeatherNowViewModel(weather);
            }

            if (weatherView != null)
            {
                AppCompatActivity?.RunOnUiThread(() =>
                {
                    locationHeader.Text = weatherView.Location;
                    // use this setting to improve performance if you know that changes
                    // in content do not change the layout size of the RecyclerView
                    recyclerView.HasFixedSize = true;
                    // use a linear layout manager
                    recyclerView.SetLayoutManager(new LinearLayoutManager(AppCompatActivity));
                    // specify an adapter (see also next example)
                    recyclerView.SetAdapter(new WeatherAlertPanelAdapter(weatherView.Extras?.Alerts?.ToList()));
                });
            }
        }
示例#8
0
        private void SetView(WeatherNowViewModel weatherView)
        {
            Activity?.RunOnUiThread(() =>
            {
                // Background
                refreshLayout.Background = new ColorDrawable(weatherView.PendingBackground);

                // Location
                locationName.Text = weatherView.Location;

                // Date Updated
                updateTime.Text = weatherView.UpdateDate;

                // Update Current Condition
                weatherTemp.Text      = weatherView.CurTemp;
                weatherCondition.Text = weatherView.CurCondition;
                weatherIcon.Text      = weatherView.WeatherIcon;

                weatherCredit.Text = weatherView.WeatherCredit;
            });
        }
示例#9
0
 public WeatherNowFragment()
 {
     // Required empty public constructor
     weatherView = new WeatherNowViewModel();
     wm          = WeatherManager.GetInstance();
 }
示例#10
0
 public void OnWeatherViewUpdated(WeatherNowViewModel weatherNowView)
 {
     mNavDrawerAdapter.UpdateNavDrawerItems(weatherNowView);
 }
 private void UpdateNavHeader(WeatherNowViewModel weatherView)
 {
     navheader.Background = new ColorDrawable(weatherView.PendingBackground);
     navLocation.Text     = weatherView.Location;
     navWeatherTemp.Text  = weatherView.CurTemp;
 }
        private void SetView(WeatherNowViewModel weatherView)
        {
            AppCompatActivity?.RunOnUiThread(() =>
            {
                // Background
                refreshLayout.Background = new ColorDrawable(weatherView.PendingBackground);
                bgImageView.ImageAlpha   = BGAlpha;
                Glide.With(this.Context)
                .Load(weatherView.Background)
                .Apply(new RequestOptions().CenterCrop())
                .Into(bgImageView);

                // Actionbar & StatusBar
                AppCompatActivity?.SupportActionBar.SetBackgroundDrawable(new ColorDrawable(weatherView.PendingBackground));
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    AppCompatActivity?.Window.SetStatusBarColor(Color.Argb(255,
                                                                           (int)(weatherView.PendingBackground.R * 0.75),
                                                                           (int)(weatherView.PendingBackground.G * 0.75),
                                                                           (int)(weatherView.PendingBackground.B * 0.75)));
                }

                // Location
                locationName.Text = weatherView.Location;

                // Date Updated
                updateTime.Text = weatherView.UpdateDate;

                // Update Current Condition
                weatherTemp.Text      = weatherView.CurTemp;
                weatherCondition.Text = weatherView.CurCondition;
                weatherIcon.Text      = weatherView.WeatherIcon;

                // WeatherDetails
                // Astronomy
                sunrise.Text = weatherView.Sunrise;
                sunset.Text  = weatherView.Sunset;

                // Wind
                feelslike.Text         = weatherView.WindChill;
                windSpeed.Text         = weatherView.WindSpeed;
                windDirection.Rotation = weatherView.WindDirection;

                // Atmosphere
                humidity.Text = weatherView.Humidity;
                pressure.Text = weatherView.Pressure;

                pressureState.Visibility = weatherView.RisingVisiblity;
                pressureState.Text       = weatherView.RisingIcon;

                visiblity.Text = weatherView._Visibility;

                // Add UI elements
                forecastAdapter.UpdateItems(weatherView.Forecasts);
                forecastPanel.Visibility = ViewStates.Visible;

                // Additional Details
                if (weatherView.Extras.HourlyForecast.Count >= 1)
                {
                    hrforecastAdapter.UpdateItems(weatherView.Extras.HourlyForecast);
                    hrforecastPanel.Visibility = ViewStates.Visible;
                }
                else
                {
                    hrforecastPanel.Visibility = ViewStates.Gone;
                }

                if (weatherView.Extras.TextForecast.Count >= 1)
                {
                    forecastSwitch.Visibility = ViewStates.Visible;
                    (txtForecastView.Adapter as TextForecastPagerAdapter).UpdateDataset(weatherView.Extras.TextForecast.ToList());
                }
                else
                {
                    forecastSwitch.Visibility = ViewStates.Gone;
                }

                if (!String.IsNullOrWhiteSpace(weatherView.Extras.Chance))
                {
                    chance.Text  = cloudiness.Text = weatherView.Extras.Chance;
                    qpfRain.Text = weatherView.Extras.Qpf_Rain;
                    qpfSnow.Text = weatherView.Extras.Qpf_Snow;

                    if (!Settings.API.Equals(WeatherAPI.MetNo))
                    {
                        precipitationPanel.Visibility = ViewStates.Visible;

                        if (IsLargeTablet(AppCompatActivity))
                        {
                            // Add back panel if not present
                            var panel    = (Android.Support.V7.Widget.GridLayout)detailsPanel;
                            int childIdx = panel.IndexOfChild(panel.FindViewById(Resource.Id.precipitation_card));
                            if (childIdx < 0)
                            {
                                panel.AddView(precipitationPanel, 0);
                            }
                        }
                    }
                    else
                    {
                        if (IsLargeTablet(AppCompatActivity))
                        {
                            var panel = (Android.Support.V7.Widget.GridLayout)detailsPanel;
                            panel.RemoveView(panel.FindViewById(Resource.Id.precipitation_card));
                        }
                        else
                        {
                            precipitationPanel.Visibility = ViewStates.Gone;
                        }
                    }

                    if (Settings.API.Equals(WeatherAPI.OpenWeatherMap) || Settings.API.Equals(WeatherAPI.MetNo))
                    {
                        chanceLabel.Visibility = ViewStates.Gone;
                        chance.Visibility      = ViewStates.Gone;

                        cloudinessLabel.Visibility = ViewStates.Visible;
                        cloudiness.Visibility      = ViewStates.Visible;
                    }
                    else
                    {
                        chanceLabel.Visibility = ViewStates.Visible;
                        chance.Visibility      = ViewStates.Visible;

                        cloudinessLabel.Visibility = ViewStates.Gone;
                        cloudiness.Visibility      = ViewStates.Gone;
                    }
                }
                else
                {
                    if (IsLargeTablet(AppCompatActivity))
                    {
                        var panel = (Android.Support.V7.Widget.GridLayout)detailsPanel;
                        panel.RemoveView(panel.FindViewById(Resource.Id.precipitation_card));
                    }
                    else
                    {
                        precipitationPanel.Visibility = ViewStates.Gone;
                    }

                    cloudinessLabel.Visibility = ViewStates.Gone;
                    cloudiness.Visibility      = ViewStates.Gone;
                }

                // Alerts
                if (wm.SupportsAlerts && weatherView.Extras.Alerts.Count > 0)
                {
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        alertButton.BackgroundTintList = ColorStateList.ValueOf(Color.OrangeRed);
                    }
                    else
                    {
                        var origDrawable   = ContextCompat.GetDrawable(AppCompatActivity, Resource.Drawable.light_round_corner_bg);
                        var compatDrawable = DrawableCompat.Wrap(origDrawable);
                        DrawableCompat.SetTint(compatDrawable, Color.OrangeRed);
                        alertButton.Background = compatDrawable;
                    }

                    alertButton.Visibility = ViewStates.Visible;
                    ResizeAlertPanel();
                }
                else
                {
                    alertButton.Visibility = ViewStates.Invisible;
                }

                // Fix DetailsLayout
                AdjustDetailsLayout();

                // Nav Header View
                UpdateNavHeader(weatherView);

                weatherCredit.Text = weatherView.WeatherCredit;
            });
        }