From e5d4b2a1454277ccb86c03330abec08804e7e419 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 12 Mar 2024 15:50:15 -0400 Subject: [PATCH] Adds a simplified version to the UI. --- .../vitorpamplona/amethyst/model/Settings.kt | 16 ++++++++++++++ .../amethyst/ui/note/NoteCompose.kt | 17 +++++++------- .../ui/screen/SharedPreferencesViewModel.kt | 14 ++++++++++-- .../ui/screen/loggedIn/SettingsScreen.kt | 22 +++++++++++++++++++ app/src/main/res/values/strings.xml | 7 ++++++ 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt index 3da6deae5..3d5993718 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt @@ -34,6 +34,7 @@ data class Settings( val automaticallyShowProfilePictures: ConnectivityType = ConnectivityType.ALWAYS, val dontShowPushNotificationSelector: Boolean = false, val dontAskForNotificationPermissions: Boolean = false, + val featureSet: FeatureSetType = FeatureSetType.COMPLETE, ) enum class ThemeType(val screenCode: Int, val resourceId: Int) { @@ -59,6 +60,11 @@ enum class ConnectivityType(val prefCode: Boolean?, val screenCode: Int, val res NEVER(false, 2, R.string.connectivity_type_never), } +enum class FeatureSetType(val screenCode: Int, val resourceId: Int) { + COMPLETE(0, R.string.ui_feature_set_type_complete), + SIMPLIFIED(1, R.string.ui_feature_set_type_simplified), +} + fun parseConnectivityType(code: Boolean?): ConnectivityType { return when (code) { ConnectivityType.ALWAYS.prefCode -> ConnectivityType.ALWAYS @@ -81,6 +87,16 @@ fun parseConnectivityType(screenCode: Int): ConnectivityType { } } +fun parseFeatureSetType(screenCode: Int): FeatureSetType { + return when (screenCode) { + FeatureSetType.COMPLETE.screenCode -> FeatureSetType.COMPLETE + FeatureSetType.SIMPLIFIED.screenCode -> FeatureSetType.SIMPLIFIED + else -> { + FeatureSetType.COMPLETE + } + } +} + enum class BooleanType(val prefCode: Boolean?, val screenCode: Int, val reourceId: Int) { ALWAYS(null, 0, R.string.connectivity_type_always), NEVER(false, 1, R.string.connectivity_type_never), diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index 679cd84b1..24b0553ac 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -58,6 +58,7 @@ import androidx.lifecycle.map import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.AddressableNote import com.vitorpamplona.amethyst.model.Channel +import com.vitorpamplona.amethyst.model.FeatureSetType import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.ui.components.GenericLoadable import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status @@ -665,10 +666,8 @@ fun InnerNoteWithReactions( Column(Modifier.fillMaxWidth()) { val showSecondRow = - baseNote.event !is RepostEvent && - baseNote.event !is GenericRepostEvent && - !isBoostedNote && - !isQuotedNote + baseNote.event !is RepostEvent && baseNote.event !is GenericRepostEvent && + !isBoostedNote && !isQuotedNote && accountViewModel.settings.featureSet != FeatureSetType.SIMPLIFIED NoteBody( baseNote = baseNote, showAuthorPicture = isQuotedNote, @@ -1234,10 +1233,12 @@ private fun BadgeBox( accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { - if (baseNote.event is RepostEvent || baseNote.event is GenericRepostEvent) { - baseNote.replyTo?.lastOrNull()?.let { RelayBadges(it, accountViewModel, nav) } - } else { - RelayBadges(baseNote, accountViewModel, nav) + if (accountViewModel.settings.featureSet != FeatureSetType.SIMPLIFIED) { + if (baseNote.event is RepostEvent || baseNote.event is GenericRepostEvent) { + baseNote.replyTo?.lastOrNull()?.let { RelayBadges(it, accountViewModel, nav) } + } else { + RelayBadges(baseNote, accountViewModel, nav) + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt index 29ce5e5d4..cf5796ba5 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt @@ -35,6 +35,7 @@ import androidx.window.layout.DisplayFeature import com.vitorpamplona.amethyst.LocalPreferences import com.vitorpamplona.amethyst.model.BooleanType import com.vitorpamplona.amethyst.model.ConnectivityType +import com.vitorpamplona.amethyst.model.FeatureSetType import com.vitorpamplona.amethyst.model.Settings import com.vitorpamplona.amethyst.model.ThemeType import kotlinx.coroutines.Dispatchers @@ -52,6 +53,7 @@ class SettingsState() { var automaticallyShowProfilePictures by mutableStateOf(ConnectivityType.ALWAYS) var dontShowPushNotificationSelector by mutableStateOf(false) var dontAskForNotificationPermissions by mutableStateOf(false) + var featureSet by mutableStateOf(FeatureSetType.COMPLETE) var isOnMobileData: State = mutableStateOf(false) @@ -113,8 +115,8 @@ class SharedPreferencesViewModel : ViewModel() { sharedPrefs.automaticallyHideNavigationBars = savedSettings.automaticallyHideNavigationBars sharedPrefs.automaticallyShowProfilePictures = savedSettings.automaticallyShowProfilePictures sharedPrefs.dontShowPushNotificationSelector = savedSettings.dontShowPushNotificationSelector - sharedPrefs.dontAskForNotificationPermissions = - savedSettings.dontAskForNotificationPermissions + sharedPrefs.dontAskForNotificationPermissions = savedSettings.dontAskForNotificationPermissions + sharedPrefs.featureSet = savedSettings.featureSet updateLanguageInTheUI() } @@ -181,6 +183,13 @@ class SharedPreferencesViewModel : ViewModel() { } } + fun updateFeatureSetType(newFeatureSetType: FeatureSetType) { + if (sharedPrefs.featureSet != newFeatureSetType) { + sharedPrefs.featureSet = newFeatureSetType + saveSharedSettings() + } + } + fun dontShowPushNotificationSelector() { if (sharedPrefs.dontShowPushNotificationSelector == false) { sharedPrefs.dontShowPushNotificationSelector = true @@ -226,6 +235,7 @@ class SharedPreferencesViewModel : ViewModel() { sharedPrefs.automaticallyShowProfilePictures, sharedPrefs.dontShowPushNotificationSelector, sharedPrefs.dontAskForNotificationPermissions, + sharedPrefs.featureSet, ), ) } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SettingsScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SettingsScreen.kt index fbc8e0db7..aeb9f87f8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SettingsScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/SettingsScreen.kt @@ -47,9 +47,11 @@ import androidx.compose.ui.unit.dp import androidx.core.os.LocaleListCompat import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.ConnectivityType +import com.vitorpamplona.amethyst.model.FeatureSetType import com.vitorpamplona.amethyst.model.ThemeType import com.vitorpamplona.amethyst.model.parseBooleanType import com.vitorpamplona.amethyst.model.parseConnectivityType +import com.vitorpamplona.amethyst.model.parseFeatureSetType import com.vitorpamplona.amethyst.model.parseThemeType import com.vitorpamplona.amethyst.ui.components.PushNotificationSettingsRow import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel @@ -141,6 +143,12 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { TitleExplainer(stringResource(ConnectivityType.NEVER.resourceId)), ) + val featureItems = + persistentListOf( + TitleExplainer(stringResource(FeatureSetType.COMPLETE.resourceId)), + TitleExplainer(stringResource(FeatureSetType.SIMPLIFIED.resourceId)), + ) + val showImagesIndex = sharedPreferencesViewModel.sharedPrefs.automaticallyShowImages.screenCode val videoIndex = sharedPreferencesViewModel.sharedPrefs.automaticallyStartPlayback.screenCode val linkIndex = sharedPreferencesViewModel.sharedPrefs.automaticallyShowUrlPreview.screenCode @@ -156,6 +164,9 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { val languageList = remember { languageEntries.keys.map { TitleExplainer(it) }.toImmutableList() } val languageIndex = getLanguageIndex(languageEntries, sharedPreferencesViewModel) + val featureSetIndex = + sharedPreferencesViewModel.sharedPrefs.featureSet.screenCode + Column( Modifier.fillMaxSize() .padding(top = Size10dp, start = Size20dp, end = Size20dp) @@ -237,6 +248,17 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { Spacer(modifier = HalfVertSpacer) + SettingsRow( + R.string.ui_style, + R.string.ui_style_description, + featureItems, + featureSetIndex, + ) { + sharedPreferencesViewModel.updateFeatureSetType(parseFeatureSetType(it)) + } + + Spacer(modifier = HalfVertSpacer) + PushNotificationSettingsRow(sharedPreferencesViewModel) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5963977bc..7ecca14c7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -505,6 +505,9 @@ Wifi-only Never + Complete + Simplified + System Light Dark @@ -516,6 +519,10 @@ URL Preview Immersive Scrolling Hide Nav Bars when Scrolling + + UI Mode + Choose the post style + Load Image Spammers