private void PopulateItems() { AnimeSearchItems.Clear(); foreach ( var item in _allAnimeSearchItems.Where( item => string.IsNullOrWhiteSpace(_currrentFilter) || string.Equals(_currrentFilter, item.Type, StringComparison.CurrentCultureIgnoreCase))) { AnimeSearchItems.Add(item); } }
public void Init(SearchPageNavigationArgs args) { if (_animeSearch != args.Anime) { PrevQuery = null; } _currrentFilter = null; _animeSearch = args.Anime; if (!string.IsNullOrWhiteSpace(args.Query)) { ViewModelLocator.Main.PopulateSearchFilters(_filters); SubmitQuery(args.Query); } else { _filters.Clear(); AnimeSearchItems.Clear(); ResetQuery(); } }
public async void SubmitQuery(string query) { if (query == PrevQuery) { return; } PrevQuery = query; Loading = Visibility.Visible; EmptyNoticeVisibility = Visibility.Collapsed; AnimeSearchItems.Clear(); var response = ""; _filters.Clear(); _allAnimeSearchItems = new List <AnimeSearchItem>(); if (_animeSearch) { await Task.Run( async() => response = await new AnimeSearchQuery(Utils.CleanAnimeTitle(query)).GetRequestResponse()); try { var parsedData = XDocument.Parse(response); foreach (var item in parsedData.Element("anime").Elements("entry")) { var type = item.Element("type").Value; _allAnimeSearchItems.Add(new AnimeSearchItem(item)); if (!_filters.Contains(type)) { _filters.Add(type); } } } catch (Exception) //if MAL returns nothing it returns unparsable xml ... { EmptyNoticeVisibility = Visibility.Visible; } } else // manga search { await Task.Run( async() => response = await new MangaSearchQuery(Utils.CleanAnimeTitle(query)).GetRequestResponse()); try { var parsedData = XDocument.Parse(response); foreach (var item in parsedData.Element("manga").Elements("entry")) { var type = item.Element("type").Value; _allAnimeSearchItems.Add(new AnimeSearchItem(item, false)); if (!_filters.Contains(type)) { _filters.Add(type); } } } catch (Exception) //if MAL returns nothing it returns unparsable xml ... { EmptyNoticeVisibility = Visibility.Visible; } } ViewModelLocator.Main.PopulateSearchFilters(_filters); PopulateItems(); Loading = Visibility.Collapsed; }