feat: 首页显示历史记录功能开关

This commit is contained in:
HuanCheng65 2024-02-02 11:33:00 +08:00
parent a7f88a8fe2
commit 43150dc4ab
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
5 changed files with 51 additions and 31 deletions

View File

@ -407,8 +407,8 @@ fun HomePage(
prop1 = HomeUiState::historyForums,
initial = persistentListOf()
)
val showHistoryForum by viewModel.uiState.collectPartialAsState(
prop1 = HomeUiState::showHistoryForum,
val expandHistoryForum by viewModel.uiState.collectPartialAsState(
prop1 = HomeUiState::expandHistoryForum,
initial = true
)
val error by viewModel.uiState.collectPartialAsState(
@ -418,7 +418,7 @@ fun HomePage(
val isLoggedIn = remember(account) { account != null }
val isEmpty by remember { derivedStateOf { forums.isEmpty() } }
val hasTopForum by remember { derivedStateOf { topForums.isNotEmpty() } }
val hasHistoryForum by remember { derivedStateOf { historyForums.isNotEmpty() } }
val showHistoryForum by remember { derivedStateOf { context.appPreferences.homePageShowHistoryForum && historyForums.isNotEmpty() } }
var listSingle by remember { mutableStateOf(context.appPreferences.listSingle) }
val isError by remember { derivedStateOf { error != null } }
val gridCells by remember { derivedStateOf { getGridCells(context, listSingle) } }
@ -518,10 +518,10 @@ fun HomePage(
contentPadding = PaddingValues(bottom = 12.dp),
modifier = Modifier.fillMaxSize(),
) {
if (hasHistoryForum) {
if (showHistoryForum) {
item(key = "HistoryForums", span = { GridItemSpan(maxLineSpan) }) {
val rotate by animateFloatAsState(
targetValue = if (showHistoryForum) 90f else 0f,
targetValue = if (expandHistoryForum) 90f else 0f,
label = "rotate"
)
Column {
@ -534,7 +534,7 @@ fun HomePage(
) {
viewModel.send(
HomeUiIntent.ToggleHistory(
showHistoryForum
expandHistoryForum
)
)
}
@ -556,7 +556,7 @@ fun HomePage(
.rotate(rotate)
)
}
AnimatedVisibility(visible = showHistoryForum) {
AnimatedVisibility(visible = expandHistoryForum) {
LazyRow(
contentPadding = PaddingValues(bottom = 8.dp),
) {
@ -641,7 +641,7 @@ fun HomePage(
)
}
}
if (hasHistoryForum || hasTopForum) {
if (showHistoryForum || hasTopForum) {
item(key = "ForumHeader", span = { GridItemSpan(maxLineSpan) }) {
Column(
modifier = Modifier.padding(vertical = 8.dp)

View File

@ -132,7 +132,7 @@ class HomeViewModel : BaseViewModel<HomeUiIntent, HomePartialChange, HomeUiState
.catch { emit(HomePartialChange.Unfollow.Failure(it.getErrorMessage())) }
private fun HomeUiIntent.ToggleHistory.toPartialChangeFlow() =
flowOf(HomePartialChange.ToggleHistory(!currentShow))
flowOf(HomePartialChange.ToggleHistory(!currentExpand))
}
}
@ -149,7 +149,7 @@ sealed interface HomeUiIntent : UiIntent {
data class Add(val forum: HomeUiState.Forum) : TopForums
}
data class ToggleHistory(val currentShow: Boolean) : HomeUiIntent
data class ToggleHistory(val currentExpand: Boolean) : HomeUiIntent
}
sealed interface HomePartialChange : PartialChange<HomeUiState> {
@ -256,9 +256,9 @@ sealed interface HomePartialChange : PartialChange<HomeUiState> {
}
}
data class ToggleHistory(val show: Boolean) : HomePartialChange {
data class ToggleHistory(val expand: Boolean) : HomePartialChange {
override fun reduce(oldState: HomeUiState): HomeUiState =
oldState.copy(showHistoryForum = show)
oldState.copy(expandHistoryForum = expand)
}
}
@ -268,7 +268,7 @@ data class HomeUiState(
val forums: ImmutableList<Forum> = persistentListOf(),
val topForums: ImmutableList<Forum> = persistentListOf(),
val historyForums: ImmutableList<History> = persistentListOf(),
val showHistoryForum: Boolean = true,
val expandHistoryForum: Boolean = true,
val error: Throwable? = null,
) : UiState {
@Immutable

View File

@ -17,6 +17,7 @@ import androidx.compose.material.icons.outlined.SecurityUpdateWarning
import androidx.compose.material.icons.outlined.SpeakerNotesOff
import androidx.compose.material.icons.outlined.StarOutline
import androidx.compose.material.icons.outlined.Verified
import androidx.compose.material.icons.outlined.WatchLater
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
@ -191,24 +192,24 @@ fun HabitSettingsPage(
}
}
}
prefsItem {
SwitchPref(
key = "showShortcutInThread",
title = stringResource(id = R.string.settings_show_shortcut),
defaultChecked = true,
leadingIcon = {
LeadingIcon {
AvatarIcon(
icon = ImageVector.vectorResource(id = R.drawable.ic_quick_yellow),
size = Sizes.Small,
contentDescription = null,
)
}
},
summaryOn = stringResource(id = R.string.tip_show_shortcut_in_thread_on),
summaryOff = stringResource(id = R.string.tip_show_shortcut_in_thread)
)
}
// prefsItem {
// SwitchPref(
// key = "showShortcutInThread",
// title = stringResource(id = R.string.settings_show_shortcut),
// defaultChecked = true,
// leadingIcon = {
// LeadingIcon {
// AvatarIcon(
// icon = ImageVector.vectorResource(id = R.drawable.ic_quick_yellow),
// size = Sizes.Small,
// contentDescription = null,
// )
// }
// },
// summaryOn = stringResource(id = R.string.tip_show_shortcut_in_thread_on),
// summaryOff = stringResource(id = R.string.tip_show_shortcut_in_thread)
// )
// }
prefsItem {
SwitchPref(
key = "collect_thread_see_lz",
@ -260,6 +261,22 @@ fun HabitSettingsPage(
}
}
}
prefsItem {
SwitchPref(
key = "homePageShowHistoryForum",
title = stringResource(id = R.string.settings_home_page_show_history_forum),
defaultChecked = true,
leadingIcon = {
LeadingIcon {
AvatarIcon(
icon = Icons.Outlined.WatchLater,
size = Sizes.Small,
contentDescription = null,
)
}
},
)
}
prefsItem {
SwitchPref(
key = "postOrReplyWarning",

View File

@ -126,6 +126,8 @@ open class AppPreferencesUtils private constructor(ctx: Context) {
var homePageScroll by DataStoreDelegates.boolean(defaultValue = false)
var homePageShowHistoryForum by DataStoreDelegates.boolean(defaultValue = true)
var imageDarkenWhenNightMode by DataStoreDelegates.boolean(defaultValue = true)
var imageLoadType by DataStoreDelegates.string(

View File

@ -520,4 +520,5 @@
<string name="desc_input_color">手动输入颜色</string>
<string name="release_to_load_latest_posts">松开加载最新回复</string>
<string name="pull_to_load_latest_posts">继续上拉加载最新回复</string>
<string name="settings_home_page_show_history_forum">首页显示最近逛的吧</string>
</resources>