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

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;
                var countList = MAdapter.GroupList.Count;
                var(respondCode, respondString) = await RequestsAsync.Group.GetGroupsByCategoryAsync(CategoryId, "10", offset);

                switch (respondCode)
                {
                case 200:
                {
                    switch (respondString)
                    {
                    case ListGroupsObject result:
                    {
                        var respondList = result.Data.Count;
                        switch (respondList)
                        {
                        case > 0 when countList > 0:
                        {
                            foreach (var item in from item in result.Data let check = MAdapter.GroupList.FirstOrDefault(a => a.GroupId == item.GroupId) where check == null select item)
                            {
                                MAdapter.GroupList.Add(item);
                            }

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

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

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

                            break;
                        }
                        }

                        break;
                    }
                    }

                    break;
                }

                default:
                    Methods.DisplayReportResult(this, respondString);
                    break;
                }

                RunOnUiThread(ShowEmptyPage);
            }
            else
            {
                Inflated = EmptyStateLayout.Inflate();
                EmptyStateInflater x = new EmptyStateInflater();
                x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection);
                switch (x.EmptyStateButton.HasOnClickListeners)
                {
                case false:
                    x.EmptyStateButton.Click += null !;
                    x.EmptyStateButton.Click += EmptyStateButtonOnClick;
                    break;
                }

                Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                MainScrollEvent.IsLoading = false;
            }
            MainScrollEvent.IsLoading = false;
        }
        private async Task LoadRandomGroup(string offset)
        {
            if (Methods.CheckConnectivity())
            {
                var countList = RandomAdapter.GroupList.Count;

                var dictionary = new Dictionary <string, string>
                {
                    { "limit", "30" },
                    { "group_offset", offset },
                    { "search_key", "a" },
                };

                var(respondCode, respondString) = await RequestsAsync.Global.Get_Search(dictionary);

                if (respondCode.Equals(200))
                {
                    if (respondString is GetSearchObject result)
                    {
                        var respondList = result.Groups.Count;
                        if (respondList > 0)
                        {
                            if (countList > 0)
                            {
                                foreach (var item in from item in result.Groups let check = RandomAdapter.GroupList.FirstOrDefault(a => a.GroupId == item.GroupId) where check == null select item)
                                {
                                    RandomAdapter.GroupList.Add(item);
                                }

                                RunOnUiThread(() => { RandomAdapter.NotifyItemRangeInserted(countList, RandomAdapter.GroupList.Count - countList); });
                            }
                            else
                            {
                                RandomAdapter.GroupList = new ObservableCollection <GroupClass>(result.Groups);

                                RunOnUiThread(() =>
                                {
                                    if (RandomGroupInflated == null)
                                    {
                                        RandomGroupInflated = RandomGroupViewStub.Inflate();
                                    }

                                    RecyclerInflaterRandomGroup = new TemplateRecyclerInflater();
                                    RecyclerInflaterRandomGroup.InflateLayout <GroupClass>(this, RandomGroupInflated, RandomAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerVertical, 0, true, GetString(Resource.String.Lbl_RandomGroups));
                                });
                            }
                        }
                        else
                        {
                            if (RecyclerInflaterRandomGroup?.Recyler != null && (RandomAdapter.GroupList.Count > 10 && !RecyclerInflaterRandomGroup.Recyler.CanScrollVertically(1)))
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreGroup), ToastLength.Short)?.Show();
                            }
                        }
                    }
                }
                else
                {
                    Methods.DisplayReportResult(this, respondString);
                }

                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();
            }
        }
Exemple #3
0
        private async Task LoadGroup(string offset)
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;
                var countList = MAdapter.GroupList.Count;
                var(respondCode, respondString) = await RequestsAsync.Group.GetRecommendedGroups("10", offset);

                if (respondCode.Equals(200))
                {
                    if (respondString is ListGroupsObject result)
                    {
                        var respondList = result.Data.Count;
                        if (respondList > 0)
                        {
                            if (countList > 0)
                            {
                                foreach (var item in from item in result.Data let check = MAdapter.GroupList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                                {
                                    MAdapter.GroupList.Add(item);
                                }

                                RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.GroupList.Count - countList); });
                            }
                            else
                            {
                                MAdapter.GroupList = new ObservableCollection <GroupClass>(result.Data);
                                RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                            }
                        }
                        else
                        {
                            if (MAdapter.GroupList.Count > 10 && !MRecycler.CanScrollVertically(1))
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreGroup), ToastLength.Short).Show();
                            }
                        }
                    }
                }
                else
                {
                    Methods.DisplayReportResult(this, respondString);
                }

                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;
            }
            MainScrollEvent.IsLoading = false;
        }