示例#1
0
            public static string AddSearchVM(SearchVM searchVM)
            {
                var query = searchVM.SearchQuery.ToString();

                AddHistory(searchVM.Keyword);
                srCache.Add(query, searchVM);
                return(query);
            }
示例#2
0
 public InfoVM()
 {
     this.RefreshStatus            = new AsyncCommand(() => Status.RefreshAsync().AsTask(), () => Status != null);
     this.RefreshTaggingStatistics = new AsyncCommand(() => TaggingStatistics.RefreshAsync().AsTask(), () => TaggingStatistics != null);
     this.OpenGallery = new Command <TaggingRecord>(tr =>
     {
         RootControl.RootController.TrackAsyncAction(GalleryVM.GetVMAsync(tr.GalleryInfo).AsAsyncAction(), (s, e) =>
         {
             RootControl.RootController.Frame.Navigate(typeof(GalleryPage), tr.GalleryInfo.ID);
         });
     }, tr => tr.GalleryInfo.ID > 0);
     this.SearchTag = new Command <TaggingRecord>(tr =>
     {
         var vm = SearchVM.GetVM(tr.Tag.Search(Category.All, new AdvancedSearchOptions(skipMasterTags: true, searchLowPowerTags: true)));
         RootControl.RootController.Frame.Navigate(typeof(SearchPage), vm.SearchQuery.ToString());
     }, tr => tr.Tag.Content != null);
 }
示例#3
0
        private GalleryVM()
        {
            this.Share = new Command <GalleryImage>(async image =>
            {
                if (!Helpers.ShareHandler.IsShareSupported)
                {
                    if (image == null)
                    {
                        await Launcher.LaunchUriAsync(this.gallery.GalleryUri, new LauncherOptions {
                            IgnoreAppUriHandlers = true
                        });
                    }
                    else
                    {
                        await Launcher.LaunchUriAsync(image.PageUri, new LauncherOptions {
                            IgnoreAppUriHandlers = true
                        });
                    }
                    return;
                }
                var gallery = this.gallery;
                Helpers.ShareHandler.Share(async(s, e) =>
                {
                    var deferral = e.Request.GetDeferral();
                    try
                    {
                        var data = e.Request.Data;
                        data.Properties.Title       = gallery.GetDisplayTitle();
                        data.Properties.Description = gallery.GetSecondaryTitle();
                        if (image == null)
                        {
                            data.Properties.ContentSourceWebLink = gallery.GalleryUri;
                            data.SetWebLink(gallery.GalleryUri);
                            data.SetText(gallery.GalleryUri.ToString());
                            if (gallery.Thumb != null)
                            {
                                var ms      = new InMemoryRandomAccessStream();
                                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ms);
                                encoder.SetSoftwareBitmap(gallery.Thumb);
                                await encoder.FlushAsync();
                                data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromStream(ms);
                                var firstImage            = gallery.FirstOrDefault()?.ImageFile;
                                if (firstImage != null)
                                {
                                    data.SetBitmap(RandomAccessStreamReference.CreateFromFile(firstImage));
                                }
                                else
                                {
                                    data.SetBitmap(RandomAccessStreamReference.CreateFromStream(ms));
                                }
                            }
                            if (gallery is SavedGallery)
                            {
                                while (gallery.HasMoreItems)
                                {
                                    await gallery.LoadMoreItemsAsync(20);
                                }
                            }
                            var imageFiles = gallery
                                             .Where(i => i.ImageFile != null)
                                             .Select(i => new { i.ImageFile, Name = $"{i.PageID}{i.ImageFile.FileType}" })
                                             .Where(f => f.ImageFile != null)
                                             .ToList();
                            if (imageFiles.Count == 0)
                            {
                                return;
                            }
                            data.SetFolderProvider(imageFiles.Select(f => f.ImageFile), imageFiles.Select(f => f.Name), gallery.GetDisplayTitle());
                        }
                        else
                        {
                            data.Properties.ContentSourceWebLink = image.PageUri;
                            data.SetWebLink(image.PageUri);
                            data.SetText(image.PageUri.ToString());
                            var imageFile = image.ImageFile;
                            if (imageFile == null)
                            {
                                return;
                            }
                            var view = RandomAccessStreamReference.CreateFromFile(imageFile);
                            data.SetBitmap(view);
                            data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromStream(await imageFile.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem));
                            var fileName = $"{image.PageID}{imageFile.FileType}";
                            data.SetFileProvider(imageFile, fileName);
                        }
                    }
                    finally
                    {
                        deferral.Complete();
                    }
                });
            }, image => this.gallery != null);
            this.Save = new Command(() =>
            {
                this.SaveStatus   = OperationState.Started;
                this.SaveProgress = -1;
                var task          = this.gallery.SaveAsync(SettingCollection.Current.GetStrategy());
                task.Progress     = (sender, e) =>
                {
                    this.SaveProgress = e.ImageLoaded / (double)e.ImageCount;
                };
                task.Completed = (sender, e) =>
                {
                    switch (e)
                    {
                    case AsyncStatus.Canceled:
                    case AsyncStatus.Error:
                        this.SaveStatus = OperationState.Failed;
                        RootControl.RootController.SendToast(sender.ErrorCode, null);
                        break;

                    case AsyncStatus.Completed:
                        this.SaveStatus = OperationState.Completed;
                        break;

                    case AsyncStatus.Started:
                        this.SaveStatus = OperationState.Started;
                        break;
                    }
                    this.SaveProgress = 1;
                };
            }, () =>
            {
                if (this.SaveStatus == OperationState.Started)
                {
                    return(false);
                }
                if (this.gallery is SavedGallery)
                {
                    return(false);
                }
                return(true);
            });
            this.OpenImage = new Command <GalleryImage>(image =>
            {
                this.CurrentIndex = image.PageID - 1;
                RootControl.RootController.Frame.Navigate(typeof(ImagePage), this.gallery.ID);
            });
            this.LoadOriginal = new Command <GalleryImage>(async image =>
            {
                image.PropertyChanged += this.Image_PropertyChanged;
                try
                {
                    await image.LoadImageAsync(true, ConnectionStrategy.AllFull, true);
                }
                catch (Exception ex)
                {
                    RootControl.RootController.SendToast(ex, typeof(ImagePage));
                }
                image.PropertyChanged -= this.Image_PropertyChanged;
            }, image => image != null && !image.OriginalLoaded);
            this.ReloadImage = new Command <GalleryImage>(async image =>
            {
                image.PropertyChanged += this.Image_PropertyChanged;
                try
                {
                    if (image.OriginalLoaded)
                    {
                        await image.LoadImageAsync(true, ConnectionStrategy.AllFull, true);
                    }
                    else
                    {
                        await image.LoadImageAsync(true, SettingCollection.Current.GetStrategy(), true);
                    }
                }
                catch (OperationCanceledException) { }
                catch (Exception ex)
                {
                    RootControl.RootController.SendToast(ex, typeof(ImagePage));
                }
                image.PropertyChanged -= this.Image_PropertyChanged;
            }, image => image != null);
            this.SearchUploader = new Command(() =>
            {
                var search = Client.Current.Search(this.gallery.Uploader, null, SettingCollection.Current.DefaultSearchCategory);
                var vm     = SearchVM.GetVM(search);
                RootControl.RootController.Frame.Navigate(typeof(SearchPage), vm.SearchQuery.ToString());
            }, () => this.gallery != null);
            this.SearchImage = new Command <SHA1Value>(sha =>
            {
                var search = Client.Current.Search("", Category.All, Enumerable.Repeat(sha, 1), this.gallery.GetDisplayTitle());
                var vm     = SearchVM.GetVM(search);
                RootControl.RootController.Frame.Navigate(typeof(SearchPage), vm.SearchQuery.ToString());
            }, sha => this.gallery != null && sha != default(SHA1Value));
            this.AddComment = new AsyncCommand(async() =>
            {
                var addComment     = System.Threading.LazyInitializer.EnsureInitialized(ref GalleryVM.addComment);
                addComment.Gallery = this.Gallery;
                await addComment.ShowAsync();
            }, () => this.Gallery != null);
            this.GoToLatestRevision = new Command <RevisionCollection>(c =>
            {
                var info = c.DescendantsInfo.Last().Gallery;
                var load = GetVMAsync(info);
                if (load.Status != AsyncStatus.Completed)
                {
                    RootControl.RootController.TrackAsyncAction(load, async(s, e) =>
                    {
                        await DispatcherHelper.YieldIdle();
                        RootControl.RootController.Frame.Navigate(typeof(GalleryPage), info.ID);
                    });
                }
                else
                {
                    RootControl.RootController.Frame.Navigate(typeof(GalleryPage), info.ID);
                }
            }, c => c != null && c.DescendantsInfo.Count != 0);
        }