Stop scroll of Epoxy Recyclerview on item update

1k Views Asked by At

I am new to Epoxy Recyclerview. My query is as follows.

  1. I have added quite a few items in recyclerview using kotlin databinding, those consists of banners, title, grid, product carousel.
  2. I have a button which adds product in wishlist and changes color of view. This functionality is working fine.
  3. What I want is not to scroll recyclerview to top and reset all views. Like if I mark 4th product in carousel as inWishlist then recyclerview must not scroll to top and carousel must not reset.

Can anyone help me in achieving this?

here is the code This is HomeData class.

data class HomeData(val listBanners : ArrayList<String> = arrayListOf("banner1", "banner2", "banner3"),
                val listOutCategories : ArrayList<String> = arrayListOf("1", "2", "3", "4", "5", "6", "7", "8"),
                val listSaleProducts : ArrayList<Product> = arrayListOf(
                    Product(id=0, price = "$10.90"),
                    Product(id=1, price = "$11.90"),
                    Product(id=2, price = "$12.90"),
                    Product(id=3, price = "$13.90"),
                    Product(id=4, price = "$14.90"),
                    Product(id=5, price = "$105.90"),
                    Product(id=6, price = "$17.90"),
                    Product(id=7, price = "$18.90")
                ))

data class Product(val id:Int = 0, val name:String = "Product", val price:String="12.90", var inWishlist:Boolean = false)

This is function called to set data.

fun setRecyclerView(data:HomeData, isLoading : Boolean){

    binding.recyclerView.clear()

    binding.recyclerView.withModels {
        if(isLoading){
            loadList {
                id("loading")
                mainViewModel(mainActivityViewModel)
                spanSizeOverride { totalSpanCount, position, itemCount -> 1 }
            }
        }else{

            carousel {
                id("top-banners")
                withModelsFrom(data.listBanners){
                    TopBannerBindingModel_().id(it)
                }
            }

            title {
                id("out_categories_title")
                title("The Out Categories")
            }

            grid {
                id("out_cat_group")
                onBind { model, view, position ->
                    (view.dataBinding as ItemGridBinding).recyclerViewGrid.withModels {
                        data.listOutCategories.forEachIndexed { index, s ->
                            outCategory {
                                id("$index-$s")
                            }
                        }
                    }
                }
            }

            title {
                id("on_sale_title")
                title("On Sale")
            }

            carousel {
                id("on_sale_products")
                withModelsFrom(data.listSaleProducts){
                    ProductBindingModel_()
                        .id(it.id)
                        .product(it)
                        .clickListener { model, parentView, clickedView, position ->
                            data.listSaleProducts[position].inWishlist = true
                            setRecyclerView(data, false)
                        }
                }
            }
        }
    }
}

enter image description here

0

There are 0 best solutions below