Repository: android/compose-samples
File: JetNews/app/src/main/java/com/example/jetnews/ui/interests/InterestsScreen.kt (Kotlin)

Code before:
        color = MaterialTheme.colors.onSurface.copy(alpha = 0.1f)
    )
}

/**
 * TabRow for the InterestsScreen
 */
@Composable
private fun InterestsTabRow(
    selectedTabIndex: Int,
    updateSection: (Sections) -> Unit,
    tabContent: List<TabContent>
) {
    BoxWithConstraints {
        val windowSize = remember(maxWidth) { getWindowSize(maxWidth) }
        when (windowSize) {
            WindowSize.Compact -> {
                TabRow(
                    selectedTabIndex = selectedTabIndex,
                    backgroundColor = MaterialTheme.colors.onPrimary,
                    contentColor = MaterialTheme.colors.primary
                ) {
                    InterestsTabRowContent(selectedTabIndex, updateSection, tabContent)
                }
            }
            else -> {
                ScrollableTabRow(
                    selectedTabIndex = selectedTabIndex,
                    backgroundColor = MaterialTheme.colors.onPrimary,
                    contentColor = MaterialTheme.colors.primary,
                    edgePadding = 0.dp
                ) {
                    InterestsTabRowContent(
                        selectedTabIndex = selectedTabIndex,
                        updateSection = updateSection,
                        tabContent = tabContent,
                        modifier = Modifier.padding(horizontal = 8.dp)
                    )
                }
            }
        }
    }
}

@Composable
private fun InterestsTabRowContent(
    selectedTabIndex: Int,
    updateSection: (Sections) -> Unit,
    tabContent: List<TabContent>,
    modifier: Modifier = Modifier
) {

Review comment (suggestion):
Minor nit: I personally prefer to always add in all cases directly, rather than use an `else`. Once the exhaustive change lands in Kotlin, that will cause a compiler exception initially if a new size class is added or one is removed, which allows re-evaluating all of the decisions like this without having to search for them.

Code after:
                }
            }
        }
    }
}

@Composable
private fun InterestsTabRowContent(
    selectedTabIndex: Int,
    updateSection: (Sections) -> Unit,
    tabContent: List<TabContent>,
    modifier: Modifier = Modifier
) {
    tabContent.forEachIndexed { index, content ->
        val colorText = if (selectedTabIndex == index) {
            MaterialTheme.colors.primary
        } else {
            MaterialTheme.colors.onSurface.copy(alpha = 0.8f)
        }
        Tab(
            selected = selectedTabIndex == index,
            onClick = { updateSection(content.section) },
            modifier = Modifier.heightIn(min = 48.dp)
        ) {
            Text(
                text = stringResource(id = content.section.titleResId),
                color = colorText,
                style = MaterialTheme.typography.subtitle2,
                modifier = modifier.paddingFromBaseline(top = 20.dp)
            )
        }
    }
}

/**
 * Return the interest sections grouped given the number of columns that fill the screen.
 * Sections are distributed to balance the number of items on each column.
 */
@Composable
private fun rememberSectionsGroupedInColumns(
    sections: List<InterestSection>,
    columns: Int
): List<List<InterestSection>> = remember(sections, columns) {
    val sectionsInColumns = List<MutableList<InterestSection>>(columns) { mutableListOf() }
    val elementsInColumns = IntArray(columns)
    // For each section, find the column with less elements and add it there
    sections.forEach { section ->
        val shortestColumnIndex = elementsInColumns.withIndex().minByOrNull { it.value }!!.index
        sectionsInColumns[shortestColumnIndex] += section
        elementsInColumns[shortestColumnIndex] += section.interests.size
    }