コード例 #1
0
        public void Get_Data_local()
        {
            try
            {
                if (MEventAdapter != null)
                {
                    if (Classes.ListChachedData_Event.Count > 0)
                    {
                        MEventAdapter.mEventList = Classes.ListChachedData_Event;
                        MEventAdapter.BindEnd();
                    }
                }

                Get_Event_Api();
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
コード例 #2
0
        //Get Data Event Using API
        public async void Get_Event_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Activity.RunOnUiThread(() =>
                    {
                        if (swipeRefreshLayout != null)
                        {
                            swipeRefreshLayout.Refreshing = false;
                        }
                    });
                    Toast.MakeText(Activity, Activity.GetString(Resource.String.Lbl_CheckYourInternetConnection),
                                   ToastLength.Short).Show();
                }
                else
                {
                    var(api_status, respond) = await Client.Event.Get_Events("20", offset, "");

                    if (api_status == 200)
                    {
                        if (respond is Get_Events_Object result)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                if (result.events.Length <= 0)
                                {
                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.events.Length > 0)
                                {
                                    if (MEventAdapter.mEventList.Count <= 0)
                                    {
                                        MEventAdapter.mEventList =
                                            new ObservableCollection <Get_Events_Object.Event>(result.events);
                                        MEventAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listnew = result.events?.Where(c =>
                                                                           !MEventAdapter.mEventList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = MEventAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(MEventAdapter.mEventList, listnew);
                                            MEventAdapter.NotifyItemRangeInserted(lastCountItem, listnew.Count);
                                        }

                                        if (swipeRefreshLayout != null)
                                        {
                                            swipeRefreshLayout.Refreshing = false;
                                        }
                                    }
                                }
                            });
                        }
                    }
                    else if (api_status == 400)
                    {
                        if (respond is Error_Object error)
                        {
                            var errortext = error._errors.Error_text;
                            //Toast.MakeText(this.Activity, errortext, ToastLength.Short).Show();

                            if (errortext.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(Activity);
                            }
                        }
                    }
                    else if (api_status == 404)
                    {
                        var error = respond.ToString();
                        //Toast.MakeText(this.Activity, error, ToastLength.Short).Show();
                    }
                }

                //Show Empty Page >>
                //===============================================================
                Activity.RunOnUiThread(() =>
                {
                    if (MEventAdapter.mEventList.Count > 0)
                    {
                        MainRecyclerView.Visibility = ViewStates.Visible;
                        Events_Empty.Visibility     = ViewStates.Gone;
                    }
                    else
                    {
                        MainRecyclerView.Visibility = ViewStates.Gone;
                        Events_Empty.Visibility     = ViewStates.Visible;
                    }

                    if (swipeRefreshLayout != null)
                    {
                        swipeRefreshLayout.Refreshing = false;
                    }

                    //Set Event Scroll
                    if (OnEventMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(MLayoutManager, swipeRefreshLayout);
                        OnEventMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnEventMainScrolEvent.LoadMoreEvent += EventOnScroll_OnLoadMoreEvent;
                        MainRecyclerView.AddOnScrollListener(OnEventMainScrolEvent);
                        MainRecyclerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        OnEventMainScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_Event_Api(offset);
            }
        }