From f9d37c4c29a91261e2e930f2b0d11dfd77c9b98b Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 25 Mar 2024 16:41:30 -0400 Subject: [PATCH] Moving to a new preferences library. (#1451) * Moving to a new preferences library. * Removing more = remember * Fix. * Small change --------- Co-authored-by: maarten.vercruysse --- app/build.gradle.kts | 2 +- app/src/main/java/com/jerboa/Utils.kt | 13 +- .../main/java/com/jerboa/datatypes/Others.kt | 4 +- .../jerboa/feat/PostNavigationGestureMode.kt | 5 +- .../java/com/jerboa/feat/SwipeToAction.kt | 3 +- .../ui/components/community/Community.kt | 2 +- .../com/jerboa/ui/components/home/Home.kt | 2 +- .../components/settings/SettingsActivity.kt | 71 +- .../settings/about/AboutActivity.kt | 271 +++--- .../settings/account/AccountSettings.kt | 216 +++-- .../lookandfeel/LookAndFeelActivity.kt | 780 ++++++++++-------- .../main/java/com/jerboa/ui/theme/Sizes.kt | 4 - app/src/main/res/values/strings.xml | 2 + 13 files changed, 714 insertions(+), 661 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5be51babe..2740aebf0 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -109,7 +109,7 @@ android { dependencies { implementation("androidx.appcompat:appcompat:1.6.1") - implementation("com.github.alorma:compose-settings-ui-m3:1.0.3") + implementation("me.zhanghai.compose.preference:library:1.0.0") implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.12") diff --git a/app/src/main/java/com/jerboa/Utils.kt b/app/src/main/java/com/jerboa/Utils.kt index 5e2380b4a..3665b42bf 100644 --- a/app/src/main/java/com/jerboa/Utils.kt +++ b/app/src/main/java/com/jerboa/Utils.kt @@ -26,6 +26,7 @@ import androidx.activity.result.ActivityResultCallback import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContract import androidx.annotation.RequiresApi +import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatDelegate import androidx.browser.customtabs.CustomTabsIntent import androidx.compose.foundation.lazy.LazyListState @@ -734,7 +735,9 @@ fun Context.findActivity(): Activity? = else -> null } -enum class ThemeMode(val mode: Int) { +enum class ThemeMode( + @StringRes val resId: Int, +) { System(R.string.look_and_feel_theme_system), SystemBlack(R.string.look_and_feel_theme_system_black), Light(R.string.look_and_feel_theme_light), @@ -742,7 +745,9 @@ enum class ThemeMode(val mode: Int) { Black(R.string.look_and_feel_theme_black), } -enum class ThemeColor(val mode: Int) { +enum class ThemeColor( + @StringRes val resId: Int, +) { Dynamic(R.string.look_and_feel_theme_color_dynamic), Beach(R.string.look_and_feel_theme_color_beach), Blue(R.string.look_and_feel_theme_color_blue), @@ -755,7 +760,9 @@ enum class ThemeColor(val mode: Int) { Dracula(R.string.look_and_feel_theme_color_dracula), } -enum class PostViewMode(val mode: Int) { +enum class PostViewMode( + @StringRes val resId: Int, +) { /** * The full size post view card. For image posts, this expands them to their full height. For * link posts, the thumbnail is shown to the right of the title. diff --git a/app/src/main/java/com/jerboa/datatypes/Others.kt b/app/src/main/java/com/jerboa/datatypes/Others.kt index d5228bc6b..498d99fcd 100644 --- a/app/src/main/java/com/jerboa/datatypes/Others.kt +++ b/app/src/main/java/com/jerboa/datatypes/Others.kt @@ -64,13 +64,13 @@ val SortType.data: SortData SortType.TopAll -> SortData(R.string.sorttype_topall, R.string.dialogs_top_all, Icons.Outlined.BarChart) SortType.MostComments -> SortData( R.string.sorttype_mostcomments, - R.string.sorttype_mostcomments, + R.string.sorttype_mostcomments_long, Icons.Outlined.FormatListNumbered, ) SortType.NewComments -> SortData( R.string.sorttype_newcomments, - R.string.sorttype_newcomments, + R.string.sorttype_newcomments_long, Icons.Outlined.NewReleases, ) diff --git a/app/src/main/java/com/jerboa/feat/PostNavigationGestureMode.kt b/app/src/main/java/com/jerboa/feat/PostNavigationGestureMode.kt index 2c0956af0..9535e82bf 100644 --- a/app/src/main/java/com/jerboa/feat/PostNavigationGestureMode.kt +++ b/app/src/main/java/com/jerboa/feat/PostNavigationGestureMode.kt @@ -1,8 +1,11 @@ package com.jerboa.feat +import androidx.annotation.StringRes import com.jerboa.R -enum class PostNavigationGestureMode(val mode: Int) { +enum class PostNavigationGestureMode( + @StringRes val resId: Int, +) { /** * Disable all navigation gestures within posts. */ diff --git a/app/src/main/java/com/jerboa/feat/SwipeToAction.kt b/app/src/main/java/com/jerboa/feat/SwipeToAction.kt index 4d2feccce..53fa04334 100644 --- a/app/src/main/java/com/jerboa/feat/SwipeToAction.kt +++ b/app/src/main/java/com/jerboa/feat/SwipeToAction.kt @@ -1,5 +1,6 @@ package com.jerboa.feat +import androidx.annotation.StringRes import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.Comment import androidx.compose.material.icons.outlined.Bookmark @@ -71,7 +72,7 @@ data class ActionColor( enum class SwipeToActionPreset( val leftActions: List, val rightActions: List, - val resId: Int, + @StringRes val resId: Int, ) { Disabled(emptyList(), emptyList(), R.string.swipe_action_preset_disabled), TwoSides( diff --git a/app/src/main/java/com/jerboa/ui/components/community/Community.kt b/app/src/main/java/com/jerboa/ui/components/community/Community.kt index 064f9f99a..30b363a4a 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/Community.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/Community.kt @@ -297,7 +297,7 @@ fun CommunityMoreDropdown( children = { PostViewMode.entries.map { DropdownMenuItem( - text = { Text(text = stringResource(it.mode)) }, + text = { Text(text = stringResource(it.resId)) }, onClick = { onDismissRequest() onClickPostViewMode(it) diff --git a/app/src/main/java/com/jerboa/ui/components/home/Home.kt b/app/src/main/java/com/jerboa/ui/components/home/Home.kt index 89e2274e6..15fd56293 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/Home.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/Home.kt @@ -217,7 +217,7 @@ fun HomeMoreDropdown( children = { PostViewMode.entries.map { DropdownMenuItem( - text = { Text(text = stringResource(it.mode)) }, + text = { Text(text = stringResource(it.resId)) }, onClick = { onDismissRequest() onClickPostViewMode(it) diff --git a/app/src/main/java/com/jerboa/ui/components/settings/SettingsActivity.kt b/app/src/main/java/com/jerboa/ui/components/settings/SettingsActivity.kt index df5cfb877..bfb0a624c 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/SettingsActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/SettingsActivity.kt @@ -4,7 +4,6 @@ package com.jerboa.ui.components.settings import android.util.Log import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Info @@ -19,14 +18,14 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import com.alorma.compose.settings.ui.SettingsMenuLink import com.jerboa.R import com.jerboa.db.entity.isAnon import com.jerboa.model.AccountViewModel import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.SimpleTopAppBar import com.jerboa.ui.components.common.getCurrentAccount -import com.jerboa.ui.theme.SETTINGS_MENU_LINK_HEIGHT +import me.zhanghai.compose.preference.Preference +import me.zhanghai.compose.preference.ProvidePreferenceTheme @Composable fun SettingsActivity( @@ -48,48 +47,48 @@ fun SettingsActivity( }, content = { padding -> Column(modifier = Modifier.padding(padding)) { - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_activity_look_and_feel)) }, - icon = { - Icon( - imageVector = Icons.Outlined.Palette, - contentDescription = null, - ) - }, - onClick = onClickLookAndFeel, - ) - if (!account.isAnon()) { - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { - Text( - stringResource( - R.string.settings_activity_account_settings, - account.name, - ), + ProvidePreferenceTheme { + Preference( + title = { Text(stringResource(R.string.settings_activity_look_and_feel)) }, + icon = { + Icon( + imageVector = Icons.Outlined.Palette, + contentDescription = null, ) }, + onClick = onClickLookAndFeel, + ) + + if (!account.isAnon()) { + Preference( + title = { + Text( + stringResource( + R.string.settings_activity_account_settings, + account.name, + ), + ) + }, + icon = { + Icon( + imageVector = Icons.Outlined.ManageAccounts, + contentDescription = null, + ) + }, + onClick = onClickAccountSettings, + ) + } + Preference( + title = { Text(stringResource(R.string.settings_activity_about)) }, icon = { Icon( - imageVector = Icons.Outlined.ManageAccounts, + imageVector = Icons.Outlined.Info, contentDescription = null, ) }, - onClick = onClickAccountSettings, + onClick = onClickAbout, ) } - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_activity_about)) }, - icon = { - Icon( - imageVector = Icons.Outlined.Info, - contentDescription = null, - ) - }, - onClick = onClickAbout, - ) } }, ) diff --git a/app/src/main/java/com/jerboa/ui/components/settings/about/AboutActivity.kt b/app/src/main/java/com/jerboa/ui/components/settings/about/AboutActivity.kt index c5443cf89..1acaf05cd 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/about/AboutActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/about/AboutActivity.kt @@ -2,7 +2,6 @@ package com.jerboa.ui.components.settings.about import android.util.Log import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState @@ -16,9 +15,7 @@ import androidx.compose.material.icons.outlined.Code import androidx.compose.material.icons.outlined.NewReleases import androidx.compose.material.icons.outlined.TravelExplore import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState @@ -26,16 +23,16 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import com.alorma.compose.settings.ui.SettingsMenuLink import com.jerboa.R import com.jerboa.ui.components.common.SimpleTopAppBar -import com.jerboa.ui.theme.SETTINGS_MENU_LINK_HEIGHT +import me.zhanghai.compose.preference.Preference +import me.zhanghai.compose.preference.PreferenceCategory +import me.zhanghai.compose.preference.ProvidePreferenceTheme const val GITHUB_URL = "https://github.com/dessalines/jerboa" const val JERBOA_MATRIX_CHAT = "https://matrix.to/#/#jerboa-dev:matrix.org" @@ -79,151 +76,133 @@ fun AboutActivity( .verticalScroll(rememberScrollState()) .padding(padding), ) { - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_what_s_new)) }, - subtitle = { - Text( - stringResource( - R.string.settings_about_version, - version ?: "", - ), - ) - }, - icon = { - Icon( - imageVector = Icons.Outlined.NewReleases, - contentDescription = null, - ) - }, - onClick = { - openLink("$GITHUB_URL/blob/main/RELEASES.md") - }, - ) - SettingsDivider() - SettingsHeader(text = stringResource(R.string.settings_about_support)) - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_issue_tracker)) }, - icon = { - Icon( - imageVector = Icons.Outlined.BugReport, - contentDescription = null, - ) - }, - onClick = { - openLink("$GITHUB_URL/issues") - }, - ) - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.crash_logs)) }, - icon = { - Icon( - imageVector = Icons.Outlined.Build, - contentDescription = null, - ) - }, - onClick = onClickCrashLogs, - ) - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_developer_matrix_chatroom)) }, - icon = { - Icon( - imageVector = Icons.AutoMirrored.Outlined.Chat, - contentDescription = null, - ) - }, - onClick = { - openLink(JERBOA_MATRIX_CHAT) - }, - ) - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_donate_to_jerboa_development)) }, - icon = { - Icon( - imageVector = Icons.Outlined.AttachMoney, - contentDescription = null, - ) - }, - onClick = { - openLink(DONATE_LINK) - }, - ) - SettingsDivider() - SettingsHeader(text = stringResource(R.string.about_social)) - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_join_c_jerboa)) }, - icon = { - Icon( - painter = painterResource(id = R.drawable.ic_jerboa), - modifier = Modifier.size(24.dp), - contentDescription = null, - ) - }, - onClick = { - openLink(JERBOA_LEMMY_ML_LINK) - }, - ) - SettingsMenuLink( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_follow_on_mastodon)) }, - icon = { - Icon( - imageVector = Icons.Outlined.TravelExplore, - contentDescription = null, - ) - }, - onClick = { - openLink(MASTODON_LINK) - }, - ) - SettingsDivider() - SettingsHeader(text = stringResource(R.string.settings_about_open_source)) - SettingsMenuLink( - modifier = Modifier.padding(top = 20.dp).height(SETTINGS_MENU_LINK_HEIGHT), - title = { Text(stringResource(R.string.settings_about_source_code)) }, - subtitle = { - Text( - stringResource(R.string.settings_about_source_code_subtitle_part1) + - stringResource(R.string.settings_about_source_code_subtitle_part2), - ) - }, - icon = { - Icon( - imageVector = Icons.Outlined.Code, - contentDescription = null, - ) - }, - onClick = { - openLink(GITHUB_URL) - }, - ) + ProvidePreferenceTheme { + Preference( + title = { Text(stringResource(R.string.settings_about_what_s_new)) }, + summary = { + Text( + stringResource( + R.string.settings_about_version, + version ?: "", + ), + ) + }, + icon = { + Icon( + imageVector = Icons.Outlined.NewReleases, + contentDescription = null, + ) + }, + onClick = { + openLink("$GITHUB_URL/blob/main/RELEASES.md") + }, + ) + PreferenceCategory( + title = { Text(stringResource(R.string.settings_about_support)) }, + ) + Preference( + title = { Text(stringResource(R.string.settings_about_issue_tracker)) }, + icon = { + Icon( + imageVector = Icons.Outlined.BugReport, + contentDescription = null, + ) + }, + onClick = { + openLink("$GITHUB_URL/issues") + }, + ) + Preference( + title = { Text(stringResource(R.string.crash_logs)) }, + icon = { + Icon( + imageVector = Icons.Outlined.Build, + contentDescription = null, + ) + }, + onClick = onClickCrashLogs, + ) + Preference( + title = { Text(stringResource(R.string.settings_about_developer_matrix_chatroom)) }, + icon = { + Icon( + imageVector = Icons.AutoMirrored.Outlined.Chat, + contentDescription = null, + ) + }, + onClick = { + openLink(JERBOA_MATRIX_CHAT) + }, + ) + Preference( + title = { Text(stringResource(R.string.settings_about_donate_to_jerboa_development)) }, + icon = { + Icon( + imageVector = Icons.Outlined.AttachMoney, + contentDescription = null, + ) + }, + onClick = { + openLink(DONATE_LINK) + }, + ) + PreferenceCategory( + title = { Text(stringResource(R.string.about_social)) }, + ) + Preference( + title = { Text(stringResource(R.string.settings_about_join_c_jerboa)) }, + icon = { + Icon( + painter = painterResource(id = R.drawable.ic_jerboa), + modifier = Modifier.size(24.dp), + contentDescription = null, + ) + }, + onClick = { + openLink(JERBOA_LEMMY_ML_LINK) + }, + ) + Preference( + title = { Text(stringResource(R.string.settings_about_follow_on_mastodon)) }, + icon = { + Icon( + imageVector = Icons.Outlined.TravelExplore, + contentDescription = null, + ) + }, + onClick = { + openLink(MASTODON_LINK) + }, + ) + PreferenceCategory( + title = { + Text(stringResource(R.string.settings_about_open_source)) + }, + ) + Preference( + title = { Text(stringResource(R.string.settings_about_source_code)) }, + summary = { + Text( + stringResource(R.string.settings_about_source_code_subtitle_part1) + + stringResource(R.string.settings_about_source_code_subtitle_part2), + ) + }, + icon = { + Icon( + imageVector = Icons.Outlined.Code, + contentDescription = null, + ) + }, + onClick = { + openLink(GITHUB_URL) + }, + ) + } } }, ) } -@Composable -fun SettingsDivider() { - HorizontalDivider(modifier = Modifier.padding(vertical = 10.dp)) -} - -@Composable -fun SettingsHeader( - text: String, - color: Color = MaterialTheme.colorScheme.primary, -) { - Text( - text, - modifier = Modifier.padding(start = 64.dp), - color = color, - ) -} - @Preview @Composable fun AboutPreview() { diff --git a/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt b/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt index f9c146857..6f2ce71c6 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState @@ -30,17 +29,15 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.TextFieldValue -import com.alorma.compose.settings.storage.base.rememberBooleanSettingState -import com.alorma.compose.settings.storage.base.rememberIntSettingState -import com.alorma.compose.settings.ui.SettingsCheckbox -import com.alorma.compose.settings.ui.SettingsListDropdown import com.jerboa.R import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.datatypes.data +import com.jerboa.datatypes.getLocalizedListingTypeName import com.jerboa.db.entity.Account import com.jerboa.imageInputStreamFromUri import com.jerboa.model.SiteViewModel @@ -49,13 +46,16 @@ import com.jerboa.ui.components.common.MarkdownTextField import com.jerboa.ui.components.common.PickImage import com.jerboa.ui.components.common.PictrsBannerImage import com.jerboa.ui.theme.MEDIUM_PADDING -import com.jerboa.ui.theme.SETTINGS_MENU_LINK_HEIGHT import com.jerboa.ui.theme.muted import it.vercruysse.lemmyapi.dto.ListingType import it.vercruysse.lemmyapi.dto.SortType import it.vercruysse.lemmyapi.dto.getSupportedEntries import it.vercruysse.lemmyapi.v0x19.datatypes.SaveUserSettings import kotlinx.coroutines.launch +import me.zhanghai.compose.preference.ListPreference +import me.zhanghai.compose.preference.ListPreferenceType +import me.zhanghai.compose.preference.ProvidePreferenceTheme +import me.zhanghai.compose.preference.SwitchPreference @Composable fun SettingsTextField( @@ -137,20 +137,18 @@ fun SettingsForm( var banner by rememberSaveable { mutableStateOf(luv?.person?.banner.orEmpty()) } val supportedSortTypes = remember { getSupportedEntries(API.version) } val defaultSortTypeInitial = luv?.local_user?.default_sort_type ?: SortType.Active - val defaultSortType = rememberIntSettingState(supportedSortTypes.indexOf(defaultSortTypeInitial)) - val defaultListingType = - rememberIntSettingState(luv?.local_user?.default_listing_type?.ordinal ?: 0) - val showAvatars = rememberBooleanSettingState(luv?.local_user?.show_avatars ?: false) - val showNsfw = rememberBooleanSettingState(luv?.local_user?.show_nsfw ?: false) - val showScores = rememberBooleanSettingState(luv?.local_user?.show_scores ?: false) - val showBotAccount = rememberBooleanSettingState(luv?.local_user?.show_bot_accounts ?: false) - val botAccount = rememberBooleanSettingState(luv?.person?.bot_account ?: false) - val showReadPosts = rememberBooleanSettingState(luv?.local_user?.show_read_posts ?: false) - val sendNotificationsToEmail = - rememberBooleanSettingState(luv?.local_user?.send_notifications_to_email ?: false) - val curr2FAEnabled = luv?.local_user?.totp_2fa_enabled ?: false - val enable2FA = rememberBooleanSettingState(curr2FAEnabled) - val sortTypeNames = remember { supportedSortTypes.map { ctx.getString(it.data.shortForm) } } + val defaultSortTypeState = remember { mutableStateOf(defaultSortTypeInitial) } + + val supportedListingTypes = remember { getSupportedEntries(API.version) } + val defaultListingTypeState = remember { mutableStateOf(ListingType.entries[luv?.local_user?.default_listing_type?.ordinal ?: 0]) } + + val showNsfwState = remember { mutableStateOf(luv?.local_user?.show_nsfw ?: false) } + val showAvatarsState = remember { mutableStateOf(luv?.local_user?.show_avatars ?: false) } + val showScoresState = remember { mutableStateOf(luv?.local_user?.show_scores ?: false) } + val showBotAccountState = remember { mutableStateOf(luv?.local_user?.show_bot_accounts ?: false) } + val botAccountState = remember { mutableStateOf(luv?.person?.bot_account ?: false) } + val showReadPostsState = remember { mutableStateOf(luv?.local_user?.show_read_posts ?: false) } + val sendNotificationsToEmailState = remember { mutableStateOf(luv?.local_user?.send_notifications_to_email ?: false) } siteViewModel.saveUserSettings = SaveUserSettings( @@ -161,16 +159,16 @@ fun SettingsForm( banner = banner, matrix_user_id = matrixUserId, interface_language = interfaceLang, - bot_account = botAccount.value, - default_sort_type = supportedSortTypes[defaultSortType.value], - send_notifications_to_email = sendNotificationsToEmail.value, - show_avatars = showAvatars.value, - show_bot_accounts = showBotAccount.value, - show_nsfw = showNsfw.value, - default_listing_type = ListingType.entries[defaultListingType.value], - show_read_posts = showReadPosts.value, + bot_account = botAccountState.value, + default_sort_type = supportedSortTypes[defaultSortTypeState.value.ordinal], + send_notifications_to_email = sendNotificationsToEmailState.value, + show_avatars = showAvatarsState.value, + show_bot_accounts = showBotAccountState.value, + show_nsfw = showNsfwState.value, + default_listing_type = supportedListingTypes[defaultListingTypeState.value.ordinal], + show_read_posts = showReadPostsState.value, theme = theme, - show_scores = showScores.value, + show_scores = showScoresState.value, discussion_languages = null, ) var isUploadingAvatar by rememberSaveable { mutableStateOf(false) } @@ -255,97 +253,77 @@ fun SettingsForm( ) } } - SettingsListDropdown( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = defaultListingType, - title = { Text(text = stringResource(R.string.account_settings_default_listing_type)) }, - items = - listOf( - stringResource(R.string.account_settings_all), - stringResource(R.string.account_settings_local), - stringResource(R.string.account_settings_subscribed), - ), - ) - SettingsListDropdown( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = defaultSortType, - title = { Text(text = stringResource(R.string.account_settings_default_sort_type)) }, - items = sortTypeNames, - ) + ProvidePreferenceTheme { + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + state = defaultListingTypeState, + values = supportedListingTypes, + valueToText = { + AnnotatedString(getLocalizedListingTypeName(ctx, it)) + }, + title = { Text(text = stringResource(R.string.account_settings_default_listing_type)) }, + summary = { + Text(getLocalizedListingTypeName(ctx, defaultListingTypeState.value)) + }, + ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showNsfw, - title = { - Text(text = stringResource(R.string.account_settings_show_nsfw)) - }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showAvatars, - title = { - Text(text = stringResource(R.string.account_settings_show_avatars)) - }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showReadPosts, - title = { - Text(text = stringResource(R.string.account_settings_show_read_posts)) - }, - ) + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + state = defaultSortTypeState, + values = supportedSortTypes, + valueToText = { + AnnotatedString(ctx.getString(it.data.longForm)) + }, + title = { Text(text = stringResource(R.string.account_settings_default_sort_type)) }, + summary = { + Text(ctx.getString(defaultSortTypeState.value.data.longForm)) + }, + ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = botAccount, - title = { - Text(text = stringResource(R.string.account_settings_bot_account)) - }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showBotAccount, - title = { - Text(text = stringResource(R.string.account_settings_show_bot_accounts)) - }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showScores, - title = { - Text(text = stringResource(R.string.account_settings_show_scores)) - }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - enabled = email.isNotEmpty(), - state = sendNotificationsToEmail, - title = { - Text(text = stringResource(R.string.account_settings_send_notifications_to_email)) - }, - ) - // TODO -// SettingsCheckbox( -// title = { -// Text(text = stringResource(R.string.settings_enable_2fa)) -// }, -// state = enable2FA, -// ) -// -// if (curr2FAEnabled) { -// Row( -// horizontalArrangement = Arrangement.Center, -// modifier = Modifier.fillMaxWidth(), -// ) { -// OutlinedButton( -// onClick = { -// val intent = Intent(Intent.ACTION_VIEW, Uri.parse(luv!!.local_user.totp_2fa_url)) -// ctx.startActivitySafe(intent) -// }, -// ) { -// Text(stringResource(R.string.settings_2fa_link)) -// } -// } -// } + SwitchPreference( + state = showNsfwState, + title = { + Text(text = stringResource(R.string.account_settings_show_nsfw)) + }, + ) + SwitchPreference( + state = showAvatarsState, + title = { + Text(text = stringResource(R.string.account_settings_show_avatars)) + }, + ) + SwitchPreference( + state = showReadPostsState, + title = { + Text(text = stringResource(R.string.account_settings_show_read_posts)) + }, + ) + SwitchPreference( + state = botAccountState, + title = { + Text(text = stringResource(R.string.account_settings_bot_account)) + }, + ) + SwitchPreference( + state = showBotAccountState, + title = { + Text(text = stringResource(R.string.account_settings_show_bot_accounts)) + }, + ) + SwitchPreference( + state = showScoresState, + title = { + Text(text = stringResource(R.string.account_settings_show_scores)) + }, + ) + + SwitchPreference( + enabled = email.isNotEmpty(), + state = sendNotificationsToEmailState, + title = { + Text(text = stringResource(R.string.account_settings_send_notifications_to_email)) + }, + ) + } } } diff --git a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt index 17b78e985..43f6b9b04 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt @@ -3,7 +3,6 @@ package com.jerboa.ui.components.settings.lookandfeel import android.util.Log import androidx.appcompat.app.AppCompatDelegate import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -23,19 +22,16 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp +import androidx.compose.ui.text.AnnotatedString import androidx.core.os.LocaleListCompat -import com.alorma.compose.settings.storage.base.rememberBooleanSettingState -import com.alorma.compose.settings.storage.base.rememberFloatSettingState -import com.alorma.compose.settings.storage.base.rememberIntSettingState -import com.alorma.compose.settings.ui.SettingsCheckbox -import com.alorma.compose.settings.ui.SettingsList -import com.alorma.compose.settings.ui.SettingsListDropdown -import com.alorma.compose.settings.ui.SettingsSlider import com.jerboa.PostViewMode import com.jerboa.R import com.jerboa.ThemeColor @@ -52,7 +48,11 @@ import com.jerboa.matchLocale import com.jerboa.model.AppSettingsViewModel import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.SimpleTopAppBar -import com.jerboa.ui.theme.SETTINGS_MENU_LINK_HEIGHT +import me.zhanghai.compose.preference.ListPreference +import me.zhanghai.compose.preference.ListPreferenceType +import me.zhanghai.compose.preference.ProvidePreferenceTheme +import me.zhanghai.compose.preference.SliderPreference +import me.zhanghai.compose.preference.SwitchPreference @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -64,8 +64,9 @@ fun LookAndFeelActivity( val ctx = LocalContext.current val settings = appSettingsViewModel.appSettings.value ?: APP_SETTINGS_DEFAULT - val themeState = rememberIntSettingState(settings.theme) - val themeColorState = rememberIntSettingState(settings.themeColor) + + var themeState by remember { mutableStateOf(ThemeMode.entries[settings.theme]) } + var themeColorState by remember { mutableStateOf(ThemeColor.entries[settings.themeColor]) } val localeMap = remember { @@ -73,72 +74,60 @@ fun LookAndFeelActivity( } val currentAppLocale = matchLocale(localeMap) - val langState = rememberIntSettingState(localeMap.keys.indexOf(currentAppLocale)) - - val fontSizeState = - rememberFloatSettingState( - settings.fontSize.toFloat(), - ) - val postViewModeState = rememberIntSettingState(settings.postViewMode) - val postNavigationGestureModeState = rememberIntSettingState(settings.postNavigationGestureMode) - val showBottomNavState = rememberBooleanSettingState(settings.showBottomNav) - val showTextDescriptionsInNavbar = rememberBooleanSettingState(settings.showTextDescriptionsInNavbar) - val showCollapsedCommentContentState = rememberBooleanSettingState(settings.showCollapsedCommentContent) - val showCommentActionBarByDefaultState = rememberBooleanSettingState(settings.showCommentActionBarByDefault) - val showVotingArrowsInListViewState = rememberBooleanSettingState(settings.showVotingArrowsInListView) - val showParentCommentNavigationButtonsState = - rememberBooleanSettingState( - settings.showParentCommentNavigationButtons, - ) - val navigateParentCommentsWithVolumeButtonsState = - rememberBooleanSettingState( - settings.navigateParentCommentsWithVolumeButtons, - ) - val useCustomTabsState = rememberBooleanSettingState(settings.useCustomTabs) - val usePrivateTabsState = rememberBooleanSettingState(settings.usePrivateTabs) + var fontSizeState by remember { mutableFloatStateOf(settings.fontSize.toFloat()) } + var fontSizeSliderState by remember { mutableFloatStateOf(fontSizeState) } + var postViewModeState by remember { mutableStateOf(PostViewMode.entries[settings.postViewMode]) } + var postNavigationGestureModeState by remember { mutableStateOf(PostNavigationGestureMode.entries[settings.postNavigationGestureMode]) } + var backConfirmationModeState by remember { mutableStateOf(BackConfirmationMode.entries[settings.backConfirmationMode]) } + var postActionBarModeState by remember { mutableStateOf(PostActionBarMode.entries[settings.postActionBarMode]) } + var blurNsfwState by remember { mutableStateOf(BlurNSFW.entries[settings.blurNSFW]) } + var swipeToActionPresetState by remember { mutableStateOf(SwipeToActionPreset.entries[settings.swipeToActionPreset]) } - val secureWindowState = rememberBooleanSettingState(settings.secureWindow) - val blurNSFW = rememberIntSettingState(settings.blurNSFW) - val backConfirmationMode = rememberIntSettingState(settings.backConfirmationMode) - val showPostLinkPreviewMode = rememberBooleanSettingState(settings.showPostLinkPreviews) - val postActionBarMode = rememberIntSettingState(settings.postActionBarMode) + var showBottomNavState by remember { mutableStateOf(settings.showBottomNav) } + var showTextDescriptionsInNavbarState by remember { mutableStateOf(settings.showTextDescriptionsInNavbar) } + var showCollapsedCommentContentState by remember { mutableStateOf(settings.showCollapsedCommentContent) } + var showCommentActionBarByDefaultState by remember { mutableStateOf(settings.showCommentActionBarByDefault) } + var showVotingArrowsInListViewState by remember { mutableStateOf(settings.showVotingArrowsInListView) } + var showParentCommentNavigationButtonsState by remember { mutableStateOf(settings.showParentCommentNavigationButtons) } + var navigateParentCommentsWithVolumeButtonsState by remember { mutableStateOf(settings.navigateParentCommentsWithVolumeButtons) } + var useCustomTabsState by remember { mutableStateOf(settings.useCustomTabs) } + var usePrivateTabsState by remember { mutableStateOf(settings.usePrivateTabs) } + var secureWindowState by remember { mutableStateOf(settings.secureWindow) } + var showPostLinkPreviewModeState by remember { mutableStateOf(settings.showPostLinkPreviews) } + var markAsReadOnScrollState by remember { mutableStateOf(settings.markAsReadOnScroll) } + var autoPlayGifsState by remember { mutableStateOf(settings.autoPlayGifs) } val snackbarHostState = remember { SnackbarHostState() } val scrollState = rememberScrollState() - val markAsReadOnScroll = rememberBooleanSettingState(settings.markAsReadOnScroll) - val autoPlayGifs = rememberBooleanSettingState(settings.autoPlayGifs) - - val swipeToActionPreset = rememberIntSettingState(settings.swipeToActionPreset) - fun updateAppSettings() { appSettingsViewModel.update( AppSettings( id = 1, lastVersionCodeViewed = settings.lastVersionCodeViewed, - theme = themeState.value, - themeColor = themeColorState.value, - fontSize = fontSizeState.value.toInt(), - postViewMode = postViewModeState.value, - showBottomNav = showBottomNavState.value, - showCollapsedCommentContent = showCollapsedCommentContentState.value, - showCommentActionBarByDefault = showCommentActionBarByDefaultState.value, - showVotingArrowsInListView = showVotingArrowsInListViewState.value, - showParentCommentNavigationButtons = showParentCommentNavigationButtonsState.value, - navigateParentCommentsWithVolumeButtons = navigateParentCommentsWithVolumeButtonsState.value, - useCustomTabs = useCustomTabsState.value, - usePrivateTabs = usePrivateTabsState.value, - secureWindow = secureWindowState.value, - showTextDescriptionsInNavbar = showTextDescriptionsInNavbar.value, - blurNSFW = blurNSFW.value, - backConfirmationMode = backConfirmationMode.value, - showPostLinkPreviews = showPostLinkPreviewMode.value, - markAsReadOnScroll = markAsReadOnScroll.value, - postActionBarMode = postActionBarMode.value, - autoPlayGifs = autoPlayGifs.value, - postNavigationGestureMode = postNavigationGestureModeState.value, - swipeToActionPreset = swipeToActionPreset.value, + theme = themeState.ordinal, + themeColor = themeColorState.ordinal, + fontSize = fontSizeState.toInt(), + postViewMode = postViewModeState.ordinal, + showBottomNav = showBottomNavState, + showCollapsedCommentContent = showCollapsedCommentContentState, + showCommentActionBarByDefault = showCommentActionBarByDefaultState, + showVotingArrowsInListView = showVotingArrowsInListViewState, + showParentCommentNavigationButtons = showParentCommentNavigationButtonsState, + navigateParentCommentsWithVolumeButtons = navigateParentCommentsWithVolumeButtonsState, + useCustomTabs = useCustomTabsState, + usePrivateTabs = usePrivateTabsState, + secureWindow = secureWindowState, + showTextDescriptionsInNavbar = showTextDescriptionsInNavbarState, + blurNSFW = blurNsfwState.ordinal, + backConfirmationMode = backConfirmationModeState.ordinal, + showPostLinkPreviews = showPostLinkPreviewModeState, + markAsReadOnScroll = markAsReadOnScrollState, + postActionBarMode = postActionBarModeState.ordinal, + autoPlayGifs = autoPlayGifsState, + postNavigationGestureMode = postNavigationGestureModeState.ordinal, + swipeToActionPreset = swipeToActionPresetState.ordinal, ), ) } @@ -155,285 +144,384 @@ fun LookAndFeelActivity( .verticalScroll(scrollState) .padding(padding), ) { - SettingsListDropdown( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { - Text(text = stringResource(R.string.lang_language)) - }, - icon = { - Icon( - imageVector = Icons.Outlined.Language, - contentDescription = stringResource(R.string.lang_language), - ) - }, - state = langState, - items = localeMap.values.toList(), - onItemSelected = { i, _ -> - AppCompatDelegate.setApplicationLocales( - LocaleListCompat.create(localeMap.keys.elementAt(i)), - ) - }, - ) - SettingsSlider( - modifier = Modifier.padding(top = 10.dp).height(SETTINGS_MENU_LINK_HEIGHT), - valueRange = 8f..48f, - state = fontSizeState, - icon = { - Icon( - imageVector = Icons.Outlined.FormatSize, - contentDescription = null, - ) - }, - title = { - Text( - text = - stringResource( - R.string.look_and_feel_font_size, - fontSizeState.value.toInt(), - ), - ) - }, - onValueChangeFinished = { updateAppSettings() }, - ) - SettingsList( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = themeState, - items = ThemeMode.entries.map { stringResource(it.mode) }, - icon = { - Icon( - imageVector = Icons.Outlined.Palette, - contentDescription = null, - ) - }, - title = { - Text(text = stringResource(R.string.look_and_feel_theme)) - }, - onItemSelected = { i, _ -> - themeState.value = i - updateAppSettings() - }, - ) - SettingsList( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = themeColorState, - items = ThemeColor.entries.map { stringResource(it.mode) }, - icon = { - Icon( - imageVector = Icons.Outlined.Colorize, - contentDescription = null, - ) - }, - title = { - Text(text = stringResource(R.string.look_and_feel_theme_color)) - }, - onItemSelected = { i, _ -> - themeColorState.value = i - updateAppSettings() - }, - ) - SettingsList( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = postViewModeState, - items = PostViewMode.entries.map { stringResource(it.mode) }, - icon = { - Icon( - imageVector = Icons.AutoMirrored.Outlined.ViewList, - contentDescription = null, - ) - }, - title = { - Text(text = stringResource(R.string.look_and_feel_post_view)) - }, - onItemSelected = { i, _ -> - postViewModeState.value = i - updateAppSettings() - }, - ) - SettingsList( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = postNavigationGestureModeState, - items = PostNavigationGestureMode.entries.map { stringResource(it.mode) }, - icon = { - Icon( - imageVector = Icons.Outlined.Swipe, - contentDescription = null, - ) - }, - title = { - Text(text = stringResource(R.string.look_and_feel_post_navigation_gesture_mode)) - }, - onItemSelected = { i, _ -> - postNavigationGestureModeState.value = i - updateAppSettings() - }, - ) - SettingsList( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { - Text(text = stringResource(R.string.confirm_exit)) - }, - state = backConfirmationMode, - items = BackConfirmationMode.entries.map { stringResource(it.resId) }, - onItemSelected = { i, _ -> - backConfirmationMode.value = i - updateAppSettings() - }, - icon = { - Icon( - imageVector = Icons.AutoMirrored.Outlined.ExitToApp, - contentDescription = null, - ) - }, - ) - SettingsList( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - title = { - Text(text = stringResource(R.string.post_actionbar)) - }, - state = postActionBarMode, - items = PostActionBarMode.entries.map { stringResource(it.resId) }, - onItemSelected = { i, _ -> - postActionBarMode.value = i - updateAppSettings() - }, - icon = { - Icon( - imageVector = Icons.Outlined.Forum, - contentDescription = null, - ) - }, - ) - SettingsListDropdown( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = blurNSFW, - icon = { - Icon( - imageVector = Icons.Outlined.LensBlur, - contentDescription = null, - ) - }, - title = { Text(stringResource(id = R.string.blur_nsfw)) }, - items = BlurNSFW.entries.map { stringResource(it.resId) }, - onItemSelected = { _, _ -> updateAppSettings() }, - ) - SettingsListDropdown( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = swipeToActionPreset, - icon = { - Icon( - imageVector = Icons.Outlined.Swipe, - contentDescription = null, - ) - }, - title = { Text(stringResource(id = R.string.swipe_to_action_presets)) }, - items = SwipeToActionPreset.entries.map { stringResource(it.resId) }, - onItemSelected = { _, _ -> updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showBottomNavState, - title = { - Text(text = stringResource(R.string.look_and_feel_show_navigation_bar)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showTextDescriptionsInNavbar, - title = { - Text(text = stringResource(R.string.look_and_feel_show_text_descriptions_in_navbar)) - }, - onCheckedChange = { updateAppSettings() }, - enabled = showBottomNavState.value, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showCollapsedCommentContentState, - title = { - Text(text = stringResource(R.string.look_and_feel_activity_show_content_for_collapsed_comments)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showCommentActionBarByDefaultState, - title = { - Text(text = stringResource(R.string.look_and_feel_show_action_bar_for_comments)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showVotingArrowsInListViewState, - title = { - Text(text = stringResource(R.string.look_and_feel_show_voting_arrows_list_view)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showParentCommentNavigationButtonsState, - title = { - Text(text = stringResource(R.string.look_and_feel_show_parent_comment_navigation_buttons)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = navigateParentCommentsWithVolumeButtonsState, - title = { - Text(text = stringResource(R.string.look_and_feel_navigate_parent_comments_with_volume_buttons)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = useCustomTabsState, - title = { - Text(text = stringResource(id = R.string.look_and_feel_use_custom_tabs)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = usePrivateTabsState, - title = { - Text(text = stringResource(id = R.string.look_and_feel_use_private_tabs)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = secureWindowState, - title = { - Text(text = stringResource(R.string.look_and_feel_secure_window)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = showPostLinkPreviewMode, - title = { - Text(stringResource(id = R.string.show_post_link_previews)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = markAsReadOnScroll, - title = { - Text(stringResource(id = R.string.mark_as_read_on_scroll)) - }, - onCheckedChange = { updateAppSettings() }, - ) - SettingsCheckbox( - modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT), - state = autoPlayGifs, - title = { - Text(stringResource(id = R.string.settings_autoplaygifs)) - }, - onCheckedChange = { updateAppSettings() }, - ) + ProvidePreferenceTheme { + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = currentAppLocale.displayName, + onValueChange = { name -> + val entry = localeMap.entries.find { it.value == name } + AppCompatDelegate.setApplicationLocales( + LocaleListCompat.create(entry?.key), + ) + }, + values = localeMap.values.toList(), + title = { + Text(text = stringResource(R.string.lang_language)) + }, + summary = { Text(currentAppLocale.displayName) }, + icon = { + Icon( + imageVector = Icons.Outlined.Language, + contentDescription = stringResource(R.string.lang_language), + ) + }, + ) + + SliderPreference( + value = fontSizeState, + sliderValue = fontSizeSliderState, + onValueChange = { + fontSizeState = it + updateAppSettings() + }, + onSliderValueChange = { fontSizeSliderState = it }, + valueRange = 8f..48f, + icon = { + Icon( + imageVector = Icons.Outlined.FormatSize, + contentDescription = null, + ) + }, + title = { + Text( + text = + stringResource( + R.string.look_and_feel_font_size, + fontSizeSliderState.toInt(), + ), + ) + }, + ) + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = themeState, + onValueChange = { + themeState = it + updateAppSettings() + }, + values = ThemeMode.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + icon = { + Icon( + imageVector = Icons.Outlined.Palette, + contentDescription = null, + ) + }, + title = { + Text(text = stringResource(R.string.look_and_feel_theme)) + }, + summary = { + Text(stringResource(themeState.resId)) + }, + ) + + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = themeColorState, + onValueChange = { + themeColorState = it + updateAppSettings() + }, + values = ThemeColor.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + icon = { + Icon( + imageVector = Icons.Outlined.Colorize, + contentDescription = null, + ) + }, + title = { + Text(text = stringResource(R.string.look_and_feel_theme_color)) + }, + summary = { + Text(stringResource(themeColorState.resId)) + }, + ) + + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = postViewModeState, + onValueChange = { + postViewModeState = it + updateAppSettings() + }, + values = PostViewMode.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + icon = { + Icon( + imageVector = Icons.AutoMirrored.Outlined.ViewList, + contentDescription = null, + ) + }, + title = { + Text(text = stringResource(R.string.look_and_feel_post_view)) + }, + summary = { + Text(stringResource(postViewModeState.resId)) + }, + ) + + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = postNavigationGestureModeState, + onValueChange = { + postNavigationGestureModeState = it + updateAppSettings() + }, + values = PostNavigationGestureMode.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + icon = { + Icon( + imageVector = Icons.Outlined.Swipe, + contentDescription = null, + ) + }, + title = { + Text(text = stringResource(R.string.look_and_feel_post_navigation_gesture_mode)) + }, + summary = { + Text(stringResource(postNavigationGestureModeState.resId)) + }, + ) + + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = backConfirmationModeState, + onValueChange = { + backConfirmationModeState = it + updateAppSettings() + }, + values = BackConfirmationMode.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + icon = { + Icon( + imageVector = Icons.AutoMirrored.Outlined.ExitToApp, + contentDescription = null, + ) + }, + title = { + Text(text = stringResource(R.string.confirm_exit)) + }, + summary = { + Text(stringResource(backConfirmationModeState.resId)) + }, + ) + + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = postActionBarModeState, + onValueChange = { + postActionBarModeState = it + updateAppSettings() + }, + values = PostActionBarMode.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + title = { + Text(text = stringResource(R.string.post_actionbar)) + }, + icon = { + Icon( + imageVector = Icons.Outlined.Forum, + contentDescription = null, + ) + }, + summary = { + Text(stringResource(postActionBarModeState.resId)) + }, + ) + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = blurNsfwState, + onValueChange = { + blurNsfwState = it + updateAppSettings() + }, + values = BlurNSFW.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + title = { Text(stringResource(id = R.string.blur_nsfw)) }, + icon = { + Icon( + imageVector = Icons.Outlined.LensBlur, + contentDescription = null, + ) + }, + summary = { + Text(stringResource(blurNsfwState.resId)) + }, + ) + + ListPreference( + type = ListPreferenceType.DROPDOWN_MENU, + value = swipeToActionPresetState, + onValueChange = { + swipeToActionPresetState = it + updateAppSettings() + }, + values = SwipeToActionPreset.entries, + valueToText = { + AnnotatedString(ctx.getString(it.resId)) + }, + title = { Text(stringResource(id = R.string.swipe_to_action_presets)) }, + icon = { + Icon( + imageVector = Icons.Outlined.Swipe, + contentDescription = null, + ) + }, + summary = { + Text(stringResource(swipeToActionPresetState.resId)) + }, + ) + SwitchPreference( + value = showBottomNavState, + onValueChange = { + showBottomNavState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_show_navigation_bar)) + }, + ) + + SwitchPreference( + enabled = showBottomNavState, + value = showTextDescriptionsInNavbarState, + onValueChange = { + showTextDescriptionsInNavbarState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_show_text_descriptions_in_navbar)) + }, + ) + + SwitchPreference( + value = showCollapsedCommentContentState, + onValueChange = { + showCollapsedCommentContentState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_activity_show_content_for_collapsed_comments)) + }, + ) + + SwitchPreference( + value = showCommentActionBarByDefaultState, + onValueChange = { + showCommentActionBarByDefaultState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_show_action_bar_for_comments)) + }, + ) + + SwitchPreference( + value = showVotingArrowsInListViewState, + onValueChange = { + showVotingArrowsInListViewState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_show_voting_arrows_list_view)) + }, + ) + SwitchPreference( + value = showParentCommentNavigationButtonsState, + onValueChange = { + showParentCommentNavigationButtonsState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_show_parent_comment_navigation_buttons)) + }, + ) + SwitchPreference( + value = navigateParentCommentsWithVolumeButtonsState, + onValueChange = { + navigateParentCommentsWithVolumeButtonsState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_navigate_parent_comments_with_volume_buttons)) + }, + ) + SwitchPreference( + value = useCustomTabsState, + onValueChange = { + useCustomTabsState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(id = R.string.look_and_feel_use_custom_tabs)) + }, + ) + SwitchPreference( + value = usePrivateTabsState, + onValueChange = { + usePrivateTabsState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(id = R.string.look_and_feel_use_private_tabs)) + }, + ) + SwitchPreference( + value = secureWindowState, + onValueChange = { + secureWindowState = it + updateAppSettings() + }, + title = { + Text(text = stringResource(R.string.look_and_feel_secure_window)) + }, + ) + SwitchPreference( + value = showPostLinkPreviewModeState, + onValueChange = { + showPostLinkPreviewModeState = it + updateAppSettings() + }, + title = { + Text(stringResource(id = R.string.show_post_link_previews)) + }, + ) + SwitchPreference( + value = markAsReadOnScrollState, + onValueChange = { + markAsReadOnScrollState = it + updateAppSettings() + }, + title = { + Text(stringResource(id = R.string.mark_as_read_on_scroll)) + }, + ) + SwitchPreference( + value = autoPlayGifsState, + onValueChange = { + autoPlayGifsState = it + updateAppSettings() + }, + title = { + Text(stringResource(id = R.string.settings_autoplaygifs)) + }, + ) + } } }, ) diff --git a/app/src/main/java/com/jerboa/ui/theme/Sizes.kt b/app/src/main/java/com/jerboa/ui/theme/Sizes.kt index c1b06ec14..10c8bbaa9 100644 --- a/app/src/main/java/com/jerboa/ui/theme/Sizes.kt +++ b/app/src/main/java/com/jerboa/ui/theme/Sizes.kt @@ -27,10 +27,6 @@ val THUMBNAIL_CARET_SIZE = 10.dp val DRAWER_ITEM_SPACING = 24.dp -// TODO this needs to be removed when Intrinsic height min is fixed -// See https://github.com/alorma/Compose-Settings/issues/203 -val SETTINGS_MENU_LINK_HEIGHT = 88.dp - // TODO remove all DPs from code, put here. const val ICON_THUMBNAIL_SIZE = 96 const val LARGER_ICON_THUMBNAIL_SIZE = 256 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3bc599a14..f4e303fcc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -274,8 +274,10 @@ Active Hot MostComments + Most Comments New NewComments + New Comments Old Controversial Scaled