Exemple #1
0
        async Task LoadMoreItemsAsync(bool refresh = false)
        {
            if (!HasMoreItems && !refresh)
            {
                //IsLoading = false;
                return;
            }
            try
            {
                if (refresh)
                {
                    Pagination = PaginationParameters.MaxPagesToLoad(1);
                    Views.Main.ActivitiesView.Current?.ShowTopLoadingYou();
                }
                else
                {
                    Views.Main.ActivitiesView.Current?.ShowBottomLoadingYou();
                }
                Views.Main.ActivitiesView.Current?.HideComments();
                CommentFeed = null;
                var result = await InstaApi.UserProcessor.GetRecentActivityFeedAsync(Pagination);

                FirstRun = false;
                Pagination.MaximumPagesToLoad = 1;
                if (!result.Succeeded)
                {
                    //IsLoading = false;
                    if (result.Value == null || result.Value?.Items?.Count == 0)
                    {
                        if (refresh)
                        {
                            Views.Main.ActivitiesView.Current?.HideTopLoadingYou();
                        }
                        else
                        {
                            Views.Main.ActivitiesView.Current?.HideBottomLoadingYou();
                        }
                        return;
                    }
                }
                MainPage.Current?.ShowActivityNotify(result.Value.Counts);
                if (string.IsNullOrEmpty(result.Value.NextMaxId))
                {
                    HasMoreItems = false;
                }

                if (result.Value?.Items?.Count > 0)
                {
                    if (refresh)
                    {
                        RecentItems.Clear();
                        RecentItems.CurrentList = null;
                    }

                    result.Value.Items.ForEach(item => RecentItems.AddWithColumns(item.ToRecentActivityFeed()));
                }
                await Task.Delay(1000);

                //IsLoading = false;
                await InstaApi.UserProcessor.MarkNewsInboxSeenAsync();

                await InstaApi.UserProcessor.MarkDiscoverMarkSuSeenAsync();
            }
            catch (Exception ex)
            {
                FirstRun =
                    /* IsLoading =*/ false;
                ex.PrintException("ActivitiesViewModel.LoadMoreItemsAsync");
            }
            if (refresh)
            {
                Views.Main.ActivitiesView.Current?.HideTopLoadingYou();
            }
            else
            {
                Views.Main.ActivitiesView.Current?.HideBottomLoadingYou();
            }
            refresh = false;
        }