Пример #1
0
        public HomePageViewModel()
        {
            Contributions = new IncrementalLoadingCollection <ContributionsModel>(LoadMoreItems)
            {
                BatchSize = SelectedBatchSize
            };

            if (DesignMode.DesignModeEnabled)
            {
                var designItems = DesignTimeHelpers.GenerateContributions();

                foreach (var contribution in designItems)
                {
                    Contributions.Add(contribution);
                }
            }

            RefreshAfterDisconnectCommand = new DelegateCommand(async() =>
            {
                IsInternetDisabled = !NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable;

                if (IsInternetDisabled)
                {
                    await new MessageDialog("Internet is still not available, please check your connection and try again.", "No Internet").ShowAsync();
                }
                else
                {
                    await BootStrapper.Current.NavigationService.NavigateAsync(typeof(LoginPage));
                }
            });
        }
Пример #2
0
        private async Task StartLoadFile()
        {
            IsNewStart = false;

            SecureFolder = await ApplicationData.Current.LocalCacheFolder.CreateFolderAsync("SecureFolder", CreationCollisionOption.OpenIfExists);

            QueryOptions Options = new QueryOptions
            {
                FolderDepth   = FolderDepth.Shallow,
                IndexerOption = IndexerOption.UseIndexerWhenAvailable
            };

            Options.SetThumbnailPrefetch(ThumbnailMode.ListView, 100, ThumbnailOptions.ResizeThumbnail);
            Options.SetPropertyPrefetch(PropertyPrefetchOptions.BasicProperties, new string[] { "System.ItemTypeText", "System.ItemNameDisplayWithoutExtension", "System.FileName", "System.Size", "System.DateModified" });

            StorageItemQueryResult ItemQuery = SecureFolder.CreateItemQueryWithOptions(Options);

            IReadOnlyList <IStorageItem> EncryptedFileList = await ItemQuery.GetItemsAsync(0, 100);

            if (EncryptedFileList.Count == 0)
            {
                EmptyTips.Visibility = Visibility.Visible;
            }

            SecureGridView.Visibility = Visibility.Visible;

            foreach (var Item in EncryptedFileList)
            {
                var Size = await Item.GetSizeRawDataAsync().ConfigureAwait(true);

                var Thumbnail    = new BitmapImage(new Uri("ms-appx:///Assets/LockFile.png"));
                var ModifiedTime = await Item.GetModifiedTimeAsync().ConfigureAwait(true);

                SecureCollection.Add(new FileSystemStorageItemBase(Item as StorageFile, Size, Thumbnail, ModifiedTime));
            }

            await SecureCollection.SetStorageQueryResultAsync(ItemQuery).ConfigureAwait(false);
        }
        public MoviePageViewModel()
        {
            MovieListCollection = new IncrementalLoadingCollection <MovieListModel>(CommonDataLoader.GetMovieListModel);
#if DEBUG
            if (DesignMode.DesignModeEnabled)
            {
                MovieListCollection.Add(new MovieListModel
                {
                    Cover = "ms-appx:///Resources/Test/cover.png",
                    Id    = "34",
                    Title = "卧虎藏龙2:青冥宝剑",
                    Score = "39"
                });
                MovieListCollection.Add(new MovieListModel
                {
                    Cover = "ms-appx:///Resources/Test/cover.png",
                    Id    = "34",
                    Title = "卧虎藏龙2:青冥宝剑",
                    Score = "39"
                });
            }
#endif
        }
Пример #4
0
        private async Task Fetch(uint page)
        {
            LoadingRing.IsActive = true;

            var data = await blogApi.GetListAsync(page);

            if (data.Item1 != null)
            {
                foreach (var blog in data.Item1)
                {
                    Blogs.Add(blog);
                }
            }
            MoreBtn.Visibility   = data.Item2 ? Visibility.Visible : Visibility.Collapsed;
            LoadingRing.IsActive = false;
        }
        public MainPageViewModel()
        {
            _appSettings = ApplicationData.Current.RoamingSettings.Values;
            var savedUn     = _appSettings["Username"] as string;
            var savedApiKey = _appSettings["APIKey"] as string;

            if (_appSettings["PerPage"] != null)
            {
                _perPage = (int)_appSettings["PerPage"];
            }
            if (_appSettings["SafeChecked"] != null)
            {
                _safeChecked = (bool)_appSettings["SafeChecked"];
            }
            if (_appSettings["QuestionableChecked"] != null)
            {
                _questionableChecked = (bool)_appSettings["QuestionableChecked"];
            }
            if (_appSettings["ExplicitChecked"] != null)
            {
                _explicitChecked = (bool)_appSettings["ExplicitChecked"];
            }
            if (_appSettings["UseLargerImagesForThumbnails"] != null)
            {
                _useLargerImagesForThumbnails = (bool)_appSettings["UseLargerImagesForThumbnails"];
            }


            GlobalInfo.ContentCheck[0] = _safeChecked;
            GlobalInfo.ContentCheck[1] = _questionableChecked;
            GlobalInfo.ContentCheck[2] = _explicitChecked;

            if (!string.IsNullOrEmpty(savedUn))
            {
                Debug.WriteLine("username not empty it's " + _appSettings["Username"] + ". APIKey is " + _appSettings["APIKey"]);

                _username = savedUn;
                if (!string.IsNullOrEmpty(savedApiKey))
                {
                    ApiKey = savedApiKey;
                    BooruApi.SetLogin(savedUn, savedApiKey);
                }
                else
                {
                    ApiKey = "";
                    BooruApi.SetLogin(savedUn, "");
                }
            }


            Debug.WriteLine("Count for saved Searches is " + SavedSearches.Count);
            BooruApi.TagSearchCompletedHandler += (sender, tuple) =>
            {
                if (tuple.Item1 && _currentTag.Length > 0)
                {
                    foreach (var tag in tuple.Item2)
                    {
                        _suggestedTags.Add(tag.Name);
                    }
                    RaisePropertyChanged("SuggestedTags");
                }
            };
            GlobalInfo.SavedSearchesLoaded += (sender, e) =>
            {
                if (GlobalInfo.SavedSearches.Count > 0)
                {
                    foreach (var search in GlobalInfo.SavedSearches)
                    {
                        _savedSearches.Add(new SavedSearchViewModel(search, this));
                    }
                    RaisePropertyChanged("SavedSearches");
                    RaisePropertyChanged("DontHaveSavedSearches");
                }
            };

            GlobalInfo.FavouriteTagsLoaded += (sender, args) =>
            {
                if (GlobalInfo.FavouriteTags.Count > 0)
                {
                    foreach (var tag in GlobalInfo.FavouriteTags)
                    {
                        _favouriteTags.First(x => x.Key == tag.category).Add(new TagViewModel(tag, this));
                    }
                    foreach (GroupInfoList t1 in _favouriteTags)
                    {
                        var tagList = t1;
                        var result  = from t in tagList
                                      orderby t.Name
                                      select t;
                        tagList = new GroupInfoList(result.ToList());
                    }
                    RaisePropertyChanged("FavouriteTags");
                    RaisePropertyChanged("DontHaveSavedSearches");
                }
            };
            GlobalInfo.FavouriteImagesLoadedEventHandler += (sender, args) =>
            {
                RaisePropertyChanged("FavouritePostCount");
            };
            GlobalInfo.LoadSavedForLaterImages();
            _savedForLater = new ObservableCollection <FullImageViewModel>();
            GlobalInfo.ImagesSavedForLaterLoaded += (sender, args) =>
            {
                _savedForLater = new ObservableCollection <FullImageViewModel>();
                foreach (var image in GlobalInfo.ImagesSavedForLater)
                {
                    _savedForLater.Add(new FullImageViewModel(image, image.id, image.Preview_File_Url, image.Large_File_Url, "https://danbooru.donmai.us/posts/" + image.id, null, null));
                }
                RaisePropertyChanged("SavedForLater");
            };


            _thumbnails = new IncrementalLoadingCollection <PostSource, FullImageViewModel>(_perPage);
            //BooruApi.Page = 1;
            foreach (var model in GlobalInfo.ImageViewModels)
            {
                _thumbnails.Add(model);
            }
            Thumbnails.OnStartLoading = () =>
            {
                IsLoading    = true;
                NoImagesText = "Loading";
            };
            Thumbnails.OnEndLoading = ImageOnLoadFinish;
            Thumbnails.OnError      = ImageLoadOnError;

            BooruApi.UserLookupEvent += (sender, args) =>
            {
                var tags = BooruApi.UserModel?.blacklisted_tags.Split('\r');
                if (tags != null && tags.Length > 0)
                {
                    foreach (var tag in tags)
                    {
                        if (tag.Trim() != "")
                        {
                            var name = tag.Replace("\n", "");
                            ExcludedTags.Add(new TagViewModel(new Tag(name.Trim())));
                            RaisePropertyChanged("ExcludedTags");
                        }
                    }
                }
            };
            ImageSaver.ImageFolderLoadedEventHandler += delegate { RaisePropertyChanged("SaveFolder"); };
            BooruApi.GetUser();
        }