private async void btnRecover_Clicked(object sender, EventArgs e) { try { List <ImageInfo> listImages = new List <ImageInfo>(); if (Selected >= 1) { listImages = TrashImages.Where(x => x.Selected == true).ToList <ImageInfo>(); } else { listImages = TrashImages.ToList <ImageInfo>(); } bool answer = await RecoverConfirmNotifications(listImages.Count); if (answer) { foreach (ImageInfo _image in listImages) { FileManager.RestoreFile(_image.ImagePath); } await LoadBitmapCollection(); ShowToastMessage("Photos moved to unsorted!"); } } catch (Exception ex) { await DisplayAlert("Error", "An error has ocurred: " + ex.Message, "OK"); } }
private async Task AddImage(string filepath) { string imagePath = await Task <string> .Factory.StartNew(() => FileManager.GetCompressedImage(filepath, 150, 150)); Device.BeginInvokeOnMainThread(async() => { CachedImage image = new CachedImage { Source = await Task <ImageSource> .Factory.StartNew(() => ImageSource.FromFile(imagePath)), HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, HeightRequest = 120, WidthRequest = 120, Aspect = Aspect.Fill, AutomationId = filepath, IsOpaque = true, BackgroundColor = Color.Gray }; image.DownsampleToViewSize = true; image.CacheDuration = new TimeSpan(5, 0, 0, 0); var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.NumberOfTapsRequired = 1; tapGestureRecognizer.Tapped += (s, e) => { ImageInfo ui = TrashImages.Where(x => x.ImagePath == image.AutomationId).First(); if (image.BackgroundColor == Color.White) { image.BackgroundColor = Color.Transparent; image.Opacity = 1; Selected--; ui.Selected = false; } else { image.BackgroundColor = Color.White; image.Opacity = 0.25; Selected++; ui.Selected = true; } setButtonBindings(Selected); }; image.GestureRecognizers.Add(tapGestureRecognizer); Grid.SetColumn(image, colPosition); Grid.SetRow(image, rowPosition); flexLayout.Children.Add(image); colPosition++; if (colPosition == 3) { colPosition = 0; rowPosition++; } }); }
async Task LoadBitmapCollection() { setButtonBindings(Selected); try { Selected = 0; await Task.Run(async() => { TrashImages.Clear(); Device.BeginInvokeOnMainThread(() => { flexLayout.Children.Clear(); }); ImageList imageList = FileManager.GetTrashImages(); foreach (string filepath in imageList.Photos) { TrashImages.Add(new ImageInfo(filepath)); } rowPosition = 0; colPosition = 0; if (TrashImages.Count > 0) { foreach (ImageInfo _image in TrashImages) { await AddImage(_image.ImagePath); } } else { AddEmptyTrashMessage("Empty Trash...", 18); } }); } catch (Exception ex) { AddEmptyTrashMessage(string.Format("Cannot access list of bitmap files: {0}", ex.Message), 12); } finally { } }