예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                // Check if we're running on Android 5.0 or higher
                if ((int)Build.VERSION.SdkInt < 23)
                {
                }
                else
                {
                    Window.AddFlags(WindowManagerFlags.TranslucentNavigation);
                }

                base.OnCreate(savedInstanceState);

                IMethods.IApp.FullScreenApp(this);

                var view = MyContextWrapper.GetContentView(this, Settings.Lang, Resource.Layout.NearByPepole_Layout);
                if (view != null)
                {
                    SetContentView(view);
                }
                else
                {
                    SetContentView(Resource.Layout.NearByPepole_Layout);
                }

                var ToolBar = FindViewById <Toolbar>(Resource.Id.toolbar);
                if (ToolBar != null)
                {
                    ToolBar.Title = GetText(Resource.String.Lbl_NearBy);

                    SetSupportActionBar(ToolBar);
                    SupportActionBar.SetDisplayShowCustomEnabled(true);
                    SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                    SupportActionBar.SetHomeButtonEnabled(true);
                    SupportActionBar.SetDisplayShowHomeEnabled(true);
                }

                //Get values
                NearByRecylerView  = (RecyclerView)FindViewById(Resource.Id.Recyler);
                NearBy_Empty       = FindViewById <LinearLayout>(Resource.Id.NearBy_LinerEmpty);
                swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
                Icon_NearBy        = FindViewById <TextView>(Resource.Id.NearBy_icon);

                FloatingActionButtonView = FindViewById <FloatingActionButton>(Resource.Id.floatingActionButtonView);

                swipeRefreshLayout.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight,
                                                           Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight,
                                                           Android.Resource.Color.HoloRedLight);
                swipeRefreshLayout.Refreshing = true;
                swipeRefreshLayout.Enabled    = true;

                IMethods.Set_TextViewIcon("2", Icon_NearBy, "\uf21d");
                Icon_NearBy.SetTextColor(Color.ParseColor(Settings.MainColor));

                //Set Adapter
                mLayoutManager = new GridLayoutManager(this, 2);
                NearByRecylerView.SetLayoutManager(mLayoutManager);
                NearByRecylerView.AddItemDecoration(new GridSpacingItemDecoration(2, 3, true));
                NearByAdapter = new NearByAdapter(this);
                NearByRecylerView.SetAdapter(NearByAdapter);
                NearByRecylerView.SetItemViewCacheSize(18);
                NearByRecylerView.GetLayoutManager().ItemPrefetchEnabled = true;
                NearByRecylerView.DrawingCacheEnabled = (true);
                NearByRecylerView.DrawingCacheQuality = DrawingCacheQuality.High;
                NearByRecylerView.Visibility          = ViewStates.Visible;
                NearBy_Empty.Visibility = ViewStates.Gone;

                InitializeLocationManager();

                Get_Data_local();
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
예제 #2
0
        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);
            }
        }