style(android): satisfy detekt on the new browse tabs — #2467
android / Build + lint + test (push) Successful in 3m54s
android / Build + lint + test (push) Successful in 3m54s
Two findings, both fair: LibraryScreen was one line over the 60-line cap once Genres and Years were added to its pager. Split the page bodies into LibraryTabPage, so the screen is the scaffold and tab bar while the routing table lives on its own -- adding a tab is now one line there and one label in LIBRARY_TABS, rather than growing a function that was already at its limit. The decade arithmetic used a bare 10 twice. Named it YEARS_PER_DECADE: floor-to-decade reads as arbitrary without it.
This commit is contained in:
@@ -240,6 +240,11 @@ fun visibleGenres(
|
||||
}
|
||||
}
|
||||
|
||||
// Integer division by this floors a year to its decade: 2007 -> 2000. Named
|
||||
// because detekt counts it as magic, and because the arithmetic reads as
|
||||
// arbitrary otherwise.
|
||||
private const val YEARS_PER_DECADE = 10
|
||||
|
||||
/** A decade's worth of the year index, newest year first. */
|
||||
data class DecadeGroup(
|
||||
val decade: Int,
|
||||
@@ -255,7 +260,7 @@ data class DecadeGroup(
|
||||
* same reason as [visibleGenres].
|
||||
*/
|
||||
fun groupByDecade(years: List<YearCount>): List<DecadeGroup> =
|
||||
years.groupBy { (it.year / 10) * 10 }
|
||||
years.groupBy { (it.year / YEARS_PER_DECADE) * YEARS_PER_DECADE }
|
||||
.map { (decade, entries) ->
|
||||
DecadeGroup(
|
||||
decade = decade,
|
||||
|
||||
@@ -117,6 +117,22 @@ fun LibraryScreen(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize().padding(inner),
|
||||
) { page ->
|
||||
LibraryTabPage(page = page, viewModel = viewModel, navController = navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The pager's page bodies, split out of [LibraryScreen] so the screen stays
|
||||
* the scaffold + tab bar and this stays the routing table. Adding a tab is
|
||||
* then one line here and one label in [LIBRARY_TABS].
|
||||
*/
|
||||
@Composable
|
||||
private fun LibraryTabPage(
|
||||
page: Int,
|
||||
viewModel: LibraryViewModel,
|
||||
navController: NavHostController,
|
||||
) {
|
||||
when (page) {
|
||||
TAB_ARTISTS -> ArtistsTab(viewModel = viewModel, navController = navController)
|
||||
TAB_ALBUMS -> AlbumsTab(viewModel = viewModel, navController = navController)
|
||||
@@ -134,8 +150,6 @@ fun LibraryScreen(
|
||||
TAB_HIDDEN -> HiddenTab()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val TAB_ARTISTS = 0
|
||||
private const val TAB_ALBUMS = 1
|
||||
|
||||
Reference in New Issue
Block a user