Esempio n. 1
0
 //Event Refresh Data Page
 private void Market_SwipeRefreshLayoutOnRefresh(object sender, EventArgs e)
 {
     try
     {
         MMarketAdapter.Clear();
         Get_DataMarket_Api("");
     }
     catch (Exception exception)
     {
         Crashes.TrackError(exception);
     }
 }
Esempio n. 2
0
        public void Get_Data_local()
        {
            try
            {
                if (MMarketAdapter != null)
                {
                    if (Classes.ListChachedData_Product.Count > 0)
                    {
                        MMarketAdapter.MarketList = Classes.ListChachedData_Product;
                        MMarketAdapter.BindEnd();
                    }
                }

                Get_DataMarket_Api();
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
Esempio n. 3
0
 //Event Go to see data Product >> Open ProductView_Activity
 private void MMarketAdapter_OnItemClick(object sender, MarketAdapterClickEventArgs adapterClickEvents)
 {
     try
     {
         var Position = adapterClickEvents.Position;
         if (Position >= 0)
         {
             var item = MMarketAdapter.GetItem(Position);
             if (item != null)
             {
                 var Int = new Intent(Context, typeof(ProductView_Activity));
                 Int.PutExtra("ProductView", JsonConvert.SerializeObject(item));
                 StartActivity(Int);
             }
         }
     }
     catch (Exception e)
     {
         Crashes.TrackError(e);
     }
 }
Esempio n. 4
0
        //Get Data Market Using API
        public async void Get_DataMarket_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Activity.RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });
                    Toast.MakeText(Activity, Activity.GetString(Resource.String.Lbl_CheckYourInternetConnection),
                                   ToastLength.Short).Show();
                }
                else
                {
                    var(Api_status, Respond) = await Client.Market.Get_Products("", "35", offset);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Products_Object result)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                if (result.products.Length <= 0)
                                {
                                    if (swipeRefreshLayout.Refreshing)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.products.Length > 0)
                                {
                                    if (MMarketAdapter.MarketList.Count <= 0)
                                    {
                                        MMarketAdapter.MarketList =
                                            new ObservableCollection <Get_Products_Object.Product>(result.products);
                                        MMarketAdapter.BindEnd();

                                        var animation = AnimationUtils.LoadAnimation(Activity,
                                                                                     Resource.Animation.slideUpAnim);
                                        MainRecyclerView.StartAnimation(animation);
                                    }
                                    else
                                    {
                                        //Bring new item
                                        //var exceptList = result.products?.ToList().Except(MMarketAdapter?.MarketList).ToList();

                                        var listnew = result.products?.Where(c =>
                                                                             !MMarketAdapter.MarketList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = MMarketAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(MMarketAdapter.MarketList, listnew);
                                            MMarketAdapter.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.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(() =>
                {
                    swipeRefreshLayout.Refreshing = false;

                    if (MMarketAdapter.MarketList.Count > 0)
                    {
                        if (MainRecyclerView.Visibility == ViewStates.Gone)
                        {
                            MainRecyclerView.Visibility = ViewStates.Visible;
                        }

                        if (Market_Empty.Visibility == ViewStates.Visible)
                        {
                            Market_Empty.Visibility = ViewStates.Gone;
                        }
                    }
                    else if (MMarketAdapter.MarketList.Count <= 0)
                    {
                        MainRecyclerView.Visibility = ViewStates.Gone;
                        Market_Empty.Visibility     = ViewStates.Visible;
                    }

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