public void ImageFilesToDownload() { foreach (WildFlowerSetting imageFile in imageFileSettingsOnServer) { WildFlowerSetting imageFileLocalSetting = App.WildFlowerSettingsRepo.GetImageZipFileSetting(imageFile.valuetext); if (imageFileLocalSetting == null) { imageFilesToDownload.Add(imageFile); } } }
//hardcoded public async Task <IEnumerable <WildFlowerSetting> > GetImageZipFileSettings() { result = await client.GetStringAsync(Url + "_settings/ImagesZipFile"); WildFlowerSetting setting = JsonConvert.DeserializeObject <WildFlowerSetting>(result); List <WildFlowerSetting> settingList = new List <WildFlowerSetting>(); settingList.Add(setting); return(settingList); }
public DownloadWildFlowersPage(bool updatePlantsNow, WildFlowerSetting dateLocalPlantDataUpdated, WildFlowerSetting datePlantDataUpdated, List<WildFlowerSetting> imageFilesNeedingDownloaded, bool downloadImagesFromServer, bool resyncplants, bool clearDatabase) { updatePlants = updatePlantsNow; this.resyncPlants = resyncplants; this.clearDatabase = clearDatabase; datePlantDataUpdatedLocally = dateLocalPlantDataUpdated; datePlantDataUpdatedLocally.valuetimestamp = DateTime.Now; datePlantDataUpdatedOnServer = datePlantDataUpdated; imageFilesToDownload = (imageFilesNeedingDownloaded == null) ? new List<WildFlowerSetting>() : imageFilesNeedingDownloaded; //downloadImages = downloadImagesFromServer; // Turn off navigation bar and initialize pageContainer NavigationPage.SetHasNavigationBar(this, false); AbsoluteLayout pageContainer = ConstructPageContainer(); // Initialize grid for inner container Grid innerContainer = new Grid { Padding = new Thickness(20, Device.OnPlatform(30, 20, 20), 20, 20), BackgroundColor = Color.FromHex("88000000") }; innerContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); // Add label innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); innerContainer.Children.Add(downloadLabel, 0, 1); // Add progressbar innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); innerContainer.Children.Add(progressBar, 0, 2); // Add dismiss button cancelButton = new Button { Style = Application.Current.Resources["outlineButton"] as Style, Text = "CANCEL", BorderRadius = Device.OnPlatform(0, 1, 0) }; cancelButton.Clicked += CancelDownload; innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); innerContainer.Children.Add(cancelButton, 0, 3); innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); // Add inner container to page container and set as page content pageContainer.Children.Add(innerContainer, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All); Content = pageContainer; }
// add or update a setting public void AddOrUpdateSetting(WildFlowerSetting setting) { try { if (string.IsNullOrEmpty(setting.name)) { throw new Exception("Valid setting name required"); } var result = conn.InsertOrReplace(setting); StatusMessage = string.Format("{0} record(s) added [Name: {1})", result, setting); } catch (Exception ex) { StatusMessage = string.Format("Failed to add/update {0}. Error: {1}", setting, ex.Message); } }
// add a setting async public async Task AddSettingAsync(WildFlowerSetting setting) { try { if (string.IsNullOrEmpty(setting.name)) { throw new Exception("Valid setting name required"); } var result = await connAsync.InsertAsync(setting); StatusMessage = string.Format("{0} record(s) added [Name: {1})", result, setting); } catch (Exception ex) { StatusMessage = string.Format("Failed to add/update {0}. Error: {1}", setting, ex.Message); } }
public WildFlowersPage(bool streaming) { GC.Collect(); // Initialize variables sortField = new WildFlowerSetting(); this.streaming = streaming; // Turn off navigation bar and initialize pageContainer NavigationPage.SetHasNavigationBar(this, false); AbsoluteLayout pageContainer = ConstructPageContainer(); // Initialize grid for inner containers Grid innerContainer = new Grid { Padding = new Thickness(0, Device.OnPlatform(10, 0, 0), 0, 0), ColumnSpacing = 0 }; innerContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); Grid gridLayout = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, ColumnSpacing = 0 }; gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); // BACK button gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); gridLayout.Children.Add(BackImageConstructor(), 0, 0); // Construct filter button group plantFilterGroup = new Grid { ColumnSpacing = -1, Margin = new Thickness(0, 8, 0, 5) }; plantFilterGroup.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); // Add browse filter browseFilter = new Button { Style = Application.Current.Resources["plantFilterButton"] as Style, Text = "Browse" }; browseFilter.Clicked += FilterPlants; plantFilterGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); plantFilterGroup.Children.Add(browseFilter, 0, 0); BoxView divider = new BoxView { HeightRequest = 40, WidthRequest = 1, BackgroundColor = Color.White }; plantFilterGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1) }); plantFilterGroup.Children.Add(divider, 1, 0); // Add Search filter searchFilter = new Button { Style = Application.Current.Resources["plantFilterButton"] as Style, Text = "Search" }; //searchFilter.Clicked += async (s, e) => { await Navigation.PushAsync(SearchPage, false); }; //SearchPage.InitRunSearch += HandleRunSearch; //SearchPage.InitCloseSearch += HandleCloseSearch; plantFilterGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); plantFilterGroup.Children.Add(searchFilter, 2, 0); BoxView divider2 = new BoxView { HeightRequest = 40, WidthRequest = 1, BackgroundColor = Color.White }; plantFilterGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1) }); plantFilterGroup.Children.Add(divider2, 3, 0); // Add Favorites filter favoritesFilter = new Button { Style = Application.Current.Resources["plantFilterButton"] as Style, Text = "Favorites" }; favoritesFilter.Clicked += FilterPlants; plantFilterGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); plantFilterGroup.Children.Add(favoritesFilter, 4, 0); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(6, GridUnitType.Star) }); gridLayout.Children.Add(plantFilterGroup, 1, 0); // Home button gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); gridLayout.Children.Add(HomeImageConstructor(), 2, 0); // Add header to inner container innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); innerContainer.Children.Add(gridLayout, 0, 0); // Add button group grid Grid searchSortGroup = new Grid(); searchSortGroup.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); searchSortGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1.7, GridUnitType.Star) }); searchSortGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // Add search bar searchBar = new CustomSearchBar { Placeholder = "Search by scientific or common name...", FontSize = 12, Margin = new Thickness(Device.OnPlatform(10, 0, 0), 0, 0, 0), SearchCommand = new Command(() => { }) }; searchBar.TextChanged += SearchBarOnChange; searchSortGroup.Children.Add(searchBar, 0, 0); // Add sort container Grid sortContainer = new Grid { ColumnSpacing = 0 }; sortContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.7, GridUnitType.Star) }); sortContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.25, GridUnitType.Star) }); sortContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.05, GridUnitType.Star) }); sortContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); sortButton.Clicked += SortPickerTapped; sortContainer.Children.Add(sortButton, 0, 0); foreach (string option in sortOptions.Keys) { sortPicker.Items.Add(option); } sortPicker.IsVisible = false; if (Device.OS == TargetPlatform.iOS) { sortPicker.Unfocused += SortOnUnfocused; } else { sortPicker.SelectedIndexChanged += SortItems; } sortContainer.Children.Add(sortPicker, 0, 0); sortDirection.Clicked += ChangeSortDirection; sortContainer.Children.Add(sortDirection, 1, 0); searchSortGroup.Children.Add(sortContainer, 1, 0); innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); innerContainer.Children.Add(searchSortGroup, 0, 1); // Create ListView container RelativeLayout listViewContainer = new RelativeLayout { VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Transparent, }; // Add Plants ListView wildFlowerList = new ListView(ListViewCachingStrategy.RecycleElement) { BackgroundColor = Color.Transparent, RowHeight = 100 }; wildFlowerList.ItemTemplate = CellTemplate(); wildFlowerList.ItemSelected += OnItemSelected; wildFlowerList.SeparatorVisibility = SeparatorVisibility.None; listViewContainer.Children.Add(wildFlowerList, Constraint.RelativeToParent((parent) => { return(parent.X); }), Constraint.RelativeToParent((parent) => { return(parent.Y - 105); }), Constraint.RelativeToParent((parent) => { return(parent.Width * .9); }), Constraint.RelativeToParent((parent) => { return(parent.Height); }) ); // Add jump list to right side jumpListContainer = new StackLayout { Spacing = -1, Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; listViewContainer.Children.Add(jumpListContainer, Constraint.RelativeToParent((parent) => { return(parent.Width * .9); }), Constraint.RelativeToParent((parent) => { return(parent.Y - 105); }), Constraint.RelativeToParent((parent) => { return(parent.Width * .1); }), Constraint.RelativeToParent((parent) => { return(parent.Height); }) ); // Add ListView and Jump List to grid innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); innerContainer.Children.Add(listViewContainer, 0, 2); //Add inner container to page container and set as page content pageContainer.Children.Add(innerContainer, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All); Content = pageContainer; GC.Collect(); }
private void GetSortField() { sortField = App.WildFlowerSettingsRepo.GetSetting("Sort Field"); sortButton.Text = sortField.valuetext; }
protected override async void OnAppearing() { if (!canceledDownload) { // Initiate variables isConnected = Connectivity.checkConnection(); isConnectedToWiFi = Connectivity.checkWiFiConnection(); downloadImagesSetting = App.WildFlowerSettingsRepo.GetSetting("Download Images"); // if connected to WiFi and updates are needed if (isConnected) { datePlantDataUpdatedLocally = App.WildFlowerSettingsRepo.GetSetting("Date Plants Downloaded"); try { datePlantDataUpdatedOnServer = await externalConnection.GetDateUpdatedDataOnServer(); imageFileSettingsOnServer = await externalConnection.GetImageZipFileSettings(); ImageFilesToDownload(); if (datePlantDataUpdatedLocally.valuetimestamp >= datePlantDataUpdatedOnServer.valuetimestamp) { DownloadButtonText = "Plant DB Up To Date"; downloadImagesButton.Text = "Clear Local Database And Stream Plants"; streamingLabel.Text = "You Are Using Your Local Plant Database"; downloadImagesLabel.TextColor = Color.Green; updatePlants = false; resyncPlants = false; clearDatabase = true; downloadImages = false; } else { if (datePlantDataUpdatedLocally.valuetimestamp == null) { DownloadButtonText = "Download Plant DB"; downloadImagesButton.Text = "Download (No Local Database)"; streamingLabel.Text = "You Are Streaming Plants"; downloadImagesLabel.TextColor = Color.Red; updatePlants = true; resyncPlants = false; clearDatabase = false; downloadImages = true; } else if ((datePlantDataUpdatedLocally.valuetimestamp < datePlantDataUpdatedOnServer.valuetimestamp) && datePlantDataUpdatedLocally.valuetimestamp != null) { DownloadButtonText = "New Plant DB Available"; downloadImagesButton.Text = "Re-Sync (New Database Available)"; streamingLabel.Text = "You Are Using Your Local Plant Database"; downloadImagesLabel.TextColor = Color.Yellow; updatePlants = true; resyncPlants = true; clearDatabase = false; downloadImages = false; } } } catch (Exception e) { Debug.WriteLine("Canceled UpdatePlants {0}", e.Message); } } else { if (numberOfPlants == 0) { await DisplayAlert("No Local Database Detected", "Please connect to WiFi or cell network to download or use CO Woodys App", "OK"); updatePlants = false; resyncPlants = false; clearDatabase = false; downloadImages = true; } else { downloadImagesButton.Text = "No Internet Connection"; } } } else { canceledDownload = false; } }