Exemplo n.º 1
0
        //Refresh
        private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e)
        {
            try
            {
                MAdapter.UserList.Clear();
                MAdapter.NotifyDataSetChanged();

                MainScrollEvent.IsLoading = false;

                StartApiService();
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
        //Refresh
        private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e)
        {
            try
            {
                MAdapter.UserList.Clear();
                MAdapter.NotifyDataSetChanged();

                MainScrollEvent.IsLoading = false;

                StartApiService();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 3
0
        private void SetRecyclerViewAdapters()
        {
            try
            {
                MAdapter = new NearByAdapter(this)
                {
                    UserList = new ObservableCollection <UserDataObject>()
                };
                LayoutManager = new GridLayoutManager(this, 2);
                MRecycler.SetLayoutManager(LayoutManager);
                MRecycler.HasFixedSize = true;
                MRecycler.SetItemViewCacheSize(10);
                MRecycler.GetLayoutManager().ItemPrefetchEnabled = true;
                var sizeProvider = new FixedPreloadSizeProvider(10, 10);
                var preLoader    = new RecyclerViewPreloader <UserDataObject>(this, MAdapter, sizeProvider, 10);
                MRecycler.AddOnScrollListener(preLoader);
                MRecycler.SetAdapter(MAdapter);

                RecyclerViewOnScrollListener xamarinRecyclerViewOnScrollListener = new RecyclerViewOnScrollListener(LayoutManager);
                MainScrollEvent = xamarinRecyclerViewOnScrollListener;
                MainScrollEvent.LoadMoreEvent += MainScrollEventOnLoadMoreEvent;
                MRecycler.AddOnScrollListener(xamarinRecyclerViewOnScrollListener);
                MainScrollEvent.IsLoading = false;

                if (ListUtils.SuggestedUserList.Count > 0)
                {
                    MAdapter.UserList = new ObservableCollection <UserDataObject>(ListUtils.SuggestedUserList);
                    MAdapter.NotifyDataSetChanged();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 4
0
        private async Task LoadUsersAsync(string offset = "0")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;
                if (UserDetails.Lat == "" && UserDetails.Lng == "")
                {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 50;
                    var position = await locator.GetPositionAsync(TimeSpan.FromMilliseconds(10000));

                    Console.WriteLine("Position Status: {0}", position.Timestamp);
                    Console.WriteLine("Position Latitude: {0}", position.Latitude);
                    Console.WriteLine("Position Longitude: {0}", position.Longitude);

                    UserDetails.Lat = position.Latitude.ToString(CultureInfo.InvariantCulture);
                    UserDetails.Lng = position.Longitude.ToString(CultureInfo.InvariantCulture);
                }

                UserDetails.Location = ListUtils.MyUserInfo.FirstOrDefault()?.Location;

                var dictionary = new Dictionary <string, string>
                {
                    { "limit", "35" },
                    { "offset", offset },
                    { "_gender", UserDetails.Gender },
                    { "_located", UserDetails.Located },
                    { "_location", UserDetails.Location },
                    { "_age_from", UserDetails.AgeMin.ToString() },
                    { "_age_to", UserDetails.AgeMax.ToString() },
                    { "_lat", UserDetails.Lat },
                    { "_lng", UserDetails.Lng },

                    { "_body", UserDetails.Body ?? "" },
                    { "_ethnicity", UserDetails.Ethnicity ?? "" },
                    { "_religion", UserDetails.Religion ?? "" },
                    { "_drink", UserDetails.Drink ?? "" },
                    { "_smoke", UserDetails.Smoke ?? "" },
                    { "_education", UserDetails.Education ?? "" },
                    { "_pets", UserDetails.Pets ?? "" },
                    { "_relationship", UserDetails.RelationShip ?? "" },
                    { "_language", UserDetails.Language ?? "english" },
                    { "_interest", UserDetails.Interest ?? "" },
                    { "_height_from", UserDetails.FromHeight ?? "139" },
                    { "_height_to", UserDetails.ToHeight ?? "220" },
                };

                int countList = AppSettings.ShowUsersAsCards ? CardDateAdapter2.UsersDateList.Count : NearByAdapter.NearByList.Count;
                var(apiStatus, respond) = await RequestsAsync.Users.SearchAsync(dictionary);

                if (apiStatus != 200 || !(respond is ListUsersObject result) || result.Data == null)
                {
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        foreach (var item in from item in result.Data let check = AppSettings.ShowUsersAsCards ? CardDateAdapter2.UsersDateList.FirstOrDefault(a => a.Id == item.Id) : NearByAdapter.NearByList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                        {
                            if (UserDetails.SwitchState)
                            {
                                var online = QuickDateTools.GetStatusOnline(item.Lastseen, item.Online);
                                if (!online)
                                {
                                    continue;
                                }
                                if (AppSettings.ShowUsersAsCards)
                                {
                                    CardDateAdapter2.UsersDateList.Add(item);
                                }
                                else
                                {
                                    NearByAdapter.NearByList.Add(item);
                                }
                            }
                            else
                            {
                                if (AppSettings.ShowUsersAsCards)
                                {
                                    CardDateAdapter2.UsersDateList.Add(item);
                                }
                                else
                                {
                                    NearByAdapter.NearByList.Add(item);
                                }
                            }
                        }

                        if (AppSettings.ShowUsersAsCards)
                        {
                            if (countList > 0)
                            {
                                Activity.RunOnUiThread(() => CardDateAdapter2.NotifyItemRangeInserted(countList - 1, CardDateAdapter2.UsersDateList.Count - countList));
                            }
                            else
                            {
                                Activity.RunOnUiThread(() => CardDateAdapter2.NotifyDataSetChanged());
                            }
                        }
                        else
                        {
                            if (countList > 0)
                            {
                                Activity.RunOnUiThread(() => NearByAdapter.NotifyItemRangeInserted(countList - 1, NearByAdapter.NearByList.Count - countList));
                            }
                            else
                            {
                                Activity.RunOnUiThread(() => NearByAdapter.NotifyDataSetChanged());
                            }
                        }
                    }
                    else
                    {
                        if (AppSettings.ShowUsersAsCards)
                        {
                            if (CardDateAdapter2.UsersDateList.Count > 10 && !NearByRecyclerView.CanScrollVertically(1))
                            {
                                Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreUsers), ToastLength.Short).Show();
                            }
                        }
                        else
                        {
                            if (NearByAdapter.NearByList.Count > 10 && !NearByRecyclerView.CanScrollVertically(1))
                            {
                                Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreUsers), ToastLength.Short).Show();
                            }
                        }
                    }
                }

                Activity.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(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                MainScrollEvent.IsLoading = false;
            }
            MainScrollEvent.IsLoading = false;
        }