/// <summary> /// Checks if the list has any mentions of the trending list, if so updates the list, otherwise it adds the new instance to the trending list. /// </summary> /// <param name="text"></param> protected void AddToTrendingList(string text) { // Prevent throwing exception for empty text if (text.Length == 0) { return; } // Split the text in order to find each hashtag // If the first char is a # then set a flag, else leave it to zero var flag = 0; if (text[0] == '#') { flag = 1; } string[] textSplit = text.Split('#'); for (var counter = 0; counter < textSplit.Length; counter++) { // Check if first word in order to deal with the eventual @ lost on splitting if (counter == 0 && flag == 0) { continue; } var hashtag = '#' + textSplit[counter]; // Hashtags can only contain letters, numbers, and underscores foreach (Match match in Regex.Matches(hashtag, @"\B\#\w{1,15}\b")) { if (TrendingList.ContainsKey(match.ToString())) { TrendingList[match.ToString()] += 1; } else { TrendingList.Add(match.ToString(), 1); } } } }
private async Task QueryTrending(DiscoverItem item) { CommonProvider common = new CommonProvider(); List <TrendingResult> result = new List <TrendingResult>(); if (pageIndex == 0) { if (TrendingList == null) { TrendingList = new ObservableCollection <TrendingResult>(); } else { TrendingList.Clear(); } } if (TypeSelectedItem.HotType != HotTopicType.None) { result = await common.QueryDiscover(TypeSelectedItem.HotType, pageIndex + 1, 20, new List <TrendingResult>(TrendingList)); } if (TypeSelectedItem.Type != TopicType.None) { int index = 0; if (TrendingList.Count != 0) { index = TrendingList[TrendingList.Count - 1].RecommendedAt - 1; } result = await common.QueryDiscover(TypeSelectedItem.Type, index, 20, 20); } result.ForEach(x => TrendingList.Add(x)); pageIndex++; }
// Open new Trending List window private void TrendingListBtn_Click(object sender, RoutedEventArgs e) { TrendingList trendingListWindow = new TrendingList(); trendingListWindow.Show(); }