示例#1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            try
            {
                var view = MyContextWrapper.GetContentView(Context, Settings.Lang,
                                                           Resource.Layout.Event_Fragment_Layout);
                if (view == null)
                {
                    view = inflater.Inflate(Resource.Layout.Event_Fragment_Layout, container, false);
                }

                MyEventRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.Recyler);
                MyEvent_Empty       = view.FindViewById <LinearLayout>(Resource.Id.Events_LinerEmpty);

                MyEventIcon = view.FindViewById <TextView>(Resource.Id.Events_icon);

                IMethods.Set_TextViewIcon("2", MyEventIcon, "\uf073");

                Btn_CreateEvents = view.FindViewById <Button>(Resource.Id.CreateEvents_Button);

                swipeRefreshLayout = view.FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
                swipeRefreshLayout.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight,
                                                           Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight,
                                                           Android.Resource.Color.HoloRedLight);
                swipeRefreshLayout.Refreshing = true;
                swipeRefreshLayout.Enabled    = true;

                MLayoutManager = new LinearLayoutManager(Activity);
                MyEventRecyclerView.SetLayoutManager(MLayoutManager);
                MyEventAdapter = new MyEvent_Adapter(Activity);
                MyEventRecyclerView.SetAdapter(MyEventAdapter);

                MyEventRecyclerView.Visibility = ViewStates.Visible;
                MyEvent_Empty.Visibility       = ViewStates.Gone;


                Get_Data_local();

                return(view);
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                return(null);
            }
        }
示例#2
0
        //Get Data My Event Using API
        public async void Get_MyEvent_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_MyEvents("20", "", offset);

                    if (api_status == 200)
                    {
                        if (respond is Get_MyEvent_object result)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                if (result.my_events.Length <= 0)
                                {
                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.my_events.Length > 0)
                                {
                                    if (MyEventAdapter.mMyEventList.Count <= 0)
                                    {
                                        MyEventAdapter.mMyEventList =
                                            new ObservableCollection <Get_MyEvent_object.My_Events>(result.my_events);
                                        MyEventAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listNew = result.my_events?.Where(c =>
                                                                              !MyEventAdapter.mMyEventList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var lastCountItem = MyEventAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(MyEventAdapter.mMyEventList, listNew);
                                            MyEventAdapter.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 (MyEventAdapter.mMyEventList.Count > 0)
                    {
                        MyEventRecyclerView.Visibility = ViewStates.Visible;
                        MyEvent_Empty.Visibility       = ViewStates.Gone;
                    }
                    else
                    {
                        MyEventRecyclerView.Visibility = ViewStates.Gone;
                        MyEvent_Empty.Visibility       = ViewStates.Visible;
                    }

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

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