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; }
public async void Get_NearByList_API(string offset = "") { try { if (!IMethods.CheckConnectivity()) { swipeRefreshLayout.Refreshing = false; Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short) .Show(); } else { XamarinRecyclerViewOnScrollListener.IsLoading = true; await GetPosition(); var dictionary = new Dictionary <string, string> { { "limit", "25" }, { "offset", offset }, { "gender", Filter_gender }, { "keyword", "" }, { "status", Filter_status }, { "distance", Filter_Distance }, { "lat", UserDetails.Lat }, { "lng", UserDetails.Lng } }; var(Api_status, Respond) = await Client.Nearby.Get_Nearby_Users(dictionary); if (Api_status == 200) { if (Respond is Get_Nearby_Users_Object result) { RunOnUiThread(() => { if (result.nearby_users.Length <= 0) { if (swipeRefreshLayout.Refreshing) { swipeRefreshLayout.Refreshing = false; } if (NearByAdapter.mNearByList.Count > 0) { Snackbar.Make(NearByRecylerView, GetText(Resource.String.Lbl_No_more_users), Snackbar.LengthLong).Show(); } } else if (result.nearby_users.Length > 0) { if (NearByAdapter.mNearByList.Count <= 0) { NearByAdapter.mNearByList = new ObservableCollection <Get_Nearby_Users_Object.Nearby_Users>( result.nearby_users); NearByAdapter.BindEnd(); } else { //Bring new item var listnew = result.nearby_users?.Where(c => !NearByAdapter.mNearByList.Select(fc => fc.user_id).Contains(c.user_id)) .ToList(); if (listnew.Count > 0) { var lastCountItem = NearByAdapter.ItemCount; //Results differ Classes.AddRange(NearByAdapter.mNearByList, listnew); NearByAdapter.NotifyItemRangeInserted(lastCountItem, listnew.Count); } if (swipeRefreshLayout.Refreshing) { swipeRefreshLayout.Refreshing = false; } } } }); } } else if (Api_status == 400) { if (Respond is Error_Object error) { var errortext = error._errors.Error_text; //Toast.MakeText(this, errortext, ToastLength.Short).Show(); if (errortext.Contains("Invalid or expired access_token")) { API_Request.Logout(this); } } } else if (Api_status == 404) { var error = Respond.ToString(); //Toast.MakeText(this, error, ToastLength.Short).Show(); } } //Show Empty Page >> //=============================================================== RunOnUiThread(() => { if (NearByAdapter.mNearByList.Count > 0) { NearByRecylerView.Visibility = ViewStates.Visible; NearBy_Empty.Visibility = ViewStates.Gone; } else { NearByRecylerView.Visibility = ViewStates.Gone; NearBy_Empty.Visibility = ViewStates.Visible; } swipeRefreshLayout.Refreshing = false; //Set Event Scroll if (OnMainScrolEvent == null) { var xamarinRecyclerViewOnScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout); OnMainScrolEvent = xamarinRecyclerViewOnScrollListener; OnMainScrolEvent.LoadMoreEvent += NearBy_OnScroll_OnLoadMoreEvent; NearByRecylerView.AddOnScrollListener(OnMainScrolEvent); NearByRecylerView.AddOnScrollListener(new ScrollDownDetector()); } else { XamarinRecyclerViewOnScrollListener.IsLoading = false; } }); } catch (Exception e) { Crashes.TrackError(e); Get_NearByList_API(offset); } }
private async Task LoadNearByAsync(string offset = "0") { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; await GetPosition(); var dictionary = new Dictionary <string, string> { { "limit", "10" }, { "offset", offset }, { "gender", UserDetails.NearByGender }, //{"keyword", ""}, { "status", UserDetails.NearByStatus }, { "distance", UserDetails.NearByDistanceCount }, { "lat", UserDetails.Lat }, { "lng", UserDetails.Lng }, { "relship", UserDetails.NearByRelationship }, }; int countList = MAdapter.UserList.Count; (int apiStatus, var respond) = await RequestsAsync.Nearby.Get_Nearby_Users(dictionary); if (apiStatus == 200) { if (respond is GetNearbyUsersObject result) { var respondList = result.NearbyUsers.Count; if (respondList > 0) { foreach (var item in from item in result.NearbyUsers let check = MAdapter.UserList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item) { MAdapter.UserList.Add(item); } RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.UserList.Count - countList); }); } 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); } 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; } }
private async Task LoadSuggestionsAsync(string offset = "0") { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; int countList = MAdapter.UserList.Count; (int apiStatus, var respond) = await RequestsAsync.Global.GetRecommendedUsers("25", offset); if (apiStatus == 200) { if (respond is ListUsersObject result) { var respondList = result.Data.Count; if (respondList > 0) { if (countList > 0) { foreach (var item in from item in result.Data let check = MAdapter.UserList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item) { MAdapter.UserList.Add(item); } RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.UserList.Count - countList); }); } else { MAdapter.UserList = new ObservableCollection <UserDataObject>(result.Data); 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); } 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; }