Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                IMethods.IApp.FullScreenApp(this);

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

                ArticlsRecylerView = (RecyclerView)FindViewById(Resource.Id.Recyler);
                Articls_Empty      = FindViewById <LinearLayout>(Resource.Id.Article_LinerEmpty);

                swipeRefreshLayout = 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;

                Icon_Article = FindViewById <TextView>(Resource.Id.Article_icon);
                IMethods.Set_TextViewIcon("2", Icon_Article, "\uf15c");
                Icon_Article.SetTextColor(Color.ParseColor(Settings.MainColor));

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

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

                ArticlesAdapter = new Articles_Adapter(this);

                mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Vertical, false);
                ArticlsRecylerView.SetLayoutManager(mLayoutManager);
                ArticlsRecylerView.SetAdapter(ArticlesAdapter);

                Articls_Empty.Visibility      = ViewStates.Gone;
                ArticlsRecylerView.Visibility = ViewStates.Visible;

                Get_Data_local();
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
Exemple #2
0
        //Get Articles API
        public async void Get_Articles_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });

                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    var(Api_status, Respond) = await Client.Article.Get_Articles("25", offset);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Users_Articles_Object result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.articles.Length <= 0)
                                {
                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.articles.Length > 0)
                                {
                                    if (ArticlesAdapter.ArticlesList.Count <= 0)
                                    {
                                        ArticlesAdapter.ArticlesList =
                                            new ObservableCollection <Get_Users_Articles_Object.Article>(
                                                result.articles);
                                        ArticlesAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listnew = result.articles?.Where(c =>
                                                                             !ArticlesAdapter.ArticlesList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = ArticlesAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(ArticlesAdapter.ArticlesList, listnew);
                                            ArticlesAdapter.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 (ArticlesAdapter.ArticlesList.Count > 0)
                        {
                            Articls_Empty.Visibility      = ViewStates.Gone;
                            ArticlsRecylerView.Visibility = ViewStates.Visible;
                        }
                        else
                        {
                            Articls_Empty.Visibility      = ViewStates.Visible;
                            ArticlsRecylerView.Visibility = ViewStates.Gone;
                        }

                        swipeRefreshLayout.Refreshing = false;

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