private async Task LoadJobsAsync(string offset) { if (MainScrollEvent.IsLoading) return; if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; // api get job by page int countList = MAdapter.JobList.Count; (int apiStatus, var respond) = await RequestsAsync.Jobs.JobByPage(PageId, "10", offset); if (apiStatus != 200 || !(respond is JobByPageObject result) || result.Data == null) { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(this, respond); } else { var respondList = result.Data.Count; if (respondList > 0) { foreach (var item in from item in result.Data let check = MAdapter.JobList.FirstOrDefault(a => a.Id == item.Id) where check == null select item) { if (item.Job != null) MAdapter.JobList.Add(WoWonderTools.ListFilterJobs(item.Job.Value.JobInfoClass)); } if (countList > 0) { RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.JobList.Count - countList); }); } else { RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); } } else { if (MAdapter.JobList.Count > 10 && !MRecycler.CanScrollVertically(1)) Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreJobs), ToastLength.Short)?.Show(); } } RunOnUiThread(ShowEmptyPage); } else { Inflated = EmptyStateLayout.Inflate(); EmptyStateInflater x = new EmptyStateInflater(); x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection); if (!x.EmptyStateButton.HasOnClickListeners) { x.EmptyStateButton.Click += null!; x.EmptyStateButton.Click += EmptyStateButtonOnClick; } Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); MainScrollEvent.IsLoading = false; } }
private async Task LoadJobsAsync(string offset) { switch (MainScrollEvent.IsLoading) { case true: return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; // api get job by page var countList = MAdapter.JobList.Count; var(apiStatus, respond) = await RequestsAsync.Jobs.JobByPageAsync(PageId, "10", offset); if (apiStatus != 200 || respond is not JobByPageObject result || result.Data == null) { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(this, respond); } else { var respondList = result.Data.Count; switch (respondList) { case > 0: { foreach (var item in from item in result.Data let check = MAdapter.JobList.FirstOrDefault(a => a.Id == item.Id) where check == null select item) { if (item.Job != null) { MAdapter.JobList.Add(WoWonderTools.ListFilterJobs(item.Job.Value.JobInfoClass)); } } switch (countList) { case > 0: RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.JobList.Count - countList); }); break; default: RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); break; } break; } default: { switch (MAdapter.JobList.Count) { case > 10 when !MRecycler.CanScrollVertically(1): Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreJobs), ToastLength.Short)?.Show(); break; } break; } } } RunOnUiThread(ShowEmptyPage); }