private async Task LoadDataComment(string offset)
        {
            switch (MainScrollEvent.IsLoading)
            {
            case true:
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;
                var countList = MAdapter.CommentList.Count;
                var(apiStatus, respond) = await RequestsAsync.Movies.GetCommentsAsync(MoviesId, "25", offset);

                if (apiStatus != 200 || respond is not GetCommentsMoviesObject result || result.Data == null)
                {
                    MainScrollEvent.IsLoading = false;
                    Methods.DisplayReportResult(this, respond);
                }
                else
                {
                    var respondList = result.Data?.Count;
                    switch (respondList)
                    {
                    case > 0 when countList > 0:
                    {
                        foreach (var item in from item in result.Data let check = MAdapter.CommentList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                        {
                            MAdapter.CommentList.Add(item);
                        }

                        RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.CommentList.Count - countList); });
                        break;
                    }

                    case > 0:
                        MAdapter.CommentList = new ObservableCollection <CommentsMoviesObject>(result.Data);
                        RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                        break;
                    }
                }

                RunOnUiThread(ShowEmptyPage);
            }
Beispiel #2
0
        private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e)
        {
            try
            {
                MAdapter.CommentList.Clear();
                MAdapter.NotifyDataSetChanged();

                if (!Methods.CheckConnectivity())
                {
                    Toast.MakeText(Activity, Activity.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
                else
                {
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => MAdapter.FetchMoviesApiComments(GlobalContext.MoviesId, "0")
                    });
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }