This commit is contained in:
parent
8c1b4fcdaa
commit
74045b9c6f
@ -14,6 +14,7 @@ import androidx.compose.material.icons.rounded.Refresh
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@ -71,6 +72,7 @@ fun FeedsPage(
|
||||
feedsUiState.importantSum.collectAsStateValue(initial = stringResource(R.string.loading))
|
||||
val groupWithFeedList =
|
||||
feedsUiState.groupWithFeedList.collectAsStateValue(initial = emptyList())
|
||||
val groupsVisible: SnapshotStateMap<String, Boolean> = feedsUiState.groupsVisible
|
||||
|
||||
val newVersion = LocalNewVersionNumber.current
|
||||
val skipVersion = LocalSkipVersionNumber.current
|
||||
@ -101,14 +103,6 @@ fun FeedsPage(
|
||||
}
|
||||
}
|
||||
|
||||
val groupsVisible = remember(groupWithFeedList) {
|
||||
mutableStateMapOf(
|
||||
*(groupWithFeedList.filterIsInstance<GroupFeedsView.Group>().map {
|
||||
it.group.id to groupListExpand.value
|
||||
}.toTypedArray())
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
feedsViewModel.fetchAccount()
|
||||
}
|
||||
@ -217,14 +211,21 @@ fun FeedsPage(
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
GroupItem(
|
||||
isExpanded = { groupsVisible[groupWithFeed.group.id] ?: false },
|
||||
isExpanded = {
|
||||
groupsVisible.getOrPut(
|
||||
groupWithFeed.group.id,
|
||||
groupListExpand::value
|
||||
)
|
||||
},
|
||||
group = groupWithFeed.group,
|
||||
alpha = groupAlpha,
|
||||
indicatorAlpha = groupIndicatorAlpha,
|
||||
isEnded = { index == groupWithFeedList.lastIndex },
|
||||
onExpanded = {
|
||||
groupsVisible[groupWithFeed.group.id] =
|
||||
!(groupsVisible[groupWithFeed.group.id] ?: false)
|
||||
groupsVisible[groupWithFeed.group.id] = groupsVisible.getOrPut(
|
||||
groupWithFeed.group.id,
|
||||
groupListExpand::value
|
||||
).not()
|
||||
}
|
||||
) {
|
||||
filterChange(
|
||||
@ -244,7 +245,12 @@ fun FeedsPage(
|
||||
alpha = groupAlpha,
|
||||
badgeAlpha = feedBadgeAlpha,
|
||||
isEnded = { index == groupWithFeedList.lastIndex || groupWithFeedList[index + 1] is GroupFeedsView.Group },
|
||||
isExpanded = { groupsVisible[groupWithFeed.feed.groupId] ?: false },
|
||||
isExpanded = {
|
||||
groupsVisible.getOrPut(
|
||||
groupWithFeed.feed.groupId,
|
||||
groupListExpand::value
|
||||
)
|
||||
},
|
||||
) {
|
||||
filterChange(
|
||||
navController = navController,
|
||||
|
@ -1,6 +1,8 @@
|
||||
package me.ash.reader.ui.page.home.feeds
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@ -102,7 +104,7 @@ data class FeedsUiState(
|
||||
val importantSum: Flow<String> = emptyFlow(),
|
||||
val groupWithFeedList: Flow<List<GroupFeedsView>> = emptyFlow(),
|
||||
val listState: LazyListState = LazyListState(),
|
||||
val groupsVisible: Boolean = true,
|
||||
val groupsVisible: SnapshotStateMap<String, Boolean> = mutableStateMapOf(),
|
||||
)
|
||||
|
||||
sealed class GroupFeedsView {
|
||||
|
@ -7,7 +7,6 @@ import androidx.compose.animation.core.spring
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -42,8 +41,10 @@ fun ReadingPage(
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
navController.currentBackStackEntryFlow.collect {
|
||||
it.arguments?.getString("articleId")?.let {
|
||||
readingViewModel.initData(it)
|
||||
it.arguments?.getString("articleId")?.let { articleId ->
|
||||
if (readingUiState.articleWithFeed?.article?.id != articleId) {
|
||||
readingViewModel.initData(articleId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user