예제 #1
0
        private async Task LoadSuggestionsAsync(string offset = "0")
        {
            if (SeconderScrollEvent.IsLoading)
            {
                return;
            }

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

                int countList = SuggestionsAdapter.SuggestionsList.Count;
                (int apiStatus, var respond) = await RequestsAsync.User.FetchSuggestionsUsers(offset, "14");

                if (apiStatus != 200 || !(respond is GetUserObject result) || result.Data == null)
                {
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        if (countList > 0)
                        {
                            foreach (var item in from item in result.Data let check = SuggestionsAdapter.SuggestionsList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item)
                            {
                                SuggestionsAdapter.SuggestionsList.Add(item);
                            }

                            Activity.RunOnUiThread(() => { SuggestionsAdapter.NotifyItemRangeInserted(countList - 1, SuggestionsAdapter.SuggestionsList.Count - countList); });
                        }
                        else
                        {
                            SuggestionsAdapter.SuggestionsList = new ObservableCollection <UserDataObject>(result.Data);
                            Activity.RunOnUiThread(() =>
                            {
                                SuggestionsAdapter.NotifyDataSetChanged();

                                if (MainLayoutSugettion.Visibility != ViewStates.Visible)
                                {
                                    MainLayoutSugettion.Visibility = ViewStates.Visible;
                                }
                            });
                        }
                    }
                    else
                    {
                        if (SuggestionsAdapter.SuggestionsList.Count > 10 && !SuggestionsRecylerView.CanScrollVertically(1))
                        {
                            Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreUsers), ToastLength.Short).Show();
                        }
                    }
                }
                SeconderScrollEvent.IsLoading = false;
            }
            else
            {
                Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
            }
            SeconderScrollEvent.IsLoading = false;
        }
        private async Task LoadDataAsync(string offset = "")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

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

                int countList = MAdapter.SuggestionsList.Count;
                (int apiStatus, var respond) = await RequestsAsync.User.FetchSuggestionsUsers(offset, "14");

                if (apiStatus != 200 || !(respond is GetUserObject result) || result.Data == null)
                {
                    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.SuggestionsList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item)
                            {
                                MAdapter.SuggestionsList.Add(item);
                            }

                            RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList - 1, MAdapter.SuggestionsList.Count - countList); });
                        }
                        else
                        {
                            MAdapter.SuggestionsList = new ObservableCollection <UserDataObject>(result.Data);
                            RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                        }
                    }
                    else
                    {
                        if (MAdapter.SuggestionsList.Count > 10 && !MRecycler.CanScrollVertically(1))
                        {
                            Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreUsers), 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;
            }
            MainScrollEvent.IsLoading = false;
        }
예제 #3
0
        private async Task LoadSuggestionsAsync(string offset = "")
        {
            if (Methods.CheckConnectivity())
            {
                var dictionary = new Dictionary <string, string>
                {
                    { "user_id", UserDetails.UserId },
                    { "limit", "35" },
                    { "user_offset", offset },
                    { "gender", UserDetails.SearchGender },
                    { "search_key", "a" },
                };

                int countList = MAdapter.UserList.Count;
                (int apiStatus, var respond) = await RequestsAsync.Global.Get_Search(dictionary);

                if (apiStatus == 200)
                {
                    if (respond is GetSearchObject result)
                    {
                        var respondList = result.Users.Count;
                        if (respondList > 0)
                        {
                            if (countList > 0)
                            {
                                foreach (var item in result.Users)
                                {
                                    var check = MAdapter.UserList.FirstOrDefault(a => a.UserId == item.UserId);
                                    if (check == null)
                                    {
                                        MAdapter.UserList.Add(item);
                                    }
                                }
                                RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList - 1, MAdapter.UserList.Count - countList); });
                            }
                            else
                            {
                                MAdapter.UserList = new ObservableCollection <UserDataObject>(result.Users);
                                RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                            }
                        }
                        else
                        {
                            if (MAdapter.UserList.Count > 10 && !MRecycler.CanScrollVertically(1))
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_No_more_users), ToastLength.Short).Show();
                            }
                        }
                    }
                }
                else
                {
                    Methods.DisplayReportResult(this, respond);
                }

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