Ejemplo n.º 1
0
        async Task LoadMoreItemsAsync(bool refresh = false)
        {
            try
            {
                Views.Infos.RecentFollowersView.Current?.ShowTopLoading();
                var result = await Helper.InstaApi.UserProcessor.GetRecentFollowersAsync();

                if (refresh)
                {
                    Items.Clear();
                    Followers   = CreateFollowers();
                    Suggestions = CreateSuggestions();
                }
                if (!result.Succeeded)
                {
                    Views.Infos.RecentFollowersView.Current?.HideTopLoading();
                    return;
                }
                if (result.Value.Users.Count > 0)
                {
                    Followers.Items.AddRange(result.Value.Users);
                }
                if (result.Value.SuggestedUsers?.Count > 0)
                {
                    Suggestions.SuggestionItems.AddRange(result.Value.SuggestedUsers);
                }

                if (Followers?.Items?.Count > 0)
                {
                    if (!CategoryExists())
                    {
                        Items.Insert(0, Followers);
                    }
                }
                if (Suggestions?.SuggestionItems?.Count > 0)
                {
                    if (!CategoryExists(true))
                    {
                        Items.Add(Suggestions);
                    }
                }
                //if (result.Value != null && result.Value.Any())
                //{
                //    Items.AddRange(result.Value.Select(t => t.ToUserShortFriendship()).ToList());
                //}
                //else
                //    return;
                try
                {
                    await Helper.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        if (Followers?.Items?.Count > 0)
                        {
                            try
                            {
                                var users    = Followers.Items.Select(x => x.Pk);
                                var statuses = await Helper.InstaApi.UserProcessor.GetFriendshipStatusesAsync(users.ToArray());
                                foreach (var item in statuses.Value)
                                {
                                    try
                                    {
                                        var u = Followers.Items.SingleOrDefault(s => s.Pk == item.Pk);
                                        if (u != null)
                                        {
                                            u.FriendshipStatus = item;
                                        }
                                    }
                                    catch { }
                                }
                            }
                            catch { }
                        }
                    });
                }
                catch { }
            }
            catch
            {
            }
            Views.Infos.RecentFollowersView.Current?.HideTopLoading();
        }
Ejemplo n.º 2
0
        async Task LoadMoreItemsAsync(bool refresh = false)
        {
            try
            {
                Views.Infos.FollowRequestsView.Current?.ShowTopLoading();
                var result = await Helper.InstaApi.UserProcessor.GetPendingFriendRequestsAsync();

                if (refresh)
                {
                    Items.Clear();
                    FollowRequests = CreateFollowRequests();
                    Suggestions    = CreateSuggestions();
                }
                if (!result.Succeeded)
                {
                    Views.Infos.FollowRequestsView.Current?.HideTopLoading();
                    return;
                }
                if (result.Value.Users.Count > 0)
                {
                    FollowRequests.Items.AddRange(result.Value.Users);
                }
                if (result.Value.SuggestedUsers?.Count > 0)
                {
                    Suggestions.SuggestionItems.AddRange(result.Value.SuggestedUsers);
                }

                if (FollowRequests?.Items?.Count > 0)
                {
                    if (!CategoryExists())
                    {
                        Items.Insert(0, FollowRequests);
                    }
                }
                if (Suggestions?.SuggestionItems?.Count > 0)
                {
                    if (!CategoryExists(true))
                    {
                        Items.Add(Suggestions);
                    }
                }
                //if (result.Value != null && result.Value.Any())
                //{
                //    Items.AddRange(result.Value.Select(t => t.ToUserShortFriendship()).ToList());
                //}
                //else
                //    return;

                //var users = result.Value.Select(x => x.Pk);
                //var statuses = await Helper.InstaApi.UserProcessor.GetFriendshipStatusesAsync(users.ToArray());
                //($"users count: {users.Count()}").PrintDebug();
                //($"statuses count: {statuses.Value.Count}").PrintDebug();
                //foreach (var item in statuses.Value)
                //{
                //    try
                //    {
                //        var u = Items.SingleOrDefault(s => s.Pk == item.Pk);
                //        if (u != null)
                //            u.FriendshipStatus = item;
                //    }
                //    catch { }
                //}
            }
            catch
            {
            }
            Views.Infos.FollowRequestsView.Current?.HideTopLoading();
        }