private async Task LoadDataComment(string offset) { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; int countList = MAdapter.CommentList.Count; (int apiStatus, var respond) = await RequestsAsync.Comment.GetPostComments(PostId, "10", offset); if (apiStatus != 200 || !(respond is CommentObject result) || result.CommentList == null) { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(this, respond); } else { var respondList = result.CommentList?.Count; if (respondList > 0) { foreach (var item in from item in result.CommentList let check = MAdapter.CommentList.FirstOrDefault(a => a.Id == item.Id) where check == null select item) { var db = Mapper.Map <CommentObjectExtra>(item); if (db != null) { MAdapter.CommentList.Add(db); } } if (countList > 0) { RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.CommentList.Count - countList); }); } else { RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); } } } RunOnUiThread(ShowEmptyPage); } }
private async Task LoadDataComment(string offset) { if (Methods.CheckConnectivity()) { var countList = MAdapter.CommentList.Count; var(apiStatus, respond) = await RequestsAsync.Comment.GetPostCommentsAsync(PostId, "10", offset); if (apiStatus != 200 || respond is not CommentObject result || result.CommentList == null) { Methods.DisplayReportResult(this, respond); } else { var respondList = result.CommentList?.Count; switch (respondList) { case > 0: { foreach (var item in from item in result.CommentList let check = MAdapter.CommentList.FirstOrDefault(a => a.Id == item.Id) where check == null select item) { var db = ClassMapper.Mapper?.Map <CommentObjectExtra>(item); if (db != null) { MAdapter.CommentList.Add(db); } } switch (countList) { case > 0: RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.CommentList.Count - countList); }); break; default: RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); break; } break; } } } RunOnUiThread(ShowEmptyPage2); }