0

I have nested scroll view and inside that has 4 recycler views(horizontal, vertical & grid), the last recycler view is vertical and it consists of nested recycler(horizontal) also. I have used the paging 3 library for the last recycler and loading 5 items once. But while inserting data to the recycler view my app is getting freeze. This is the image of my app screen

 viewModel.fullPriceListItem.observe(this@MainFragment) {
                    when (it) {
                        is Resource.Success -> {
                            isApiCallON = false
                            binding.pbPagination.visibility = View.GONE
                            if (KeyConstants.SUCCESS == it.value?.status ?: 0) {

                                if (isFreeDelivery!=null && KeyConstants.isFirstTime) {
                                    showFreeDeliveryDialog(isFreeDelivery!!)
                                    KeyConstants.isFirstTime = false
                                }

                                try{

                                    if (it.value?.data?.isNotEmpty() == true && !isThisLastPage) {
                                        pageNum++

                                        enablePagination(
                                            binding.nestedSv,
                                            binding.rvCheckRegularMenu
                                        )
                                    }else {
                                        isThisLastPage = true

                                        if (!it?.value?.isclosed!!){
                                            requestModel = CommonHomeModel(
                                                latitude = getPrefrenceStringValue(
                                                    requireContext(),
                                                    latitude
                                                ),
                                                longitude = getPrefrenceStringValue(
                                                    requireContext(),
                                                    longitude
                                                ),
                                                distance = getPrefrenceStringValue(
                                                    requireContext(),
                                                    distance
                                                ),
                                                foodType = BOTH,
                                                limit = 5,
                                                token = getPrefrenceStringValue(
                                                    requireContext(),
                                                    jwtToken
                                                ),
                                                userId = getPrefrenceStringValue(
                                                    requireContext(),
                                                    _id
                                                ),
                                                page = pageNum,
                                                isclosed = true
                                            )
                                            pageNum ++
                                            binding.pbPagination.visibility = View.VISIBLE

                                        }

                                        isApiCallON = true

                                    }

                                    if (it.value?.orderCount != null) {
                                        if (it.value?.orderCount == 1) {
                                            AnalyticsEventMethod.MinimumOneOrder(requireContext())
                                        }
                                    }

                                    if (pageNum > 2 && it.value?.data?.isNotEmpty() == true) {
                                        fullPriceListItem?.addAll(it.value?.data?.toMutableList()!!)

                                        binding.rvCheckRegularMenu.adapter?.notifyItemChanged(pageNum*5)

                                    } else if (pageNum == 2){

                                        fullPriceListItem = (it.value?.data?.toMutableList()!!)
                                        binding.rvCheckRegularMenu.layoutManager =
                                            LinearLayoutManager(
                                                requireContext(),
                                                LinearLayoutManager.VERTICAL,
                                                false
                                            )

                                        binding.rvCheckRegularMenu.adapter = RestaurantHomeAdapter(
                                            this@MainFragment,
                                            requireContext(),
                                            fullPriceListItem,
                                            "FullPrice",
                                            this@MainFragment,
                                            it.value?.data?.toMutableList()!!,
                                            filterRequestModel
                                        )

                                        if (it.value?.totalpage?:1 > pageNum && pageNum <=4 && !isThisLastPage){
                                            binding.pbPagination.visibility = View.VISIBLE
                                            requestModel = CommonHomeModel(
                                                latitude = getPrefrenceStringValue(requireContext(), latitude),
                                                longitude = getPrefrenceStringValue(requireContext(), longitude),
                                                distance = getPrefrenceStringValue(requireContext(), distance),
                                                foodType = BOTH,
                                                limit = 5,
                                                token = getPrefrenceStringValue(requireContext(), jwtToken),
                                                userId = getPrefrenceStringValue(requireContext(), _id),
                                                page = pageNum,
                                                isclosed = false

                                            )
                                        }

                                    }

                                    if (binding.rvCheckRegularMenu.adapter?.itemCount!! > 0){
                                        binding.rvCheckRegularMenu.visibility = View.VISIBLE
                                        binding.txtPopularRestaurant.visibility = View.VISIBLE

                                    }
                                    binding.rvCheckRegularMenu.itemAnimator = DefaultItemAnimator()

                                }catch (e: Exception){
                                    e.printStackTrace()
                                    Log.e("mainfragment","Excp: ${e.printStackTrace()}")
                                }
                                binding.shimmerPopular.shimmerContainer.stopShimmer()
                                binding.shimmerPopular.shimmerContainer.visibility = View.GONE
                            } else if (KeyConstants.FAILURE <= it.value?.status ?: 0) {
                                binding.shimmerPopular.shimmerContainer.stopShimmer()
                                binding.shimmerPopular.shimmerContainer.visibility = View.GONE
                                Log.e("mainfragment","fail api")
                            }

                        }

                        is Resource.Failure -> {
                            Log.e("mainfragment","resource fail:$it")
                            binding.shimmerPopular.shimmerContainer.stopShimmer()
                            binding.shimmerPopular.root.visibility = View.GONE
                        }
                        else -> {}
                    }

//                    stopShimmer()
                }

I tried the pagination with paging 3 library and without library also using nested scroll view listener. But both the options making lag while data inserting to the recycler view. I want my page should scroll vertically smoothly.

0 Answers0