private void P_GetProduct(object sender, List <Products> obj) { _products = _products.Concat(obj).ToList(); if (_products.Count == 6) { LoadingSkeleton.HideShimmerAdapter(); LoadingSkeleton.Visibility = ViewStates.Gone; if (mAdapter != null && mAdapter.Product.Count > 0) { mAdapter.AddList(_products); } else { mAdapter = new Wishlist_Adapter(this, _products, this); recyclerView.SetAdapter(mAdapter); } onScrollListener.IsLoading = false; HideShowProgress(); } else if (_products.Count > 0 && myList.Count == 0) { LoadingSkeleton.HideShimmerAdapter(); LoadingSkeleton.Visibility = ViewStates.Gone; if (mAdapter != null && mAdapter.Product.Count > 0) { mAdapter.AddList(_products); } else { mAdapter = new Wishlist_Adapter(this, _products, this); recyclerView.SetAdapter(mAdapter); } onScrollListener.IsLoading = false; HideShowProgress(); } else { if (myList.Count > 0) { CategoryID = myList[myList.Count - 1].CategoryID; SubCategoryID = myList[myList.Count - 1].SubCategoryID; ProductID = myList[myList.Count - 1].ProductID; GetWishList(CategoryID, SubCategoryID, ProductID); myList.RemoveAt(myList.Count - 1); } else { LoadingSkeleton.HideShimmerAdapter(); LoadingSkeleton.Visibility = ViewStates.Gone; } } }
private void ChangeLayout(RecyclerView _recyclerView) { if (mAdapter != null && mAdapter.ItemCount > 0) { int scrollPosition = 0; LinearLayoutManager mLayoutManager; // If a layout manager has already been set, get current scroll position. if (_recyclerView.GetLayoutManager() != null) { scrollPosition = ((LinearLayoutManager)_recyclerView.GetLayoutManager()) .FindFirstCompletelyVisibleItemPosition(); } switch (mCurrentLayoutManagerType) { case MyEnum.ListView: mLayoutManager = new LinearLayoutManager(this); mCurrentLayoutManagerType = MyEnum.Thumbnail; ChangeMenuIconToThumbnail(); _recyclerView.SetLayoutManager(mLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager); break; case MyEnum.Thumbnail: var mGridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false); mCurrentLayoutManagerType = MyEnum.GridView; ChangeMenuIconToList(); _recyclerView.SetLayoutManager(mGridLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mGridLayoutManager); break; case MyEnum.GridView: mLayoutManager = new LinearLayoutManager(this); mCurrentLayoutManagerType = MyEnum.ListView; ChangeMenuIconToList(); _recyclerView.SetLayoutManager(mLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager); break; default: mLayoutManager = new LinearLayoutManager(this); mCurrentLayoutManagerType = MyEnum.ListView; ChangeMenuIconToList(); _recyclerView.SetLayoutManager(mLayoutManager); onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager); break; } mAdapter = new Wishlist_Adapter(this, mAdapter.Product, this); mAdapter.SetLayoutManager(mCurrentLayoutManagerType); _recyclerView.SetAdapter(mAdapter); _recyclerView.ScrollToPosition(scrollPosition); recyclerView.RemoveOnScrollListener(onScrollListener); onScrollListener.LoadMoreEvent += OnScrollListener_LoadMoreEventAsync; onScrollListener.OnHide += OnScrollListener_OnHide; onScrollListener.OnShow += OnScrollListener_OnShow; recyclerView.AddOnScrollListener(onScrollListener); //Decorate Recyclerview if (mCurrentLayoutManagerType == MyEnum.GridView) { _recyclerView.AddItemDecoration(verticalDecoration); } else { _recyclerView.AddItemDecoration(verticalDecoration); } } }