fix(android): detekt LongMethod on DiscoverScreen (63/60)

PullToRefreshScaffold addition in 4ca10e2 pushed the function 3
lines over. Extracted the inner Column body into a private
DiscoverBody helper composable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-26 18:44:27 -04:00
parent cf07a2a5a8
commit b6a48a56e8
5 changed files with 726 additions and 36 deletions
@@ -80,41 +80,58 @@ fun DiscoverScreen(
},
snackbarHost = { SnackbarHost(snackbar) },
) { inner ->
Column(modifier = Modifier.fillMaxSize().padding(inner)) {
SearchBar(
query = state.query,
onQueryChange = viewModel::setQuery,
onSubmit = viewModel::runSearch,
)
KindChips(kind = state.kind, onChange = viewModel::setKind)
PullToRefreshScaffold(
onRefresh = { viewModel.loadSuggestions().join() },
modifier = Modifier.fillMaxSize(),
) {
when (val r = state.results) {
ResultsState.Idle -> SuggestionsPane(
state = state.suggestions,
locallyRequestedMbids = state.locallyRequestedMbids,
onRequest = { s ->
scope.launch {
val outcome = viewModel.requestSuggestion(s)
snackbar.showSnackbar(snackbarFor(outcome, s.name))
}
},
)
ResultsState.Loading -> LoadingCentered()
is ResultsState.Loaded -> ResultsList(
rows = r.items,
locallyRequestedMbids = state.locallyRequestedMbids,
onRequest = { row ->
scope.launch {
val outcome = viewModel.requestRow(row)
snackbar.showSnackbar(snackbarFor(outcome, row.name))
}
},
)
is ResultsState.Error -> CenteredMessage("Search failed: ${r.message}")
}
DiscoverBody(
inner = inner,
state = state,
viewModel = viewModel,
snackbar = snackbar,
scope = scope,
)
}
}
@Composable
private fun DiscoverBody(
inner: androidx.compose.foundation.layout.PaddingValues,
state: DiscoverState,
viewModel: DiscoverViewModel,
snackbar: SnackbarHostState,
scope: kotlinx.coroutines.CoroutineScope,
) {
Column(modifier = Modifier.fillMaxSize().padding(inner)) {
SearchBar(
query = state.query,
onQueryChange = viewModel::setQuery,
onSubmit = viewModel::runSearch,
)
KindChips(kind = state.kind, onChange = viewModel::setKind)
PullToRefreshScaffold(
onRefresh = { viewModel.loadSuggestions().join() },
modifier = Modifier.fillMaxSize(),
) {
when (val r = state.results) {
ResultsState.Idle -> SuggestionsPane(
state = state.suggestions,
locallyRequestedMbids = state.locallyRequestedMbids,
onRequest = { s ->
scope.launch {
val outcome = viewModel.requestSuggestion(s)
snackbar.showSnackbar(snackbarFor(outcome, s.name))
}
},
)
ResultsState.Loading -> LoadingCentered()
is ResultsState.Loaded -> ResultsList(
rows = r.items,
locallyRequestedMbids = state.locallyRequestedMbids,
onRequest = { row ->
scope.launch {
val outcome = viewModel.requestRow(row)
snackbar.showSnackbar(snackbarFor(outcome, row.name))
}
},
)
is ResultsState.Error -> CenteredMessage("Search failed: ${r.message}")
}
}
}