コード例 #1
0
        private async Task OnResetFilter()
        {
            var checkeds = FilterData.Genres.Where(p => p.IsChecked);

            FilterData.SortDirections[0].IsChecked = true;
            FilterData.Orders[0].IsChecked         = true;

            foreach (var item in checkeds)
            {
                item.IsChecked = false;
            }

            MessagingCenter.Send(this, "CloseFilterView");
            switch (_catalogueMode)
            {
            case CatalogueModeEnum.Season:

                Loading = true;
                _animesWithSpecifiedFilters = null;
                Animes.ReplaceRange(_originalCollection);
                Loading = false;

                break;

            case CatalogueModeEnum.Global:

                ResetSearchConfig(_settingsPreferences.ShowNSFW, AnimeSearchSortable.Score, SortDirection.Descending);

                await ResetAndLoadGlobalAsync();

                break;
            }
        }
コード例 #2
0
        private async Task OnChangeSeason()
        {
            try
            {
                Loading = true;
                ClearTextQuery();

                await App.DelayRequest();

                Lazy <ResourceManager> ResMgr = new Lazy <ResourceManager>(
                    () => new ResourceManager(typeof(Lang.Lang)));

                string selectedSeasonEnUs = string.Empty;
                foreach (var seasonKey in SeasonData.SeasonKeys)
                {
                    string seasonName = ResMgr.Value.GetString(seasonKey.ToString());

                    if (SeasonData.SelectedSeason == seasonName)
                    {
                        selectedSeasonEnUs = seasonKey.ToString();
                        break;
                    }
                }

                var selectedSeasonEnum = (JikanDotNet.Seasons)Enum.Parse(typeof(JikanDotNet.Seasons), selectedSeasonEnUs);

                var result = await App.Jikan.GetSeason(SeasonData.SelectedYear.Value, selectedSeasonEnum);

                result.RequestCached = true;

                var favoritedEntries = await result.SeasonEntries.ConvertCatalogueAnimesToFavoritedAsync(_settingsPreferences.ShowNSFW);

                _originalCollection = favoritedEntries.OrderByDescending(p => p.Anime.Score).ToList();
                Animes.ReplaceRange(_originalCollection);

                Loading = false;
            }
            catch (JikanRequestException ex)
            {
                ex.SaveExceptionData();
            }
            catch (OperationCanceledException ex)
            { }
            catch (Exception ex)
            {
                ex.SaveExceptionData();
            }
        }
コード例 #3
0
        private async Task OnApplyFilter()
        {
            var selectedGenres = FilterData.Genres.Where(p => p.IsChecked).Select(p => p.Genre).ToList();
            var selectedOrder  = FilterData.Orders.Where(p => p.IsChecked).First();
            var selectedSort   = FilterData.SortDirections.Where(p => p.IsChecked).First();

            _animeSearchConfig.OrderBy       = selectedOrder.OrderBy;
            _animeSearchConfig.SortDirection = selectedSort.SortDirection;
            _animeSearchConfig.Genres        = selectedGenres;
            _animeSearchConfig.GenreIncluded = true;

            if (!_settingsPreferences.ShowNSFW && selectedGenres.Count == 0)
            {
                _animeSearchConfig.Genres        = UTIL.AnimeExtension.FillNSFWGenres().Select(p => p.Genre).ToList();
                _animeSearchConfig.GenreIncluded = false;
            }

            MessagingCenter.Send(this, "CloseFilterView");
            switch (_catalogueMode)
            {
            case CatalogueModeEnum.Season:

                Loading = true;
                await Task.Delay(TimeSpan.FromMilliseconds(500));     // usado para impedir que seja visto um leve engasto na filtragem

                _animesWithSpecifiedFilters = new List <FavoritedAnime>();

                switch (_animeSearchConfig.OrderBy)
                {
                case AnimeSearchSortable.Title:

                    if (_animeSearchConfig.SortDirection == SortDirection.Ascending)
                    {
                        _animesWithSpecifiedFilters.AddRange(_originalCollection.OrderBy(p => p.Anime.Title));
                    }
                    else
                    {
                        _animesWithSpecifiedFilters.AddRange(_originalCollection.OrderByDescending(p => p.Anime.Title));
                    }

                    break;

                case AnimeSearchSortable.StartDate:
                    //TODO: existem alguns animes da temporada que não estão refletindo corretamente a data crescente, investigar e tentar descobrir
                    //o que pode ser
                    if (_animeSearchConfig.SortDirection == SortDirection.Ascending)
                    {
                        _animesWithSpecifiedFilters.AddRange(_originalCollection.OrderBy(p => p.Anime.Aired.From));
                    }
                    else
                    {
                        _animesWithSpecifiedFilters.AddRange(_originalCollection.OrderByDescending(p => p.Anime.Aired.From));
                    }

                    break;

                case AnimeSearchSortable.Score:

                    if (_animeSearchConfig.SortDirection == SortDirection.Ascending)
                    {
                        _animesWithSpecifiedFilters.AddRange(_originalCollection.OrderBy(p => p.Anime.Score));
                    }
                    else
                    {
                        _animesWithSpecifiedFilters.AddRange(_originalCollection.OrderByDescending(p => p.Anime.Score));
                    }

                    break;
                }

                var animeToRemove = new List <FavoritedAnime>();
                for (int i = 0; i < _animesWithSpecifiedFilters.Count; i++)
                {
                    FavoritedAnime favoritedAnime = _animesWithSpecifiedFilters[i];

                    bool hasAllGenres = await favoritedAnime.HasAllSpecifiedGenresAsync(selectedGenres.ToArray());

                    if (!hasAllGenres)
                    {
                        animeToRemove.Add(favoritedAnime);
                    }
                }

                if (animeToRemove.Count > 0)
                {
                    foreach (var item in animeToRemove)
                    {
                        _animesWithSpecifiedFilters.Remove(item);
                    }
                }

                Animes.ReplaceRange(_animesWithSpecifiedFilters);

                Loading = false;

                break;

            case CatalogueModeEnum.Global:
                await ResetAndLoadGlobalAsync();

                break;
            }
        }
コード例 #4
0
        private async Task OnSearch()
        {
            try
            {
                if (SearchQuery?.Length > 0 && _catalogueMode == CatalogueModeEnum.Season)
                {
                    RemainingAnimeCount = -1;
                }

                else if (SearchQuery?.Length > 0 && _catalogueMode == CatalogueModeEnum.Global)
                {
                    RemainingAnimeCount = 0;
                }

                else if (SearchQuery?.Length == 0 && _catalogueMode == CatalogueModeEnum.Season)
                {
                    RemainingAnimeCount = -1;
                }

                else if (SearchQuery?.Length == 0 && _catalogueMode == CatalogueModeEnum.Global)
                {
                    RemainingAnimeCount = 0;
                }

                else if (SearchQuery?.Length == 0 && _currentGenre != null)
                {
                    RemainingAnimeCount = 0;
                }

                if (string.IsNullOrWhiteSpace(SearchQuery) && _catalogueMode == CatalogueModeEnum.Season)
                {
                    IsSearchVisible = false;
                    SearchQuery     = string.Empty;
                }

                Loading = true;
                var resultListTask = Task.Run(async() =>
                {
                    IList <FavoritedAnime> result = new List <FavoritedAnime>();

                    switch (_catalogueMode)
                    {
                    case CatalogueModeEnum.Season:

                        if (_animesWithSpecifiedFilters != null)
                        {
                            result = _animesWithSpecifiedFilters.Where(anime => anime.Anime.Title.ToLowerInvariant()
                                                                       .Contains(SearchQuery.ToLowerInvariant())).ToList();
                        }

                        else
                        {
                            result = _originalCollection.Where(anime => anime.Anime.Title.ToLowerInvariant()
                                                               .Contains(SearchQuery.ToLowerInvariant())).ToList();
                        }

                        break;

                    case CatalogueModeEnum.Global:
                        await App.DelayRequest();

                        _pageCount = 1;
                        AnimeSearchResult animes = null;

                        if (string.IsNullOrWhiteSpace(SearchQuery))
                        {
                            ResetSearchConfig(_settingsPreferences.ShowNSFW, AnimeSearchSortable.Score, SortDirection.Descending);
                            animes = await App.Jikan.SearchAnime(_animeSearchConfig, _pageCount++);
                        }
                        else
                        {
                            ResetSearchConfig(_settingsPreferences.ShowNSFW, AnimeSearchSortable.Title, SortDirection.Descending);

                            animes = await App.Jikan.SearchAnime(SearchQuery, _pageCount++, _animeSearchConfig);
                        }
                        result = await animes.Results.ConvertAnimeSearchEntryToAnimeSubEntry()
                                 .ConvertCatalogueAnimesToFavoritedAsync(_settingsPreferences.ShowNSFW);
                        Console.WriteLine("chamou pesquisa global {0}", DateTime.Now.TimeOfDay.ToString());

                        break;
                    }

                    return(result);
                });

                Animes.ReplaceRange(await resultListTask);
                Loading = false;
            }
            catch (JikanRequestException ex)
            {
                ex.SaveExceptionData();
            }
            catch (OperationCanceledException ex)
            { }
            catch (Exception ex)
            {
                ex.SaveExceptionData();
            }
        }