Repository: Automattic/pocket-casts-android
File: modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/view/podcast/PodcastFragment.kt (Kotlin)

Code before:
                    }
                }
            }
        }

        viewModel.castConnected.observe(viewLifecycleOwner) { castConnected ->
            adapter?.castConnected = castConnected
        }

        viewLifecycleOwner.lifecycleScope.launch {
            viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                settings.bottomInset.collect {
                    binding?.episodesRecyclerView?.updatePadding(bottom = it)
                }
            }
        }
    }

    /**
     * Episode search needs at least a page worth of space under the search box so the user can see the results below.
     */
    private fun addPaddingForEpisodeSearch(episodes: List<PodcastEpisode>) {
        val binding = binding ?: return
        val rowCount = episodes.size

        // No padding if there are no episodes
        if (rowCount == 0) {
            binding.episodesRecyclerView.updatePadding(bottom = 0)
            return
        }

        val pageHeight = binding.episodesRecyclerView.height
        val context = binding.episodesRecyclerView.context
        val episodeHeaderHeightPx = 90.dpToPx(context)
        val rowHeightPx = 80.dpToPx(context)
        val actualHeight = episodeHeaderHeightPx + (rowCount * rowHeightPx)
        val missingHeightPx = pageHeight - actualHeight

        // Only add padding if needed to prevent screen jump
        if (binding.episodesRecyclerView.paddingBottom <= missingHeightPx && missingHeightPx > 0) {
            binding.episodesRecyclerView.updatePadding(bottom = missingHeightPx)
        }
    }

    override fun onDestroyView() {
        binding?.episodesRecyclerView?.adapter = null
        itemTouchHelper = null

        viewModel.multiSelectEpisodesHelper.cleanup()
        viewModel.multiSelectBookmarksHelper.cleanup()


Review comment (suggestion):
There's no need to include such comments. It is obvious what the code does here. If you want to include one it's better to explain why such a check exists. But it should be combined with the comment below to a single comment.

Code after:
                    }
                }
            }
        }

        viewModel.castConnected.observe(viewLifecycleOwner) { castConnected ->
            adapter?.castConnected = castConnected
        }

        viewLifecycleOwner.lifecycleScope.launch {
            viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                settings.bottomInset.collect {
                    binding?.episodesRecyclerView?.updatePadding(bottom = it)
                }
            }
        }
    }

    /**
     * Episode search needs at least a page worth of space under the search box so the user can see the results below.
     */
    private fun addPaddingForEpisodeSearch(episodes: List<PodcastEpisode>) {
        val binding = binding ?: return
        val rowCount = episodes.size

        // No padding for empty state to avoid excessive whitespace
        if (rowCount == 0) {
            binding.episodesRecyclerView.updatePadding(bottom = 0)
            return
        }

        val pageHeight = binding.episodesRecyclerView.height
        val context = binding.episodesRecyclerView.context
        val episodeHeaderHeightPx = 90.dpToPx(context)
        val rowHeightPx = 80.dpToPx(context)
        val actualHeight = episodeHeaderHeightPx + (rowCount * rowHeightPx)
        val missingHeightPx = pageHeight - actualHeight

        // Only add padding if needed to prevent screen jump
        if (binding.episodesRecyclerView.paddingBottom <= missingHeightPx && missingHeightPx > 0) {
            binding.episodesRecyclerView.updatePadding(bottom = missingHeightPx)
        }
    }

    override fun onDestroyView() {
        binding?.episodesRecyclerView?.adapter = null
        itemTouchHelper = null

        viewModel.multiSelectEpisodesHelper.cleanup()
        viewModel.multiSelectBookmarksHelper.cleanup()