From e9861d80f69d7676976339ce2cf0629db0957373 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:48:26 +0100 Subject: [PATCH] add option for 2 profile gallery views --- .../vitorpamplona/amethyst/model/Settings.kt | 18 +++++++++++++++++ .../ui/screen/SharedPreferencesViewModel.kt | 19 ++++++++++++++++++ .../profile/gallery/GalleryCardCompose.kt | 7 ++++++- .../loggedIn/profile/gallery/GalleryThumb.kt | 17 ++++++++++------ .../profile/gallery/ProfileGalleryFeed.kt | 13 +++++++++++- .../loggedIn/settings/AppSettingsScreen.kt | 20 +++++++++++++++++++ amethyst/src/main/res/values/strings.xml | 6 ++++++ 7 files changed, 92 insertions(+), 8 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt index 25798635a..cc722dc75 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Settings.kt @@ -35,6 +35,7 @@ data class Settings( val dontShowPushNotificationSelector: Boolean = false, val dontAskForNotificationPermissions: Boolean = false, val featureSet: FeatureSetType = FeatureSetType.SIMPLIFIED, + val gallerySet: ProfileGalleryType = ProfileGalleryType.CLASSIC, ) enum class ThemeType( @@ -75,6 +76,14 @@ enum class FeatureSetType( PERFORMANCE(2, R.string.ui_feature_set_type_performance), } +enum class ProfileGalleryType( + val screenCode: Int, + val resourceId: Int, +) { + CLASSIC(0, R.string.gallery_type_classic), + MODERN(1, R.string.gallery_type_modern), +} + fun parseConnectivityType(code: Boolean?): ConnectivityType = when (code) { ConnectivityType.ALWAYS.prefCode -> ConnectivityType.ALWAYS @@ -105,6 +114,15 @@ fun parseFeatureSetType(screenCode: Int): FeatureSetType = } } +fun parseGalleryType(screenCode: Int): ProfileGalleryType = + when (screenCode) { + ProfileGalleryType.CLASSIC.screenCode -> ProfileGalleryType.CLASSIC + ProfileGalleryType.MODERN.screenCode -> ProfileGalleryType.MODERN + else -> { + ProfileGalleryType.CLASSIC + } + } + enum class BooleanType( val prefCode: Boolean?, val screenCode: Int, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt index 10a5f21d1..3294969b9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/SharedPreferencesViewModel.kt @@ -38,6 +38,7 @@ 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.ProfileGalleryType import com.vitorpamplona.amethyst.model.Settings import com.vitorpamplona.amethyst.model.ThemeType import kotlinx.coroutines.Dispatchers @@ -56,6 +57,7 @@ class SettingsState { var dontShowPushNotificationSelector by mutableStateOf(false) var dontAskForNotificationPermissions by mutableStateOf(false) var featureSet by mutableStateOf(FeatureSetType.SIMPLIFIED) + var gallerySet by mutableStateOf(ProfileGalleryType.CLASSIC) var isOnMobileData: State = mutableStateOf(false) @@ -71,6 +73,14 @@ class SettingsState { } } + val modernGalleryStyle = + derivedStateOf { + when (gallerySet) { + ProfileGalleryType.CLASSIC -> false + ProfileGalleryType.MODERN -> true + } + } + val showUrlPreview = derivedStateOf { when (automaticallyShowUrlPreview) { @@ -117,6 +127,7 @@ class SharedPreferencesViewModel : ViewModel() { sharedPrefs.automaticallyShowProfilePictures = savedSettings.automaticallyShowProfilePictures sharedPrefs.dontShowPushNotificationSelector = savedSettings.dontShowPushNotificationSelector sharedPrefs.dontAskForNotificationPermissions = savedSettings.dontAskForNotificationPermissions + sharedPrefs.gallerySet = savedSettings.gallerySet sharedPrefs.featureSet = savedSettings.featureSet updateLanguageInTheUI() @@ -191,6 +202,13 @@ class SharedPreferencesViewModel : ViewModel() { } } + fun updateGallerySetType(newgalleryType: ProfileGalleryType) { + if (sharedPrefs.gallerySet != newgalleryType) { + sharedPrefs.gallerySet = newgalleryType + saveSharedSettings() + } + } + fun dontShowPushNotificationSelector() { if (sharedPrefs.dontShowPushNotificationSelector == false) { sharedPrefs.dontShowPushNotificationSelector = true @@ -237,6 +255,7 @@ class SharedPreferencesViewModel : ViewModel() { sharedPrefs.dontShowPushNotificationSelector, sharedPrefs.dontAskForNotificationPermissions, sharedPrefs.featureSet, + sharedPrefs.gallerySet, ), ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryCardCompose.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryCardCompose.kt index 981fcebe5..d815efebd 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryCardCompose.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryCardCompose.kt @@ -46,6 +46,7 @@ fun GalleryCardCompose( modifier: Modifier = Modifier, accountViewModel: AccountViewModel, nav: INav, + ratio: Float = 1.0f, ) { WatchNoteEvent(baseNote = baseNote, accountViewModel = accountViewModel, shortPreview = true) { CheckHiddenFeedWatchBlockAndReport( @@ -74,6 +75,7 @@ fun GalleryCardCompose( modifier = modifier, accountViewModel = accountViewModel, nav = nav, + ratio = ratio, ) } else { RedirectableGalleryCard( @@ -82,6 +84,7 @@ fun GalleryCardCompose( modifier = modifier, accountViewModel = accountViewModel, nav = nav, + ratio = ratio, ) } } @@ -92,6 +95,7 @@ fun GalleryCardCompose( modifier = modifier, accountViewModel = accountViewModel, nav = nav, + ratio = ratio, ) } } @@ -105,6 +109,7 @@ fun RedirectableGalleryCard( modifier: Modifier = Modifier, accountViewModel: AccountViewModel, nav: INav, + ratio: Float = 1.0f, ) { QuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup -> ClickableNote( @@ -123,7 +128,7 @@ fun RedirectableGalleryCard( note = galleryNote, accountViewModel = accountViewModel, ) { - GalleryThumbnail(galleryNote, accountViewModel, nav) + GalleryThumbnail(galleryNote, accountViewModel, nav, ratio = ratio) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt index 2e01fc52e..5e27dec94 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/GalleryThumb.kt @@ -77,6 +77,7 @@ fun GalleryThumbnail( baseNote: Note, accountViewModel: AccountViewModel, nav: INav, + ratio: Float = 1.0f, ) { val noteState by baseNote.live().metadata.observeAsState() val noteEvent = noteState?.note?.event ?: return @@ -134,7 +135,7 @@ fun GalleryThumbnail( emptyList() } - InnerRenderGalleryThumb(content, baseNote, accountViewModel) + InnerRenderGalleryThumb(content, baseNote, accountViewModel, ratio) } @Composable @@ -142,9 +143,10 @@ fun InnerRenderGalleryThumb( content: List, note: Note, accountViewModel: AccountViewModel, + ratio: Float = 1.0f, ) { if (content.isNotEmpty()) { - GalleryContentView(content, accountViewModel) + GalleryContentView(content, accountViewModel, ratio = ratio) } else { DisplayGalleryAuthorBanner(note) } @@ -162,16 +164,17 @@ fun DisplayGalleryAuthorBanner(note: Note) { fun GalleryContentView( contentList: List, accountViewModel: AccountViewModel, + ratio: Float = 1.0f, ) { AutoNonlazyGrid(contentList.size) { contentIndex -> when (val content = contentList[contentIndex]) { is MediaUrlImage -> SensitivityWarning(content.contentWarning != null, accountViewModel) { - UrlImageView(content, accountViewModel) + UrlImageView(content, accountViewModel, ratio = ratio) } is MediaUrlVideo -> SensitivityWarning(content.contentWarning != null, accountViewModel) { - UrlVideoView(content, accountViewModel) + UrlVideoView(content, accountViewModel, ratio = ratio) } } } @@ -182,8 +185,9 @@ fun UrlImageView( content: MediaUrlImage, accountViewModel: AccountViewModel, alwayShowImage: Boolean = false, + ratio: Float = 1.0f, ) { - val defaultModifier = Modifier.fillMaxSize().aspectRatio(1f) + val defaultModifier = Modifier.fillMaxSize().aspectRatio(ratio) val showImage = remember { @@ -250,8 +254,9 @@ fun UrlImageView( fun UrlVideoView( content: MediaUrlVideo, accountViewModel: AccountViewModel, + ratio: Float = 1.0f, ) { - val defaultModifier = Modifier.fillMaxSize().aspectRatio(1f) + val defaultModifier = Modifier.fillMaxSize().aspectRatio(ratio) val automaticallyStartPlayback = remember(content) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/ProfileGalleryFeed.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/ProfileGalleryFeed.kt index 9cf067dba..4ab78a01a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/ProfileGalleryFeed.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/ProfileGalleryFeed.kt @@ -33,6 +33,7 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.viewmodel.compose.viewModel import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled import com.vitorpamplona.amethyst.ui.feeds.FeedEmpty import com.vitorpamplona.amethyst.ui.feeds.FeedError @@ -40,6 +41,7 @@ import com.vitorpamplona.amethyst.ui.feeds.FeedState import com.vitorpamplona.amethyst.ui.feeds.LoadingFeed import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.screen.FeedViewModel +import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.FeedPadding @@ -87,6 +89,14 @@ private fun GalleryFeedLoaded( nav: INav, ) { val items by loaded.feed.collectAsStateWithLifecycle() + val sharedPreferencesViewModel: SharedPreferencesViewModel = viewModel() + + sharedPreferencesViewModel.init() + + var ratio = 1.0f + if (sharedPreferencesViewModel.sharedPrefs.modernGalleryStyle.value) { + ratio = 0.8f + } LazyVerticalGrid( columns = GridCells.Fixed(3), @@ -100,11 +110,12 @@ private fun GalleryFeedLoaded( baseNote = item, modifier = Modifier - .aspectRatio(1f) + .aspectRatio(ratio) .fillMaxSize() .animateItem(), accountViewModel = accountViewModel, nav = nav, + ratio = ratio, ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt index 45e4e4cea..efcb0a3ed 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt @@ -48,10 +48,12 @@ 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.ProfileGalleryType 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.parseGalleryType import com.vitorpamplona.amethyst.model.parseThemeType import com.vitorpamplona.amethyst.ui.components.PushNotificationSettingsRow import com.vitorpamplona.amethyst.ui.navigation.INav @@ -187,6 +189,12 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { TitleExplainer(stringRes(FeatureSetType.PERFORMANCE.resourceId)), ) + val galleryItems = + persistentListOf( + TitleExplainer(stringRes(ProfileGalleryType.CLASSIC.resourceId)), + TitleExplainer(stringRes(ProfileGalleryType.MODERN.resourceId)), + ) + val showImagesIndex = sharedPreferencesViewModel.sharedPrefs.automaticallyShowImages.screenCode val videoIndex = sharedPreferencesViewModel.sharedPrefs.automaticallyStartPlayback.screenCode val linkIndex = sharedPreferencesViewModel.sharedPrefs.automaticallyShowUrlPreview.screenCode @@ -204,6 +212,8 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { val featureSetIndex = sharedPreferencesViewModel.sharedPrefs.featureSet.screenCode + val galleryIndex = + sharedPreferencesViewModel.sharedPrefs.gallerySet.screenCode Column( Modifier @@ -295,9 +305,19 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { ) { sharedPreferencesViewModel.updateFeatureSetType(parseFeatureSetType(it)) } + Spacer(modifier = HalfVertSpacer) Spacer(modifier = HalfVertSpacer) + SettingsRow( + R.string.gallery_style, + R.string.gallery_style_description, + galleryItems, + galleryIndex, + ) { + sharedPreferencesViewModel.updateGallerySetType(parseGalleryType(it)) + } + PushNotificationSettingsRow(sharedPreferencesViewModel) } } diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml index c779f88a8..6f14f9662 100644 --- a/amethyst/src/main/res/values/strings.xml +++ b/amethyst/src/main/res/values/strings.xml @@ -634,6 +634,9 @@ Simplified Performance + Classic + Modern + System Light Dark @@ -650,6 +653,9 @@ UI Mode Choose the post style + Profile Gallery Style + Choose the gallery style + Load Image Spammers