示例#1
0
        public async void GetRecentSearches()
        {
            try
            {
                RecentSearchesAdded = false;
                Views.Searches.SearchView.Current?.ShowTopLoadingTop();
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    var result = await InstaApi.DiscoverProcessor.GetRecentSearchesAsync();
                    if (result.Succeeded)
                    {
                        AccountSearchesPrivate.Clear();
                        HashtagSearchesPrivate.Clear();
                        AccountSearches.Clear();
                        RecentSearches.Clear();
                        RecentSearches.AddRange(result.Value.Recent);
                        if (TopItems.Count > 0)
                        {
                            AddRecentSearches();
                            if (result.Value.Recent.Count > 0)
                            {
                                var xxx = result.Value.Recent.Where(a => !a.IsHashtag).Select(b => b.User).ToList();
                                xxx.ForEach(tx => AccountSearchesPrivate.Add(tx.ToUser()));
                                AccountSearches.AddRange(AccountSearchesPrivate);
                            }
                            if (result.Value.Recent.Count > 0)
                            {
                                var xxx = result.Value.Recent.Where(a => a.IsHashtag).Select(b => b.Hashtag.ToHashtag()).ToList();
                                xxx.ForEach(tx => HashtagSearchesPrivate.Add(tx));
                                HashtagSearches.AddRange(HashtagSearchesPrivate);
                            }
                        }
                    }

                    Views.Searches.SearchView.Current?.HideTopLoadingTop();
                });
            }
            catch { Views.Searches.SearchView.Current?.HideTopLoadingTop(); }
        }
示例#2
0
        //public string TextSearch = string.Empty;
        //PaginationParameters AccountPagination = PaginationParameters.MaxPagesToLoad(1);
        public async void SearchAccounts(string text)
        {
            try
            {
                if (text.Contains("@"))
                {
                    text = text.Replace("@", "");
                }
                if (text.Contains("#"))
                {
                    text = text.Replace("#", "");
                }
                text = text.ToLower();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    Views.Searches.SearchView.Current?.ShowTopLoadingAccount();
                    var result = await InstaApi.DiscoverProcessor.SearchPeopleAsync(text, PaginationParameters.MaxPagesToLoad(1));

                    AccountSearches.Clear();
                    if (result.Succeeded && result.Value?.Users?.Count > 0)
                    {
                        //AccountSearches.AddRange(result.Value.Users);
                        var users = result.Value.Users;//.OrderBy(x=> x.FriendshipStatus!= null && x.FriendshipStatus.Following).ToList();

                        var userIds = new List <long>();
                        if (users?.Count > 0)
                        {
                            users.ForEach(x =>
                            {
                                userIds.Add(x.Pk);
                            });
                        }
                        try
                        {
                            if (userIds.Count > 0)
                            {
                                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                                {
                                    var friendshipStatuses = await InstaApi.UserProcessor.GetFriendshipStatusesAsync(userIds.ToArray());
                                    if (friendshipStatuses.Succeeded)
                                    {
                                        var friends = friendshipStatuses.Value;
                                        friends.ForEach(x =>
                                        {
                                            var t = users.FirstOrDefault(u => u.Pk == x.Pk);
                                            if (t != null)
                                            {
                                                t.FriendshipStatus = x;
                                            }
                                        });
                                        var orderedUsers = users.OrderBy(x => x.FriendshipStatus != null && !x.FriendshipStatus.Following).ToList();

                                        //var aaaaaaa0 = users.OrderBy(x => x.FriendshipStatus != null && x.FriendshipStatus.Following).ToList();


                                        orderedUsers.ForEach(x =>
                                        {
                                            AccountSearches.Add(x);
                                        });
                                    }
                                });
                            }
                        }
                        catch { }
                    }


                    Views.Searches.SearchView.Current?.HideTopLoadingAccount();
                });
            }
            catch
            {
                Views.Searches.SearchView.Current?.HideTopLoadingAccount();
            }
        }