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

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;
                var countList = MAdapter.NearbyShopsList.Count;
                var(apiStatus, respond) = await RequestsAsync.Nearby.GetNearbyShopsAsync("10", offset, SearchText, UserDetails.NearbyShopsDistanceCount);

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

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

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

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

                        break;
                    }
                    }
                }

                RunOnUiThread(ShowEmptyPage);
            }
Beispiel #2
0
        private async Task LoadShopsAsync(string offset = "0")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;
                int countList = MAdapter.NearbyShopsList.Count;
                (int apiStatus, var respond) = await RequestsAsync.Global.GetNearbyShops("10", offset, SearchText, UserDetails.NearbyShopsDistanceCount);

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

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