public AnimeSeasonalQuery(AnimeSeason season) { _season = season; _overriden = _season.Url != "https://myanimelist.net/anime/season"; Request = WebRequest.Create(Uri.EscapeUriString(_season.Url)); Request.ContentType = "application/x-www-form-urlencoded"; Request.Method = "GET"; }
public AnimeListPageNavigationArgs(SortOptions sort, int status, bool desc, AnimeListWorkModes seasonal, string source, AnimeSeason season, AnimeListDisplayModes dispMode) { SortOption = sort; Status = status; Descending = desc; WorkMode = seasonal; ListSource = source; NavArgs = true; CurrSeason = season; DisplayMode = dispMode; }
private async Task FetchSeasonalData(bool force = false, int page = 0) { if(_fetchingSeasonal) return; _fetchingSeasonal = true; Loading = true; EmptyNoticeVisibility = false; var setDefaultSeason = false; if (CurrentSeason == null) { CurrentSeason = new AnimeSeason {Name = "Airing", Url = "https://myanimelist.net/anime/season"}; setDefaultSeason = true; } ViewModelLocator.GeneralMain.CurrentStatus = "Downloading data...\nThis may take a while..."; //get top or seasonal anime var data = new List<ISeasonalAnimeBaseData>(); page = page == 0 ? 1 : page; switch (WorkMode) { case AnimeListWorkModes.SeasonalAnime: var tResponse = new List<SeasonalAnimeData>(); await Task.Run( new Func<Task>( async () => tResponse = await new AnimeSeasonalQuery(CurrentSeason).GetSeasonalAnime(force))); data.AddRange(tResponse ?? new List<SeasonalAnimeData>()); break; case AnimeListWorkModes.TopAnime: case AnimeListWorkModes.TopManga: var topResponse = new List<TopAnimeData>(); await Task.Run( new Func<Task>( async () => topResponse = await new AnimeTopQuery( WorkMode == AnimeListWorkModes.TopAnime ? TopAnimeWorkMode : TopAnimeType.Manga, page - 1).GetTopAnimeData(force))); data.AddRange(topResponse ?? new List<TopAnimeData>()); break; case AnimeListWorkModes.AnimeByGenre: case AnimeListWorkModes.AnimeByStudio: var sResponse = new List<SeasonalAnimeData>(); var query = WorkMode == AnimeListWorkModes.AnimeByStudio ? new AnimeGenreStudioQuery(Studio,page) : new AnimeGenreStudioQuery(Genre,page); await Task.Run(new Func<Task>(async () => sResponse = await query.GetAnime())); data.AddRange(sResponse ?? new List<SeasonalAnimeData>()); break; default: throw new ArgumentOutOfRangeException(); } //if we don't have any we cannot do anything I guess... if (data.Count == 0) { _fetchingSeasonal = false; RefreshList(); return; } List<AnimeItemAbstraction> source; List<AnimeItemAbstraction> target; if (WorkMode == AnimeListWorkModes.TopManga) { //We have to load base mnga item first if not loaded before. if (AllLoadedMangaItemAbstractions.Count == 0 && !_attemptedMangaFetch) await FetchData(false, AnimeListWorkModes.Manga); target = _allLoadedSeasonalMangaItems = new List<AnimeItemAbstraction>(); source = _allLoadedAuthMangaItems.Count > 0 ? _allLoadedAuthMangaItems : new List<AnimeItemAbstraction>(); } else { if (AllLoadedAnimeItemAbstractions.Count == 0 && !_attemptedAnimeFetch) await FetchData(false, AnimeListWorkModes.Anime); if (WorkMode == AnimeListWorkModes.AnimeByGenre || WorkMode == AnimeListWorkModes.AnimeByStudio && page > 1) { target = _allLoadedSeasonalAnimeItems; } else { target = _allLoadedSeasonalAnimeItems = new List<AnimeItemAbstraction>(); } source = _allLoadedAuthAnimeItems.Count > 0 ? _allLoadedAuthAnimeItems : new List<AnimeItemAbstraction>(); } var updateScore = Settings.SelectedApiType == ApiType.Mal; foreach (var animeData in data) { try { if (WorkMode == AnimeListWorkModes.SeasonalAnime && Settings.SelectedApiType == ApiType.Mal) //seasonal anme comes with mal score, we don't want to polute hummingbird data DataCache.RegisterVolatileData(animeData.Id, new VolatileDataCache { DayOfAiring = animeData.AirDay, GlobalScore = animeData.Score, Genres = animeData.Genres, AirStartDate = animeData.AirStartDate == AnimeItemViewModel.InvalidStartEndDate ? null : animeData.AirStartDate }); AnimeItemAbstraction abstraction = null; if (Settings.SelectedApiType == ApiType.Mal) abstraction = source.FirstOrDefault(item => item.Id == animeData.Id); else abstraction = source.FirstOrDefault(item => item.MalId == animeData.Id); if (abstraction == null) target.Add(new AnimeItemAbstraction(animeData as SeasonalAnimeData, WorkMode != AnimeListWorkModes.TopManga)); else { if(animeData.AirDay != -1) abstraction.AirDay = animeData.AirDay; if (updateScore) abstraction.GlobalScore = animeData.Score; abstraction.Index = animeData.Index; abstraction.ViewModel.UpdateWithSeasonData(animeData as SeasonalAnimeData, updateScore); target.Add(abstraction); } } catch (Exception e) { // wat } } if (WorkMode == AnimeListWorkModes.SeasonalAnime && SeasonSelection.Count == 0) { SeasonSelection.Clear(); var i = 0; var currSeasonIndex = -1; foreach (var seasonalUrl in DataCache.SeasonalUrls) { if (seasonalUrl.Key != "current") { SeasonSelection.Add(new AnimeSeason {Name = seasonalUrl.Key, Url = seasonalUrl.Value}); i++; } else currSeasonIndex = Convert.ToInt32(seasonalUrl.Value) - 1; if (seasonalUrl.Key == CurrentSeason.Name) { _seasonalUrlsSelectedIndex = i - 1; RaisePropertyChanged(() => SeasonalUrlsSelectedIndex); } } //we have set artificial default one because we did not know what lays ahead of us if (setDefaultSeason && currSeasonIndex != -1) { CurrentSeason = SeasonSelection[currSeasonIndex]; _seasonalUrlsSelectedIndex = currSeasonIndex; RaisePropertyChanged(() => SeasonalUrlsSelectedIndex); } } _fetchingSeasonal = false; RefreshList(); }
public async void Init(AnimeListPageNavigationArgs args) { //base _scrollHandlerAdded = false; Initializing = true; _manuallySelectedViewMode = null; //take out trash _animeItemsSet = new List<AnimeItemAbstraction>(); AnimeItems = new SmartObservableCollection<AnimeItemViewModel>(); RaisePropertyChanged(() => AnimeItems); _randomedIds = new List<int>(); _fetching = _fetchingSeasonal = false; CurrentPage = 1; if (args == null || args.ResetBackNav) ViewModelLocator.NavMgr.ResetMainBackNav(); if (!_queryHandler) { ViewModelLocator.GeneralMain.OnSearchDelayedQuerySubmitted += OnOnSearchDelayedQuerySubmitted; ViewModelLocator.GeneralMain.OnSearchQuerySubmitted += OnOnSearchDelayedQuerySubmitted; } _queryHandler = true; //give visual feedback Loading = true; LoadMoreFooterVisibility = false; await Task.Delay(10); //depending on args var gotArgs = false; if (args != null) //Save current mode { ResetedNavBack = args.ResetBackNav; WorkMode = args.WorkMode; if (WorkMode == AnimeListWorkModes.TopAnime) { TopAnimeWorkMode = args.TopWorkMode; ViewModelLocator.GeneralHamburger.SetActiveButton(args.TopWorkMode);//we have to have it } else if (WorkMode == AnimeListWorkModes.AnimeByGenre) { Genre = args.Genre; } else if(WorkMode == AnimeListWorkModes.AnimeByStudio) { Studio = args.Studio; } if (!string.IsNullOrEmpty(args.ListSource)) ListSource = args.ListSource; else ListSource = Credentials.UserName; if (args.NavArgs) // Use args if we have any { SortDescending = SortDescending = args.Descending; SetSortOrder(args.SortOption); //index SetDesiredStatus(args.Status); CurrentIndexPosition = args.SelectedItemIndex; CurrentSeason = args.CurrSeason; DisplayMode = args.DisplayMode; gotArgs = true; } } else //assume default AnimeList { WorkMode = AnimeListWorkModes.Anime; ListSource = Credentials.UserName; } ViewModelLocator.GeneralHamburger.UpdateAnimeFiltersSelectedIndex(); RaisePropertyChanged(() => CurrentlySelectedDisplayMode); switch (WorkMode) { case AnimeListWorkModes.Manga: case AnimeListWorkModes.Anime: if (!gotArgs) SetDefaults(args?.StatusIndex); AppBtnListSourceVisibility = true; AppbarBtnPinTileVisibility = false; AppBtnSortingVisibility = true; AnimeItemsDisplayContext = AnimeItemDisplayContext.AirDay; if (WorkMode == AnimeListWorkModes.Anime) { SortAirDayVisibility = true; Sort3Label = "Watched"; StatusAllLabel = "All"; Filter1Label = "Watching"; Filter5Label = "Plan to watch"; } else // manga { SortAirDayVisibility = false; Sort3Label = "Read"; StatusAllLabel = "All"; Filter1Label = "Reading"; Filter5Label = "Plan to read"; } //try to set list source - display notice on fail if (string.IsNullOrWhiteSpace(ListSource)) { if (!string.IsNullOrWhiteSpace(Credentials.UserName)) ListSource = Credentials.UserName; } if (string.IsNullOrWhiteSpace(ListSource)) { EmptyNoticeVisibility = true; EmptyNoticeContent = "We have come up empty...\nList source is not set.\nLog in or set it manually."; BtnSetSourceVisibility = true; Loading = false; } else await FetchData(); //we have source we can fetch break; case AnimeListWorkModes.SeasonalAnime: case AnimeListWorkModes.TopAnime: case AnimeListWorkModes.TopManga: case AnimeListWorkModes.AnimeByGenre: case AnimeListWorkModes.AnimeByStudio: Loading = true; EmptyNoticeVisibility = false; AppBtnListSourceVisibility = false; AppBtnGoBackToMyListVisibility = false; BtnSetSourceVisibility = false; ViewModelLocator.NavMgr.DeregisterBackNav(); ViewModelLocator.NavMgr.RegisterBackNav(PageIndex.PageAnimeList, null); if (!gotArgs) { SortDescending = false; SetSortOrder(SortOptions.SortWatched); //index SetDesiredStatus(null); CurrentSeason = null; SeasonSelection.Clear(); } //StatusAllLabel = WorkMode == AnimeListWorkModes.SeasonalAnime ? "Airing" : "All"; Sort3Label = "Index"; await FetchSeasonalData(); if (WorkMode == AnimeListWorkModes.TopAnime || WorkMode == AnimeListWorkModes.TopManga) { AppbarBtnPinTileVisibility = AppBtnSortingVisibility = false; if (CurrentPage <= 4) LoadMoreFooterVisibility = true; AnimeItemsDisplayContext = AnimeItemDisplayContext.Index; } else { if (CurrentPage <= 4) LoadMoreFooterVisibility = true; if (WorkMode == AnimeListWorkModes.AnimeByGenre || WorkMode == AnimeListWorkModes.AnimeByStudio) { AppbarBtnPinTileVisibility = false; AppBtnSortingVisibility = true; } else AppbarBtnPinTileVisibility = AppBtnSortingVisibility = true; AnimeItemsDisplayContext = AnimeItemDisplayContext.AirDay; } break; default: throw new ArgumentOutOfRangeException(); } RaisePropertyChanged(() => LoadAllDetailsButtonVisiblity); SortingSettingChanged?.Invoke(SortOption, SortDescending); Initializing = false; UpdateUpperStatus(); }