优化
This commit is contained in:
@@ -104,30 +104,20 @@ fun HomepageScreen(
|
||||
uiState.manageState.sets.filter { it.isSelected }
|
||||
}
|
||||
val pagerState = rememberPagerState(pageCount = {
|
||||
if (layoutMode == 1) selectedSets.size.coerceAtLeast(1) else 1
|
||||
selectedSets.size.coerceAtLeast(1)
|
||||
})
|
||||
|
||||
val mixedGridState = rememberLazyStaggeredGridState()
|
||||
val homeString = stringResource(R.string.home)
|
||||
val currentTitle by remember(
|
||||
layoutMode,
|
||||
pagerState.currentPage,
|
||||
selectedSets,
|
||||
uiState.modules
|
||||
) {
|
||||
derivedStateOf {
|
||||
if (layoutMode == 1) {
|
||||
homeString
|
||||
} else {
|
||||
val firstHeader = mixedGridState.layoutInfo.visibleItemsInfo.firstOrNull {
|
||||
(it.key as? String)?.startsWith("header_") == true
|
||||
}
|
||||
if (firstHeader != null) {
|
||||
val id = (firstHeader.key as? String).orEmpty().substringAfter("header_", "")
|
||||
uiState.modules.find { it.globalId == id }?.setName ?: homeString
|
||||
} else {
|
||||
homeString
|
||||
}
|
||||
selectedSets.getOrNull(pagerState.currentPage)?.sourceName ?: homeString
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,48 +189,36 @@ fun HomepageScreen(
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues),
|
||||
) {
|
||||
if (layoutMode == 0) {
|
||||
ModuleList(
|
||||
modules = uiState.modules,
|
||||
viewModel = viewModel,
|
||||
gridState = mixedGridState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
onErrorClick = { errorMsg = it },
|
||||
sharedTransitionScope = sharedTransitionScope,
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
)
|
||||
if (selectedSets.isEmpty()) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
AppText(stringResource(R.string.homepage_no_source_sets_selected))
|
||||
}
|
||||
} else {
|
||||
if (selectedSets.isEmpty()) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
AppText(stringResource(R.string.homepage_no_source_sets_selected))
|
||||
}
|
||||
} else {
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
key = { index -> selectedSets.getOrNull(index)?.sourceUrl ?: index }
|
||||
) { pageIndex ->
|
||||
val source = selectedSets.getOrNull(pageIndex)
|
||||
val sourceModules = remember(uiState.modules, source) {
|
||||
uiState.modules.filter { module ->
|
||||
if (source?.isCustomSet == true) {
|
||||
val setId =
|
||||
HomepageViewModel.customSetIdFromUrl(source.sourceUrl)
|
||||
module.customSetId == setId
|
||||
} else {
|
||||
module.sourceUrl == source?.sourceUrl
|
||||
}
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
key = { index -> selectedSets.getOrNull(index)?.sourceUrl ?: index }
|
||||
) { pageIndex ->
|
||||
val source = selectedSets.getOrNull(pageIndex)
|
||||
val sourceModules = remember(uiState.modules, source) {
|
||||
uiState.modules.filter { module ->
|
||||
if (source?.isCustomSet == true) {
|
||||
val setId =
|
||||
HomepageViewModel.customSetIdFromUrl(source.sourceUrl)
|
||||
module.customSetId == setId
|
||||
} else {
|
||||
module.sourceUrl == source?.sourceUrl
|
||||
}
|
||||
}
|
||||
ModuleList(
|
||||
modules = sourceModules,
|
||||
viewModel = viewModel,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
onErrorClick = { errorMsg = it },
|
||||
sharedTransitionScope = sharedTransitionScope,
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
)
|
||||
}
|
||||
ModuleList(
|
||||
modules = sourceModules,
|
||||
viewModel = viewModel,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
onErrorClick = { errorMsg = it },
|
||||
sharedTransitionScope = sharedTransitionScope,
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user