Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for 2 profile gallery views #1270

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -71,6 +73,14 @@ class SettingsState {
}
}

val modernGalleryStyle =
derivedStateOf {
when (gallerySet) {
ProfileGalleryType.CLASSIC -> false
ProfileGalleryType.MODERN -> true
}
}

val showUrlPreview =
derivedStateOf {
when (automaticallyShowUrlPreview) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -237,6 +255,7 @@ class SharedPreferencesViewModel : ViewModel() {
sharedPrefs.dontShowPushNotificationSelector,
sharedPrefs.dontAskForNotificationPermissions,
sharedPrefs.featureSet,
sharedPrefs.gallerySet,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -74,6 +75,7 @@ fun GalleryCardCompose(
modifier = modifier,
accountViewModel = accountViewModel,
nav = nav,
ratio = ratio,
)
} else {
RedirectableGalleryCard(
Expand All @@ -82,6 +84,7 @@ fun GalleryCardCompose(
modifier = modifier,
accountViewModel = accountViewModel,
nav = nav,
ratio = ratio,
)
}
}
Expand All @@ -92,6 +95,7 @@ fun GalleryCardCompose(
modifier = modifier,
accountViewModel = accountViewModel,
nav = nav,
ratio = ratio,
)
}
}
Expand All @@ -105,6 +109,7 @@ fun RedirectableGalleryCard(
modifier: Modifier = Modifier,
accountViewModel: AccountViewModel,
nav: INav,
ratio: Float = 1.0f,
) {
QuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
ClickableNote(
Expand All @@ -123,7 +128,7 @@ fun RedirectableGalleryCard(
note = galleryNote,
accountViewModel = accountViewModel,
) {
GalleryThumbnail(galleryNote, accountViewModel, nav)
GalleryThumbnail(galleryNote, accountViewModel, nav, ratio = ratio)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,17 +135,18 @@ fun GalleryThumbnail(
emptyList()
}

InnerRenderGalleryThumb(content, baseNote, accountViewModel)
InnerRenderGalleryThumb(content, baseNote, accountViewModel, ratio)
}

@Composable
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)
}
Expand All @@ -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)
}
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ 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
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

Expand Down Expand Up @@ -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),
Expand All @@ -100,11 +110,12 @@ private fun GalleryFeedLoaded(
baseNote = item,
modifier =
Modifier
.aspectRatio(1f)
.aspectRatio(ratio)
.fillMaxSize()
.animateItem(),
accountViewModel = accountViewModel,
nav = nav,
ratio = ratio,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -204,6 +212,8 @@ fun SettingsScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) {

val featureSetIndex =
sharedPreferencesViewModel.sharedPrefs.featureSet.screenCode
val galleryIndex =
sharedPreferencesViewModel.sharedPrefs.gallerySet.screenCode

Column(
Modifier
Expand Down Expand Up @@ -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)
}
}
Expand Down
6 changes: 6 additions & 0 deletions amethyst/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down