public LoadingPage(RootPage rootPage)
        {
            _rootPage = rootPage;
            NavigationPage.SetHasNavigationBar(this, false);

            //TODO : Inject ForecastService

            _viewModel     = new LoadingViewModel(Navigation, new ForecastService(new OpenWeatherMapService(new HttpClient())), rootPage);
            BindingContext = _viewModel;

            var statusMessageLabel = new LargeLabel {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                TextColor         = Color.White,
            };

            statusMessageLabel.SetBinding <LoadingViewModel> (Label.TextProperty, vm => vm.StatusMessage);

            var stackLayout = new StackLayout {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Spacing           = 10
            };

            var loadingImage = new Image();

            loadingImage.SetBinding <LoadingViewModel> (Image.SourceProperty, vm => vm.LoadingImage);

            var refreshButton = new Button {
                Text = "Refresh", HorizontalOptions = LayoutOptions.Center
            };

            refreshButton.SetBinding <LoadingViewModel> (Button.CommandProperty, vm => vm.GetForecastCommand);
            refreshButton.SetBinding <LoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsRefreshButtonVisible);

            var activityIndicator = new ActivityIndicator {
                IsRunning = true
            };

            activityIndicator.SetBinding <LoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsActivityIndicatorVisible);

            stackLayout.Children.Add(loadingImage);
            stackLayout.Children.Add(statusMessageLabel);
            stackLayout.Children.Add(activityIndicator);
            stackLayout.Children.Add(refreshButton);

            Content = stackLayout;
        }
Example #2
0
        public LoadingPage(RootPage rootPage)
        {
            _rootPage = rootPage;
            NavigationPage.SetHasNavigationBar (this, false);

            //TODO : Inject ForecastService

            _viewModel = new LoadingViewModel (Navigation, new ForecastService (new OpenWeatherMapService (new HttpClient ())), rootPage);
            BindingContext = _viewModel;

            var statusMessageLabel = new LargeLabel {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
                TextColor = Color.White,
            };

            statusMessageLabel.SetBinding<LoadingViewModel> (Label.TextProperty, vm => vm.StatusMessage);

            var stackLayout = new StackLayout {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
                Spacing = 10
            };

            var loadingImage = new Image ();

            loadingImage.SetBinding<LoadingViewModel> (Image.SourceProperty, vm => vm.LoadingImage);

            var refreshButton = new Button{ Text = "Refresh", HorizontalOptions = LayoutOptions.Center };

            refreshButton.SetBinding<LoadingViewModel> (Button.CommandProperty, vm => vm.GetForecastCommand);
            refreshButton.SetBinding<LoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsRefreshButtonVisible);

            var activityIndicator = new ActivityIndicator{ IsRunning = true };

            activityIndicator.SetBinding<LoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsActivityIndicatorVisible);

            stackLayout.Children.Add (loadingImage);
            stackLayout.Children.Add (statusMessageLabel);
            stackLayout.Children.Add (activityIndicator);
            stackLayout.Children.Add (refreshButton);

            Content = stackLayout;
        }
		public LoadingViewModel (INavigation navigation, IForecastService forecastService, RootPage rootPage)
		{
			this.rootPage = rootPage;
			_navigation = navigation;
			_forecastService = forecastService;

			LoadingImage = "Radar.png";
			IsRefreshButtonVisible = false;
			IsActivityIndicatorVisible = false;

			Setup ();

			if (_geolocator.IsGeolocationEnabled) {
				GetForecastAsync ();
			} else {
				StatusMessage = "GPS is disabled, please enable GPS and refresh.";
				IsRefreshButtonVisible = true;
			}
		}
Example #4
0
        public LoadingViewModel(INavigation navigation, IForecastService forecastService, RootPage rootPage)
        {
            this.rootPage    = rootPage;
            _navigation      = navigation;
            _forecastService = forecastService;

            LoadingImage               = "Radar.png";
            IsRefreshButtonVisible     = false;
            IsActivityIndicatorVisible = false;

            Setup();

            if (_geolocator.IsGeolocationEnabled)
            {
                GetForecastAsync();
            }
            else
            {
                StatusMessage          = "GPS is disabled, please enable GPS and refresh.";
                IsRefreshButtonVisible = true;
            }
        }
        public ForecastPage(RootPage rootPage, Forecast forecast)
        {
            this._rootPage = rootPage;
            _forecast      = forecast;
            BindingContext = new ForecastViewModel(Navigation, _forecast);

            NavigationPage.SetHasNavigationBar(this, false);

            var masterGrid = new Grid {
                RowDefinitions = new RowDefinitionCollection {
                    new RowDefinition {
                        Height = new GridLength(0.3, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(0.3, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(0.4, GridUnitType.Star)
                    }
                },
                ColumnDefinitions = new ColumnDefinitionCollection {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                }
            };

            var forecastListview = new ListView();

            var forecastListviewItemTemplate = new DataTemplate(typeof(ImageCell));

            forecastListviewItemTemplate.SetBinding(ImageCell.TextProperty, "ItemTemplateTextProperty");
            forecastListviewItemTemplate.SetValue(ImageCell.TextColorProperty, Color.FromHex("#3498DB"));
            forecastListviewItemTemplate.SetBinding(ImageCell.DetailProperty, "ItemTemplateDetailProperty");
            forecastListviewItemTemplate.SetValue(ImageCell.DetailColorProperty, Color.White);
            forecastListviewItemTemplate.SetBinding(ImageCell.ImageSourceProperty, "Icon");

            forecastListview.ItemTemplate = forecastListviewItemTemplate;
            forecastListview.SetBinding <ForecastViewModel> (ListView.ItemsSourceProperty, vm => vm.WeatherList);

            var refreshImage = new ImageButton()
            {
                Image = "Refresh",
                ImageHeightRequest = 70,
                ImageWidthRequest  = 70,
                BorderColor        = Color.Transparent,
                VerticalOptions    = LayoutOptions.Start,
                BackgroundColor    = Color.Transparent
            };

            refreshImage.Clicked += (object sender, EventArgs e) => {
                _rootPage.ShowLoadingDialog();
            };

            var topGrid = new Grid {
                RowDefinitions = new RowDefinitionCollection {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    }
                },
                ColumnDefinitions = new ColumnDefinitionCollection {
                    new ColumnDefinition {
                        Width = new GridLength(0.8, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(0.2, GridUnitType.Star)
                    },
                }
            };

            topGrid.Children.Add(CreateForecastStatusStackLayout(), 0, 0);
            topGrid.Children.Add(refreshImage, 1, 0);

            masterGrid.Children.Add(topGrid, 0, 0);
            masterGrid.Children.Add(CreateMiddleStackLayout(), 0, 1);
            masterGrid.Children.Add(forecastListview, 0, 2);

            Content = masterGrid;
        }