Example #1
0
        private async Task LoadJoinAsync(string offset = "")
        {
            switch (MainScrollEvent.IsLoading)
            {
            case true:
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;

                var countList = MAdapter.JoinList.Count;
                var(apiStatus, respond) = await RequestsAsync.Group.GetGroupJoinRequestsAsync(GroupId, "10", offset);

                if (apiStatus != 200 || respond is not GetGroupJoinRequestsObject 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.JoinList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                        {
                            MAdapter.JoinList.Add(item);
                        }

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

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

                    default:
                    {
                        switch (MAdapter.JoinList.Count)
                        {
                        case > 10 when !MRecycler.CanScrollVertically(1):
                            Toast.MakeText(this, GetText(Resource.String.Lbl_No_more_users), ToastLength.Short)?.Show();
                            break;
                        }

                        break;
                    }
                    }
                }

                RunOnUiThread(ShowEmptyPage);
            }
        private async Task LoadJoinAsync(string offset = "")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;

                int countList = MAdapter.JoinList.Count;
                (int apiStatus, var respond) = await RequestsAsync.Group.GetGroupJoinRequests(GroupId, "10", offset);

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

                            RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.JoinList.Count - countList); });
                        }
                        else
                        {
                            MAdapter.JoinList = new ObservableCollection <JoinRequestsObject>(result.Data);
                            RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                        }
                    }
                    else
                    {
                        if (MAdapter.JoinList.Count > 10 && !MRecycler.CanScrollVertically(1))
                        {
                            Toast.MakeText(this, GetText(Resource.String.Lbl_No_more_users), 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;
            }
        }