private async Task OnApplyFilter()
        {
            var checkedGenres     = FilterData.Genres.Where(p => p.IsChecked).Select(p => p.Genre).ToList();
            var checkedDaysOfWeek = FilterData.DayOfWeekOrder.Where(p => p.IsChecked).ToList();

            MessagingCenter.Send(this, "CloseFilterView");

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

            var animeToRemove = new List <FavoritedAnime>();

            // meio encontrado de não ter a originalCollection filtrada, não está bom, mas é a correção por hora
            _originalCollection = await ConstructGroupedCollectionAsync();

            var groupAnimes = new List <GroupedFavoriteAnimeByWeekDay>(_originalCollection);

            //TODO:contar a quantidade de animes cadastrados e ver se todos estão aparecendo apenas uma única vez

            //TODO:olhar aqui em conjunto com o HasAnyDayOfWeek
            for (int i = 0; i < groupAnimes.Count; i++)
            {
                GroupedFavoriteAnimeByWeekDay favoritedAnimeGroup = groupAnimes[i];

                for (int j = 0; j < favoritedAnimeGroup.Count; j++)
                {
                    FavoritedAnime favoritedAnime = favoritedAnimeGroup[j];

                    var hasAllGenresTask     = favoritedAnime.HasAllSpecifiedGenresAsync(checkedGenres.ToArray());
                    var hasAnyDaysOfWeekTask = favoritedAnime.HasAnyDayOfWeekAsync(checkedDaysOfWeek.ToArray());

                    if (!await hasAllGenresTask || !await hasAnyDaysOfWeekTask)
                    {
                        animeToRemove.Add(favoritedAnime);
                    }
                }
            }

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

            var groupsWithAnimes = groupAnimes.Where(p => p.Count > 0);

            GroupedFavoriteByWeekList.ReplaceRange(groupsWithAnimes);
        }
Beispiel #2
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;
            }
        }