// Can give some params default value later!! public RaffleListPage(bool isLocationDetected, IList<RaffleLocation> raffleLocations, RaffleLocation userSelectedLocation, GeonamesCountrySubdivision countrySubdivision, bool includeSocialMedia) { InitializeComponent(); NavigationPage.SetHasBackButton(this, false); Title = "Raffle List"; LocationDetected = isLocationDetected; IncludeSocialMedia = includeSocialMedia; _viewModel = new RaffleListViewModel(isLocationDetected, raffleLocations, userSelectedLocation, countrySubdivision); var locationPicker = new Picker(); locationPicker.HorizontalOptions = LayoutOptions.Center; layout.Children.Add(locationPicker); locationPicker.Items.Add(_viewModel.LocationName); locationPicker.SelectedIndex = 0; locationPicker.IsEnabled = false; if (_viewModel.RaffleLocation == null) // only happen when locationDetected == true { layout.Children.Add(new StackLayout { Children = { new Label { Text = "Sorry. There is no available raffle at your location.", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, } }, Padding = new Thickness(20, 0, 20, 0), VerticalOptions = LayoutOptions.CenterAndExpand, } ); } else { GetRaffleEventsAndCreateList(_viewModel.LocationName); } // Previous UX // else // { // foreach (var location in raffleLocations) // { // locationPicker.Items.Add(location.Name); // } // locationPicker.IsEnabled = true; // locationPicker.SelectedIndexChanged += (sender, e) => // { // if (layout.Children.Count == 2) // { // layout.Children.RemoveAt(1); // } // GetRaffleEventsAndCreateList(locationPicker.Items[locationPicker.SelectedIndex]); // }; // } }
public async Task GetCurrentLocationAndServerData() { var updateGeolocationTask = GeolocationManager.UpdateGeolocation(); var getRaffleLocationsTask = GetRaffleLocations(); var tasks = new List<Task>{ updateGeolocationTask, getRaffleLocationsTask }; bool isGetCountriesAndProvinces = false; var getCountries = GetCountries(); var getProvinces = GetProvinces(); if ((DatabaseManager.DbConnection.Table<Country>().Count() == 0) || (DatabaseManager.DbConnection.Table<Province>().Count() == 0)) { isGetCountriesAndProvinces = true; } if (isGetCountriesAndProvinces) { tasks.Add(getCountries); tasks.Add(getProvinces); } await Task.WhenAll(tasks); RaffleLocations = getRaffleLocationsTask.Result; if (RaffleLocations != null) { // Set default value UserSelectedLocation = RaffleLocations[0]; } CountrySubdivision = GeolocationManager.CountrySubdivision; if ((CountrySubdivision != null) && (CountrySubdivision.AdminName != null)) { IsLocationDetected = true; } else { IsLocationDetected = false; } if (isGetCountriesAndProvinces) { var countries = getCountries.Result; var provinces = getProvinces.Result; foreach (var country in countries) { DatabaseManager.DbConnection.Insert(country); } foreach (var province in provinces) { DatabaseManager.DbConnection.Insert(province); } } }