Example #1
0
        private void SetRecyclerViewAdapters()
        {
            try
            {
                SuggestionsAdapter = new SuggestionsAdapter(Activity);
                LinearLayoutManager suggestionsLayoutManager = new LinearLayoutManager(Activity, LinearLayoutManager.Horizontal, false);
                SuggestionsRecylerView.SetLayoutManager(suggestionsLayoutManager);
                SuggestionsRecylerView.HasFixedSize = true;
                SuggestionsRecylerView.SetItemViewCacheSize(10);
                SuggestionsRecylerView.GetLayoutManager().ItemPrefetchEnabled = true;
                var sizeProviderSuggestions = new FixedPreloadSizeProvider(10, 10);
                var preLoaderSuggestions    = new RecyclerViewPreloader <UserDataObject>(Activity, SuggestionsAdapter, sizeProviderSuggestions, 10);
                SuggestionsRecylerView.AddOnScrollListener(preLoaderSuggestions);
                SuggestionsAdapter.ItemClick += SuggestionsAdapterOnItemClick;
                SuggestionsRecylerView.SetAdapter(SuggestionsAdapter);

                RecyclerViewOnScrollListener xamarinRecyclerViewOnScrollListener2 = new RecyclerViewOnScrollListener(suggestionsLayoutManager);
                SeconderScrollEvent = xamarinRecyclerViewOnScrollListener2;
                SeconderScrollEvent.LoadMoreEvent += SeconderScrollEventOnLoadMoreEvent;
                SuggestionsRecylerView.AddOnScrollListener(xamarinRecyclerViewOnScrollListener2);
                SeconderScrollEvent.IsLoading = false;

                //*******************************************************************

                ExploreAdapter = new ExploreAdapter(Activity);
                GridLayoutManager mLayoutManager = new GridLayoutManager(Activity, 3);
                mLayoutManager.SetSpanSizeLookup(new MySpanSizeLookup(8, 1, 2));
                ExploreRecylerView.AddItemDecoration(new GridSpacingItemDecoration(1, 1, true));
                ExploreRecylerView.SetLayoutManager(mLayoutManager);
                ExploreRecylerView.HasFixedSize = true;
                ExploreRecylerView.SetItemViewCacheSize(10);
                ExploreRecylerView.GetLayoutManager().ItemPrefetchEnabled = true;
                var sizeProvider = new FixedPreloadSizeProvider(10, 10);
                var preLoader    = new RecyclerViewPreloader <PostsObject>(Activity, ExploreAdapter, sizeProvider, 8);
                ExploreRecylerView.AddOnScrollListener(preLoader);
                ExploreAdapter.ItemClick += ExploreAdapterOnItemClick;
                ExploreRecylerView.SetAdapter(ExploreAdapter);

                RecyclerViewOnScrollListener xamarinRecyclerViewOnScrollListener = new RecyclerViewOnScrollListener(mLayoutManager);
                MainScrollEvent = xamarinRecyclerViewOnScrollListener;
                MainScrollEvent.LoadMoreEvent += MainScrollEventOnLoadMoreEvent;
                ExploreRecylerView.AddOnScrollListener(xamarinRecyclerViewOnScrollListener);
                MainScrollEvent.IsLoading = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #2
0
        private async Task LoadExploreAsync(string offset = "0")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;

                int countList = ExploreAdapter.FeaturedList.Count;
                var(apiStatus, respond) = await RequestsAsync.Post.FetchExplorePosts(offset, "25");

                if (apiStatus != 200 || !(respond is FetchExplorePostsObject result) || result.Data == null)
                {
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        result.Data.RemoveAll(a => a.MediaSet?.Count == 0 || a.MediaSet == null);

                        if (countList > 0)
                        {
                            foreach (var item in from item in result.Data let check = ExploreAdapter.FeaturedList.FirstOrDefault(a => a.PostId == item.PostId) where check == null select item)
                            {
                                item.Mp4 = Methods.FunString.StringNullRemover(item.Mp4);
                                ExploreAdapter.FeaturedList.Add(item);
                            }

                            Activity.RunOnUiThread(() => { ExploreAdapter.NotifyItemRangeInserted(countList, ExploreAdapter.FeaturedList.Count); });
                        }
                        else
                        {
                            ExploreAdapter.FeaturedList = new ObservableCollection <PostsObject>(result.Data);
                            Activity.RunOnUiThread(() => { ExploreAdapter.NotifyDataSetChanged(); });
                        }
                    }
                    else
                    {
                        if (ExploreAdapter.FeaturedList.Count > 10 && !ExploreRecylerView.CanScrollVertically(1))
                        {
                            Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMorePost), ToastLength.Short).Show();
                        }
                    }
                }

                Activity.RunOnUiThread(ShowEmptyPage);
            }
            else
            {
                Inflated = EmptyStateLayout.Inflate();
                EmptyStateInflater x = new EmptyStateInflater();
                x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection);
                if (!x.EmptyStateButton.HasOnClickListeners)
                {
                    x.EmptyStateButton.Click += null;
                    x.EmptyStateButton.Click += EmptyStateButtonOnClick;
                }

                Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                MainScrollEvent.IsLoading = false;
            }
            MainScrollEvent.IsLoading = false;
        }