From 43150dc4abaa49de768349799461162caa1fc57f Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 2 Feb 2024 11:33:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/ui/page/main/home/HomePage.kt | 16 +++--- .../post/ui/page/main/home/HomeViewModel.kt | 10 ++-- .../page/settings/habit/HabitSettingsPage.kt | 53 ++++++++++++------- .../tieba/post/utils/AppPreferencesUtils.kt | 2 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 51 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomePage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomePage.kt index 3bfcdf56..329cc859 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomePage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomePage.kt @@ -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) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomeViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomeViewModel.kt index 602bde80..6f3aaf5c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomeViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/home/HomeViewModel.kt @@ -132,7 +132,7 @@ class HomeViewModel : BaseViewModel { @@ -256,9 +256,9 @@ sealed interface HomePartialChange : PartialChange { } } - 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 = persistentListOf(), val topForums: ImmutableList = persistentListOf(), val historyForums: ImmutableList = persistentListOf(), - val showHistoryForum: Boolean = true, + val expandHistoryForum: Boolean = true, val error: Throwable? = null, ) : UiState { @Immutable diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt index 11ff3078..af108f8e 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt @@ -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", diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt index 61ae5e65..4506d9fa 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt @@ -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( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 768bc338..699fd3a9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -520,4 +520,5 @@ 手动输入颜色 松开加载最新回复 继续上拉加载最新回复 + 首页显示最近逛的吧