public void Refresh() { container = DatabaseHandler.GetDatabase().GetContainer(id, container.GetLocation()); //set title this.Title = container.GetName(); //set proportions this.imageFrame.HeightRequest = MasterNavigationPage.current.Height / 2.0; //set text SetNotes(); //init image if (ImageTools.HasImage(container)) { if (ImageBaseHandler.current.isContainerCached(container.GetId())) { SetImage(ImageBaseHandler.current.GetContainerImageSource(container.GetId())); } else { SetImage(ImageTools.LoadImage(container)); } } else //if no image give it the place holder image { Console.WriteLine("no image"); SetImage("camera"); } //init tags tagDisplay.ClearTags(); if (container.GetTags().Count != 0 && !(container.GetTags().Count == 1 && container.GetTags()[0] == "")) { tagDisplay.AddTagToBatchWithoutClick(container.GetTags()); } //remove uneeded lines if (container.GetNotes().Trim() == "") { notesLabel.Hide(); notesDivider.Hide(); } else { notesLabel.Show(); notesDivider.Show(); } //set colors this.BackgroundColor = PageColors.secondaryColor; }
//loads the image for the container and returns a ImageSource public static Xamarin.Forms.ImageSource LoadImage(StorageContainer containerIn) { int id = containerIn.GetId(); Xamarin.Forms.ImageSource returnSource = LoadImage(Path.Combine(Directories.containerImageDirectory, id.ToString() + ".jpg")); ImageBaseHandler.current.AddContainerImage(containerIn.GetId(), returnSource); return(returnSource); }
private void SetImage() { if (ImageTools.HasImage(container)) { if (ImageBaseHandler.current.isContainerCached(container.GetId())) { this.Source = ImageBaseHandler.current.GetContainerImageSource(container.GetId()); } else { this.Source = ImageTools.LoadImage(container); } } else { Source = "camera"; } }
private bool deleted = false; //whether or the page's container has been deleted public ContainerPage(StorageContainer container) { this.container = container; this.Title = container.GetName(); this.id = container.GetId(); InitializeComponent(); this.optionsTable.Margin = new Thickness(15, 5, 15, 5); InitButtons(); Refresh(); //the resfresh method also initializes the page }
//moves all the hightlighted items to the given container private void MoveHighlightedItems(StorageContainer con) { foreach (HighlightedItemImageButton button in currentButtons) { if (button.IsHighlighted()) //delete if highlighted { Console.WriteLine("moving"); DatabaseHandler.GetDatabase().MoveItem(button.item.GetId(), con.GetId()); } } Refresh(); DataTools.Save(); }
public void Refresh() { container = DatabaseHandler.GetDatabase().GetContainer(id, container.GetLocation()); ; //set title this.Title = container.GetName(); //set proportions this.imageFrame.HeightRequest = MasterNavigationPage.current.Height / 2.0; //init image if (ImageTools.HasImage(container)) { if (ImageBaseHandler.current.isContainerCached(container.GetId())) { SetImage(ImageBaseHandler.current.GetContainerImageSource(container.GetId())); } else { SetImage(ImageTools.LoadImage(container)); } } else //if no image give it the place holder image { SetImage("camera"); } //set colors this.BackgroundColor = PageColors.secondaryColor; }
public async void Delete() { //displays a pop up asking if the user is sure bool choice = await DisplayAlert("Are you sure?", "Deleting this container will delete all the items inside of the container", "Delete", "Cancel"); if (choice) { DatabaseHandler.GetDatabase().DeleteContainer(container.GetId()); DataTools.Save(); await Navigation.PopAsync(); deleted = true; } else { deleted = false; } }
public ContainerDetailsPage(StorageContainer container) { this.container = container; this.id = container.GetId(); InitializeComponent(); this.Appearing += (sen, e) => Refresh(); this.imageFrame.Content = img; img.VerticalOptions = LayoutOptions.FillAndExpand; img.HorizontalOptions = LayoutOptions.FillAndExpand; img.Aspect = Aspect.AspectFit; //set colors this.notesLabel.TextColor = PageColors.textColor; Refresh(); }
//for editing a preexisting container public NewContainerPage(string name, string notes, List <string> tags, int id, StorageContainer prevContainer, StorageLocation location) : base() { this.location = location; InitializeComponent(); InitContent(); newContainerId = id; this.nameInput.Text = name; this.notesEditor.Text = notes; this.previousContainer = prevContainer; this.isEditing = true; if (isEditing) { this.Title = "Editing"; } tagDisplay = new TagDisplay(); this.tagDisplayWrapper.Children.Add(tagDisplay); tagDisplay.AddTagBatch(tags); //set colors this.BackgroundColor = PageColors.secondaryColor; InitContent(); //set image if (ImageTools.HasImage(previousContainer)) { if (ImageBaseHandler.current.isContainerCached(previousContainer.GetId())) { SetImageHolderContent(ImageBaseHandler.current.GetContainerImageSource(previousContainer.GetId())); } else { ImageSource imageLoadTask = ImageTools.LoadImage(System.IO.Path.Combine(Directories.locationImageDirectory, id.ToString() + ".jpg")); SetImageHolderContent(imageLoadTask); } } }
//makes the menu page to open private PopupPageMenu MakeMenuPage() { PopupPageMenu menu = new PopupPageMenu(); //move container menu button Grid moveContainerGrid = menu.AddLabelAndImage("Move Container", "move_to_container"); TapGestureRecognizer moveContainerGesture = new TapGestureRecognizer(); ContainerWrapper containerWrapper = new ContainerWrapper(); //to call when the container is selected Action callOnMoveSelected = () => { if (containerWrapper.Container != null) { MoveHighlightedItems(containerWrapper.Container); PopupNavigation.Instance.PushAsync(new PopupTextNotification("Items moved")); container = DatabaseHandler.GetDatabase().GetContainer(container.GetId(), container.GetLocation()); MasterNavigationPage.current.Refresh(); } }; moveContainerGesture.Tapped += (sen, e) => { PopupNavigation.Instance.PopAsync(); if (container.GetLocation().GetContainers().Count <= 1) //if there arent enough locations to move, display an error { PopupNavigation.Instance.PushAsync(new PopupErrorNotification("You need more containers to do that")); } else { Navigation.PushAsync(new ContainerSelectPage(containerWrapper, callOnMoveSelected, container.GetLocation().GetContainers(), new List <int>() { container.GetId() })); } }; moveContainerGrid.GestureRecognizers.Add(moveContainerGesture); //delete item menu button Grid deleteItemGrid = menu.AddLabelAndImage("Delete Items", "trash"); TapGestureRecognizer deleteItemGesture = new TapGestureRecognizer(); deleteItemGesture.Tapped += (sen, e) => { if (CanDelete()) //if can delete - delete, else give error messxage { Delete(); PopupNavigation.Instance.PopAsync(); } else { PopupNavigation.Instance.PushAsync(new PopupErrorNotification("Unable to delete")); } }; deleteItemGrid.GestureRecognizers.Add(deleteItemGesture); return(menu); }
//makes the element for a search result private Grid MakeResultElement(ISearchable result) { Grid returnGrid = new Grid(); ImageSource imgSource = "camera"; ImageButton gridImage = new ImageButton(); //get correct image source //if none is found - the source will default to the camera source if (typeof(StorageLocation).IsInstanceOfType(result)) { StorageLocation resultLocation = (StorageLocation)result; TapGestureRecognizer gesture = new TapGestureRecognizer(); gesture.Tapped += (sen, e) => { Navigation.PushAsync(new LocationPage(resultLocation)); }; returnGrid.GestureRecognizers.Add(gesture); gridImage.Clicked += (sen, e) => { Navigation.PushAsync(new LocationPage(resultLocation)); }; if (ImageTools.HasImage(resultLocation)) { if (ImageBaseHandler.current.isLocationCached(resultLocation.GetId())) //check for caching of image { imgSource = ImageBaseHandler.current.GetLocationImageSource(resultLocation.GetId()); } else { imgSource = ImageTools.LoadImage(resultLocation); } } } else if (typeof(StorageContainer).IsInstanceOfType(result)) { StorageContainer resultContainer = (StorageContainer)result; TapGestureRecognizer gesture = new TapGestureRecognizer(); gesture.Tapped += (sen, e) => { Navigation.PushAsync(new ContainerPage(resultContainer)); }; returnGrid.GestureRecognizers.Add(gesture); gridImage.Clicked += (sen, e) => { Navigation.PushAsync(new ContainerPage(resultContainer)); }; if (ImageTools.HasImage(resultContainer)) { if (ImageBaseHandler.current.isContainerCached(resultContainer.GetId())) //check for caching of image { imgSource = ImageBaseHandler.current.GetContainerImageSource(resultContainer.GetId()); } else { imgSource = ImageTools.LoadImage(resultContainer); } } } else if (typeof(Item).IsInstanceOfType(result)) { Item resultItem = (Item)result; TapGestureRecognizer gesture = new TapGestureRecognizer(); gesture.Tapped += (sen, e) => { Navigation.PushAsync(new ItemDetailsPage(resultItem)); }; returnGrid.GestureRecognizers.Add(gesture); gridImage.Clicked += (sen, e) => { Navigation.PushAsync(new ItemDetailsPage(resultItem)); }; if (ImageTools.HasImage(resultItem)) { if (ImageBaseHandler.current.isItemCached(resultItem.GetId())) //check for caching of image { imgSource = ImageBaseHandler.current.GetItemImageSource(resultItem.GetId()); } else { imgSource = ImageTools.LoadImage(resultItem); } } } ColumnDefinition imageColumn = new ColumnDefinition() { Width = new GridLength(0.2, GridUnitType.Star) }; ColumnDefinition nameColumn = new ColumnDefinition() { Width = new GridLength(0.8, GridUnitType.Star) }; returnGrid.ColumnDefinitions.Add(imageColumn); returnGrid.ColumnDefinitions.Add(nameColumn); gridImage.Source = imgSource; gridImage.BackgroundColor = Color.Transparent; Grid.SetColumn(gridImage, 0); returnGrid.Children.Add(gridImage); Label nameLabel = new Label() { Text = result.GetName() }; nameLabel.TextColor = PageColors.textColor; nameLabel.FontSize = FontSizes.subTitleFont; nameLabel.VerticalTextAlignment = TextAlignment.Center; Grid.SetColumn(nameLabel, 1); returnGrid.Children.Add(nameLabel); returnGrid.HeightRequest = MasterNavigationPage.current.Height / SEARCH_RESULTS_ON_PAGE; return(returnGrid); }
//returns true if the container has an image public static bool HasImage(StorageContainer containerIn) { int id = containerIn.GetId(); return(HasImage(Path.Combine(Directories.containerImageDirectory, id.ToString() + ".jpg"))); }
public async void Edit() { NewContainerPage editPage = new NewContainerPage(container.GetName(), container.GetNotes(), container.GetTags(), container.GetId(), container, container.GetLocation()); await Navigation.PushAsync(editPage); }