mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
add option for 2 profile gallery views
This commit is contained in:
parent
7b84c81d9c
commit
e9861d80f6
@ -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,
|
||||
|
@ -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<Boolean>(false)
|
||||
var dontAskForNotificationPermissions by mutableStateOf<Boolean>(false)
|
||||
var featureSet by mutableStateOf(FeatureSetType.SIMPLIFIED)
|
||||
var gallerySet by mutableStateOf(ProfileGalleryType.CLASSIC)
|
||||
|
||||
var isOnMobileData: State<Boolean> = 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,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<MediaUrlContent>,
|
||||
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<MediaUrlContent>,
|
||||
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) {
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -634,6 +634,9 @@
|
||||
<string name="ui_feature_set_type_simplified">Simplified</string>
|
||||
<string name="ui_feature_set_type_performance">Performance</string>
|
||||
|
||||
<string name="gallery_type_classic">Classic</string>
|
||||
<string name="gallery_type_modern">Modern</string>
|
||||
|
||||
<string name="system">System</string>
|
||||
<string name="light">Light</string>
|
||||
<string name="dark">Dark</string>
|
||||
@ -650,6 +653,9 @@
|
||||
<string name="ui_style">UI Mode</string>
|
||||
<string name="ui_style_description">Choose the post style</string>
|
||||
|
||||
<string name="gallery_style">Profile Gallery Style</string>
|
||||
<string name="gallery_style_description">Choose the gallery style</string>
|
||||
|
||||
<string name="load_image">Load Image</string>
|
||||
|
||||
<string name="spamming_users">Spammers</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user