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

Code before:
        val widthPx = UiUtil.getWindowWidthPx(context)
        if (orientation == lastOrientationRefreshed && lastWidthPx == widthPx) return

        // screen has rotated, redraw the grid to the right size
        setupGridView()

        lastOrientationRefreshed = orientation
        lastWidthPx = widthPx
    }

    private fun setupEmptyStateView() {
        val folderUuid = folderUuid

        binding.emptyView.setContentWithViewCompositionStrategy {
            val ads by viewModel.activeAds.collectAsState()

            AppTheme(themeType = theme.activeTheme) {
                Column(
                    verticalArrangement = Arrangement.spacedBy(16.dp),
                    horizontalAlignment = Alignment.CenterHorizontally,
                    modifier = Modifier
                        .fillMaxSize()
                        .verticalScroll(rememberScrollState())
                        .padding(16.dp),
                ) {
                    ads.take(1).forEach { ad ->
                        AdBanner(
                            ad = ad,
                            colors = rememberAdColors().bannerAd,
                            onAdClick = { openAd(ad) },
                            onOptionsClick = {},
                        )
                    }

                    Spacer(
                        modifier = Modifier.weight(1f),
                    )

                    if (folderUuid != null) {
                        NoFolderPodcastsBanner(
                            onClickButton = {
                                FolderEditPodcastsFragment.newInstance(folderUuid).show(parentFragmentManager, "add_podcasts_card")
                            },
                        )
                    } else {
                        NoPodcastsBanner(
                            onClickButton = {
                                analyticsTracker.track(AnalyticsEvent.PODCASTS_LIST_DISCOVER_BUTTON_TAPPED)
                                (activity as FragmentHostListener).openTab(VR.id.navigation_discover)
                            },
                        )

Review comment (suggestion):
💡 maybe `ads.firstOrNull()?.let` would be more fitting

Code after:
        val orientation = resources.configuration.orientation
        val widthPx = UiUtil.getWindowWidthPx(context)
        if (orientation == lastOrientationRefreshed && lastWidthPx == widthPx) return

        // screen has rotated, redraw the grid to the right size
        setupGridView()

        lastOrientationRefreshed = orientation
        lastWidthPx = widthPx
    }

    private fun setupEmptyStateView() {
        val folderUuid = folderUuid

        binding.emptyView.setContentWithViewCompositionStrategy {
            val ads by viewModel.activeAds.collectAsState()

            AppTheme(themeType = theme.activeTheme) {
                Column(
                    verticalArrangement = Arrangement.spacedBy(16.dp),
                    horizontalAlignment = Alignment.CenterHorizontally,
                    modifier = Modifier
                        .fillMaxSize()
                        .verticalScroll(rememberScrollState())
                        .padding(16.dp),
                ) {
                    ads.firstOrNull()?.let { ad ->
                        AdBanner(
                            ad = ad,
                            colors = rememberAdColors().bannerAd,
                            onAdClick = { openAd(ad) },
                            onOptionsClick = {},
                        )
                    }

                    Spacer(
                        modifier = Modifier.weight(1f),
                    )

                    if (folderUuid != null) {
                        NoFolderPodcastsBanner(
                            onClickButton = {
                                FolderEditPodcastsFragment.newInstance(folderUuid).show(parentFragmentManager, "add_podcasts_card")
                            },
                        )
                    } else {
                        NoPodcastsBanner(
                            onClickButton = {
                                analyticsTracker.track(AnalyticsEvent.PODCASTS_LIST_DISCOVER_BUTTON_TAPPED)
                                (activity as FragmentHostListener).openTab(VR.id.navigation_discover)
                            },