public Image NextImageConstructor(ObservableCollection <WoodyPlant> plants, int plantIndex) { Image nextImage = new Image { Source = ImageSource.FromResource("WoodyPlants.Resources.Icons.next_icon.png"), HeightRequest = 20, WidthRequest = 20, Margin = new Thickness(0, 15, 0, 15) }; if (plantIndex < plants.Count - 1) { WoodyPlant nextPlant = plants[plantIndex + 1]; var nextImageGestureRecognizer = new TapGestureRecognizer(); nextImageGestureRecognizer.Tapped += async(sender, e) => { nextImage.Opacity = .5; await Task.Delay(200); nextImage.Opacity = 1; await Navigation.PushAsync(new WoodyPlantDetailPage(nextPlant, downloadImages, plants)); Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]); }; nextImage.GestureRecognizers.Add(nextImageGestureRecognizer); } return(nextImage); }
public async Task UpdatePlantAsync(WoodyPlant plant) { try { await connAsync.UpdateAsync(plant); } catch (Exception ex) { StatusMessage = string.Format("Failed to update {0}. Error: {1}", plant, ex.Message); } }
public static WoodyPlantDocument ToDocument(this WoodyPlant plant, string?version = null) { return(new WoodyPlantDocument { ImageUrls = plant.ImageUrls, LocalizedNames = plant.LocalizedNames.ToDocument(), LocalizedNotes = plant.LocalizedNotes.ToDocument(), LocalizedSpecies = plant.LocalizedSpecies.ToDocument(), Location = plant.Location.ToDocument(), Type = plant.Type.ToType(), Version = version }); }
public WoodyPlantEcologyPage(WoodyPlant plant, ObservableCollection <WoodyPlant> plants) { // 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(0, Device.OnPlatform(10, 0, 0), 0, 0) }; innerContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // Add header to inner container Grid navigationBar = ConstructPlantNavigationBar(plant.commonName, plant, plants); innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); innerContainer.Children.Add(navigationBar, 0, 0); ScrollView contentScrollView = new ScrollView { BackgroundColor = Color.FromHex("88000000"), Padding = new Thickness(20, 5, 20, 5), Margin = new Thickness(0, 0, 0, 0) }; TransparentWebView browser = ConstructHTMLContent(plant); //browser.Navigating += ToWoodyType; contentScrollView.Content = browser; innerContainer.RowDefinitions.Add(new RowDefinition { }); innerContainer.Children.Add(contentScrollView, 0, 1); //var WoodyTypes = ConstructWoodyTypes(plant.ecologicalsystems); //innerContainer.RowDefinitions.Add(new RowDefinition { }); //innerContainer.Children.Add(WoodyTypes, 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; base.OnAppearing(); }
public async Task AddOrUpdatePlantAsync(WoodyPlant plant) { try { if (string.IsNullOrEmpty(plant.commonName)) { throw new Exception("Valid plant required"); } await connAsync.InsertOrReplaceWithChildrenAsync(plant); } catch (Exception ex) { StatusMessage = string.Format("Failed to add {0}. Error: {1}", plant, ex.Message); } }
public Image FavoriteImageConstructor(WoodyPlant plant) { string favoriteIcon = plant.isFavorite ? "favorite_icon_filled.png" : "favorite_icon_empty.png"; string favoriteIconOpposite = !plant.isFavorite ? "favorite_icon_filled.png" : "favorite_icon_empty.png"; Image favoriteImage = new Image { Source = ImageSource.FromResource("WoodyPlants.Resources.Icons." + favoriteIcon), HeightRequest = 20, WidthRequest = 20, Margin = new Thickness(0, 15, 0, 15) }; var favoriteGestureRecognizer = new TapGestureRecognizer(); favoriteGestureRecognizer.Tapped += async(sender, e) => { plant.isFavorite = plant.isFavorite == true ? false : true; favoriteImage.Source = ImageSource.FromResource("WoodyPlants.Resources.Icons." + favoriteIconOpposite); await App.WoodyPlantRepo.UpdatePlantAsync(plant); }; favoriteImage.GestureRecognizers.Add(favoriteGestureRecognizer); return(favoriteImage); }
public WoodyPlantDetailPage(WoodyPlant plant, bool streaming, ObservableCollection <WoodyPlant> plants = null) { GC.Collect(); NavigationPage.SetHasNavigationBar(this, false); var helpers = new ViewHelpers(); Children.Add(new WoodyPlantImagesPage(plant, plants, streaming) { Title = "IMAGES", Icon = "images.png" }); Children.Add(new WoodyPlantInfoPage(plant, plants) { Title = "INFO", Icon = "info.png" }); Children.Add(new WoodyPlantEcologyPage(plant, plants) { Title = "ECOLOGY", Icon = "ecology.png" }); Children.Add(new WoodyPlantRangePage(plant, plants, streaming) { Title = "RANGE", Icon = "range.png" }); BarBackgroundColor = Color.Black; BarTextColor = Color.White; BackgroundColor = Color.Black; if (selectedTabSetting != null) { SelectedItem = Children[Convert.ToInt32(selectedTabSetting.valueint)]; } else { SelectedItem = Children[0]; } this.CurrentPageChanged += RememberPageChange; }
public TransparentWebView ConstructHTMLContent(WoodyPlant plant) { browser = new TransparentWebView(); var htmlSource = new HtmlWebViewSource(); string html = ""; html += "<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><meta charset = 'utf-8' /><title>Plant Info Page</title></head><body>"; html += "<style>body{ color: white; font-size: 0.9em; padding-bottom: 200px; padding-top: 50px; } a { color: white; font-size: 0.9em; } .section_header { font-weight: bold; border-bottom: 1px solid white; margin: 10px 0; } .embedded_table { width: 100%; margin-left: 10px; } .iconImg { height: 40px; }</style>"; if ((plant.frequency != null && plant.frequency.Length != 0) || (plant.lifeZone != null && plant.lifeZone.Length != 0) || (plant.habitat != null && plant.habitat.Length != 0) || (plant.endemicLocation != null && plant.endemicLocation.Length != 0)) { html += "<div class='section_header'>ECOSYSTEM</div>"; if (plant.frequency != null && plant.frequency.Length != 0) { html += "<strong>Frequency: </strong>" + plant.frequency + "<br/>"; } if (plant.lifeZone != null && plant.lifeZone.Length != 0) { html += "<strong>Life Zone: </strong>" + plant.lifeZone + "<br/>"; } if (plant.habitat != null && plant.habitat.Length != 0) { html += "<strong>Habitat: </strong>" + plant.habitat + "<br/>"; } if (plant.endemicLocation != null && plant.endemicLocation.Length != 0) { html += "<strong>Endemic Location: </strong>" + plant.endemicLocation + "<br/>"; } } if ((plant.edibility != null && plant.edibility.Length != 0) || (plant.toxicity != null && plant.toxicity.Length != 0) || (plant.fiber != null && plant.fiber.Length != 0) || (plant.otherUses != null && plant.otherUses.Length != 0)) { html += "<div class='section_header'>HUMAN CONNECTIONS</div>"; if (plant.edibility != null && plant.edibility.Length != 0) { html += "<strong>Edibility: </strong>" + plant.edibility + "<br/>"; } if (plant.toxicity != null && plant.toxicity.Length != 0) { html += "<strong>Toxicity: </strong>" + plant.toxicity + "<br/>"; } if (plant.fiber != null && plant.fiber.Length != 0) { html += "<strong>Fiber/Dye: </strong>" + plant.fiber + "<br/>"; } if (plant.otherUses != null && plant.otherUses.Length != 0) { html += "<strong>Other Uses: </strong>" + plant.otherUses + "<br/>"; } } if ((plant.alien != null && plant.alien.Length != 0) || (plant.weedManagement != null && plant.weedManagement.Length != 0)) { html += "<div class='section_header'>Origin</div>"; if (plant.alien != null && plant.alien.Length != 0) { html += plant.alien + "<br/>"; } if (plant.weedManagement != null && plant.weedManagement.Length != 0) { html += "<strong>Weed Management: </strong>" + plant.weedManagement + "<br/>"; } } if ((plant.landscapingUse != null && plant.landscapingUse.Length != 0) || (plant.matureHeight != null && plant.matureHeight.Length != 0) || (plant.matureSpread != null && plant.matureSpread.Length != 0) || (plant.siteRequirements != null && plant.siteRequirements.Length != 0) || (plant.soilRequirements != null && plant.soilRequirements.Length != 0) || (plant.moistureRequirements != null && plant.moistureRequirements.Length != 0) || (plant.cultivar != null && plant.cultivar.Length != 0) || (plant.availability != null && plant.availability.Length != 0)) { html += "<div class='section_header'>LANDSCAPING</div>"; if (plant.landscapingUse != null && plant.landscapingUse.Length != 0) { html += "<strong>Landscaping Use: </strong>" + plant.landscapingUse + "<br/>"; } if (plant.matureHeight != null && plant.matureHeight.Length != 0) { html += "<strong>Mature Height: </strong>" + plant.matureHeight + "<br/>"; } if (plant.matureSpread != null && plant.matureSpread.Length != 0) { html += "<strong>Mature Spread: </strong>" + plant.matureSpread + "<br/>"; } if (plant.siteRequirements != null && plant.siteRequirements.Length != 0) { html += "<strong>Site Requirements: </strong>" + plant.siteRequirements + "<br/>"; } if (plant.soilRequirements != null && plant.soilRequirements.Length != 0) { html += "<strong>Soil Requirements: </strong>" + plant.soilRequirements + "<br/>"; } if (plant.moistureRequirements != null && plant.moistureRequirements.Length != 0) { html += "<strong>Moisture Requirements: </strong>" + plant.moistureRequirements + "<br/>"; } if (plant.cultivar != null && plant.cultivar.Length != 0) { html += "<strong>Cultivar: </strong>" + plant.cultivar + "<br/>"; } if (plant.availability != null && plant.availability.Length != 0) { html += "<strong>Availability: </strong>" + plant.availability + "<br/>"; } } if ((plant.ecologicalRelationships != null && plant.ecologicalRelationships.Length != 0) || (plant.scientificNameMeaning != null && plant.scientificNameMeaning.Length != 0) || (plant.derivation != null && plant.derivation.Length != 0) || (plant.comments != null && plant.comments.Length != 0)) { html += "<div class='section_header'>NOTES</div>"; if (plant.ecologicalRelationships != null && plant.ecologicalRelationships.Length != 0) { html += "<strong>Ecological Relationships: </strong>" + plant.ecologicalRelationships + "<br/>"; } if (plant.scientificNameMeaning != null && plant.scientificNameMeaning.Length != 0) { html += "<strong>Scientific Name Meaning: </strong>" + plant.scientificNameMeaning + "<br/>"; } if (plant.derivation != null && plant.derivation.Length != 0) { html += "<strong>Derivation: </strong>" + plant.derivation + "<br/>"; } if (plant.comments != null && plant.comments.Length != 0) { html += "<strong>Comments: </strong>" + plant.comments + "<br/>"; } } html += "</body></html>"; htmlSource.Html = html; browser.Source = htmlSource; return(browser); }
public WoodyPlantImagesPage(WoodyPlant plant, ObservableCollection <WoodyPlant> plants, bool streaming) { System.GC.Collect(); // 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(0, Device.OnPlatform(10, 0, 0), 0, 0) }; innerContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // Add header to inner container Grid navigationBar = ConstructPlantNavigationBar(plant.commonName, plant, plants); innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); innerContainer.Children.Add(navigationBar, 0, 0); CarouselViewControl carouselControl = new CarouselViewControl(); try { carouselControl.ItemsSource = plant.Images; } catch (NullReferenceException e) { carouselControl.ItemsSource = null; } carouselControl.ShowIndicators = true; DataTemplate imageTemplate = new DataTemplate(() => { Grid cell = new Grid { BackgroundColor = Color.FromHex("88000000") }; cell.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); //cell.RowDefinitions.Add(new RowDefinition { Height = new GridLength(60) }); cell.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); // Add image var image = new ZoomImage { Margin = new Thickness(10, 0, 10, 0) }; string imageBinding = streaming ? "ImagePathStreamed" : "ImagePathDownloaded"; var cachedImage = new CachedImage() { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, WidthRequest = 300, HeightRequest = 300, Aspect = Aspect.AspectFill, Margin = new Thickness(10, 0, 10, 0), CacheDuration = System.TimeSpan.FromDays(30), DownsampleToViewSize = true, RetryCount = 0, RetryDelay = 250, TransparencyEnabled = false, LoadingPlaceholder = "loading.png", ErrorPlaceholder = "error.png", }; image.SetBinding(Image.SourceProperty, new Binding(imageBinding)); cachedImage.SetBinding(CachedImage.SourceProperty, new Binding(imageBinding)); cell.Children.Add(image, 0, 0); return(cell); }); carouselControl.ItemTemplate = imageTemplate; carouselControl.Position = 0; carouselControl.InterPageSpacing = 10; carouselControl.Orientation = CarouselViewOrientation.Horizontal; innerContainer.RowDefinitions.Add(new RowDefinition { }); innerContainer.Children.Add(carouselControl, 0, 1); // 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; System.GC.Collect(); }
public WoodyPlantRangePage(WoodyPlant plant, ObservableCollection <WoodyPlant> plants, bool streaming) { System.GC.Collect(); // 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(0, Device.OnPlatform(10, 0, 0), 0, 0) }; innerContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // Add header to inner container Grid navigationBar = ConstructPlantNavigationBar(plant.commonName, plant, plants); innerContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); innerContainer.Children.Add(navigationBar, 0, 0); ScrollView contentScrollView = new ScrollView { BackgroundColor = Color.FromHex("88000000"), Padding = new Thickness(0, 20, 0, 20), Margin = new Thickness(0, 0, 0, 0) }; StackLayout contentContainer = new StackLayout(); Image rangeImage = new Image { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, WidthRequest = 600, HeightRequest = 300, Aspect = Aspect.AspectFit, Margin = new Thickness(10, 0, 10, 0), }; rangeImage.BindingContext = plant; string imageBinding = streaming ? "RangePathStreamed" : "RangePathDownloaded"; rangeImage.SetBinding(Image.SourceProperty, new Binding(imageBinding)); contentContainer.Children.Add(rangeImage); Image mapKey = new Image { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, WidthRequest = 600, HeightRequest = 300, Aspect = Aspect.AspectFit, Margin = new Thickness(10, 0, 10, 0), }; mapKey.Source = ImageSource.FromResource("WoodyPlants.Resources.Images.WoodyMapKey.png"); contentContainer.Children.Add(mapKey); contentScrollView.Content = contentContainer; innerContainer.RowDefinitions.Add(new RowDefinition { }); innerContainer.Children.Add(contentScrollView, 0, 1); // 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; System.GC.Collect(); }
public TransparentWebView ConstructHTMLContent(WoodyPlant plant) { var browser = new TransparentWebView(); var htmlSource = new HtmlWebViewSource(); string html = ""; html += "<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><meta charset = 'utf-8' /><title>Plant Info Page</title></head><body>"; html += "<style>body { color: white; font-size: 0.9em; padding-bottom: 200px; padding-top: 50px; } .section_header { font-weight: bold; border-bottom: 1px solid white; margin: 10px 0; } .embedded_table { width: 100%; margin-left: 10px; }</style>"; html += "<div class='section_header'>NAME</div>"; if (plant.commonName != null && plant.commonName.Length != 0) { html += "<strong>Common Name: </strong>" + plant.commonName + "<br/>"; } if (plant.scientificNameWeber != null && plant.scientificNameWeber.Length != 0) { html += "<strong>Scientific Name: </strong>" + plant.scientificNameWeber + "<br/>"; } if (plant.scientificNameOther != null && plant.scientificNameOther.Length != 0) { html += "<strong>Synonyms: </strong>" + plant.scientificNameOther + "<br/>"; } if (plant.family != null && plant.family.Length != 0) { html += "<strong>Family: </strong>" + plant.family + "<br/>"; } if (plant.keyCharacteristics != null && plant.keyCharacteristics.Length != 0) { html += "<div class='section_header'>KEY CHARACTERISTICS</div>"; html += plant.keyCharacteristics; } if (plant.flowerDescription != null && plant.flowerDescription.Length != 0) { html += "<div class='section_header'>FLOWER</div>"; html += plant.flowerDescription; } if (plant.seasonOfBloom != null && plant.seasonOfBloom.Length != 0) { html += "<div class='section_header'>SEASON OF BLOOM</div>"; html += plant.seasonOfBloom; } if (plant.fruitDescription != null && plant.fruitDescription.Length != 0) { html += "<div class='section_header'>FRUIT/CONE DESCRIPTION</div>"; html += plant.fruitDescription; } string leafDescrip = ""; if (plant.leafType != null && plant.leafType.Length != 0) { leafDescrip += "<b>Leaf Type: </b>"; leafDescrip += plant.leafType; leafDescrip += "</br>"; } if (plant.leafArrangement != null && plant.leafArrangement.Length != 0) { leafDescrip += "<b>Leaf Arrangement: </b>"; leafDescrip += plant.leafArrangement; } if (!leafDescrip.Equals("")) { html += "<div class='section_header'>LEAF DESCRIPTION</div>"; html += leafDescrip; } if (plant.barkDescription != null && plant.barkDescription.Length != 0) { html += "<div class='section_header'>BARK/STEM DESCRIPTION</div>"; html += plant.barkDescription; } html += "</body></html>"; htmlSource.Html = html; browser.Source = htmlSource; return(browser); }
public Grid ConstructPlantNavigationBar(string titleText, WoodyPlant plant, ObservableCollection <WoodyPlant> plants) { Grid gridLayout = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, ColumnSpacing = 0 }; gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); //BACK gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); gridLayout.Children.Add(BackImageConstructor(), 0, 0); //Favorite icon gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); gridLayout.Children.Add(FavoriteImageConstructor(plant), 1, 0); //Title gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(6, GridUnitType.Star) }); gridLayout.Children.Add(TitleConstructor(titleText), 2, 0); int plantIndex = plants.IndexOf(plant); // add to layout if (plantIndex > 0 && plantIndex < plants.Count - 1) { //Previous gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // gridLayout.Children.Add(PreviousImageConstructor(plants, plantIndex), 3, 0); //Next gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // gridLayout.Children.Add(NextImageConstructor(plants, plantIndex), 4, 0); } else if (plantIndex > 0) { //Previous gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // gridLayout.Children.Add(PreviousImageConstructor(plants, plantIndex), 3, 0); } else if (plantIndex < plants.Count - 1) { //Next gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // gridLayout.Children.Add(NextImageConstructor(plants, plantIndex), 3, 0); } return(gridLayout); }