async void GetPreviews() { List <string> preppedTags = new List <string>(Tags.Length); Debug.WriteLine("Getting previews for Search: " + AllTags); var i = 0; foreach (var tag in Tags) { if (!string.IsNullOrEmpty(tag)) { preppedTags.Add(tag.Replace(" ", "_") + " "); } i++; } if (!string.IsNullOrEmpty(BooruApi.ApiKey)) { preppedTags.Add("order:score"); } var result = (await BooruApi.SearchPosts(preppedTags.ToArray(), 1, 4)); if (result.Item2 != null && result.Item2.Count > 0) { var imageResults = result.Item2.Select(x => x.Preview_File_Url).ToArray(); SearchPreview = imageResults; Debug.WriteLine("Got all images"); } }
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(); }