From 99d1480f2619668e728857155b6802194b619419 Mon Sep 17 00:00:00 2001 From: Filipe Belatti Date: Sun, 17 Nov 2024 21:43:35 +0000 Subject: [PATCH] Make blockquote optional through settings --- .../core/persistence/UserSharedPreferences.kt | 7 +++++++ .../features/share/ShareReceiverViewModel.kt | 8 ++++++-- .../features/user/data/UserDataSource.kt | 8 ++++++++ .../features/user/domain/UserPreferences.kt | 1 + .../features/user/domain/UserRepository.kt | 2 ++ .../presentation/UserPreferencesProvider.kt | 1 + .../presentation/UserPreferencesScreen.kt | 19 ++++++++++++++++++- .../presentation/UserPreferencesViewModel.kt | 4 ++++ app/src/main/res/values/strings.xml | 2 ++ .../features/user/data/UserDataSourceTest.kt | 1 + 10 files changed, 50 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/core/persistence/UserSharedPreferences.kt b/app/src/main/kotlin/com/fibelatti/pinboard/core/persistence/UserSharedPreferences.kt index 09b16a3d..34d81d25 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/core/persistence/UserSharedPreferences.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/core/persistence/UserSharedPreferences.kt @@ -44,6 +44,9 @@ const val KEY_FOLLOW_REDIRECTS = "FOLLOW_REDIRECTS" @VisibleForTesting const val KEY_AUTO_FILL_DESCRIPTION = "AUTO_FILL_DESCRIPTION" +@VisibleForTesting +const val KEY_USE_BLOCKQUOTE = "USE_BLOCKQUOTE" + @VisibleForTesting const val KEY_SHOW_DESCRIPTION_IN_LISTS = "SHOW_DESCRIPTION_IN_LISTS" @@ -123,6 +126,10 @@ class UserSharedPreferences @Inject constructor(private val sharedPreferences: S get() = sharedPreferences.get(KEY_AUTO_FILL_DESCRIPTION, false) set(value) = sharedPreferences.put(KEY_AUTO_FILL_DESCRIPTION, value) + var useBlockquote: Boolean + get() = sharedPreferences.get(KEY_USE_BLOCKQUOTE, false) + set(value) = sharedPreferences.put(KEY_USE_BLOCKQUOTE, value) + var showDescriptionInLists: Boolean get() = sharedPreferences.get(KEY_SHOW_DESCRIPTION_IN_LISTS, true) set(value) = sharedPreferences.put(KEY_SHOW_DESCRIPTION_IN_LISTS, value) diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/share/ShareReceiverViewModel.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/share/ShareReceiverViewModel.kt index d72ddf30..c9af8e1f 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/share/ShareReceiverViewModel.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/share/ShareReceiverViewModel.kt @@ -79,7 +79,9 @@ class ShareReceiverViewModel @Inject constructor( val newPost = Post( url = finalUrl, title = title, - description = description?.let { "
$it
" }.orEmpty(), + description = description + ?.let { if (userRepository.useBlockquote) "
$it
" else it } + .orEmpty(), private = userRepository.defaultPrivate ?: false, readLater = userRepository.defaultReadLater ?: false, tags = userRepository.defaultTags, @@ -96,7 +98,9 @@ class ShareReceiverViewModel @Inject constructor( params = Post( url = finalUrl, title = title, - description = description?.let { "
$it
" }.orEmpty(), + description = description + ?.let { if (userRepository.useBlockquote) "
$it
" else it } + .orEmpty(), private = userRepository.defaultPrivate, readLater = userRepository.defaultReadLater, tags = userRepository.defaultTags, diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSource.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSource.kt index 5b6c2709..c3f3dd8b 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSource.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSource.kt @@ -142,6 +142,13 @@ class UserDataSource @Inject constructor( updateCurrentPreferences() } + override var useBlockquote: Boolean + get() = userSharedPreferences.useBlockquote + set(value) { + userSharedPreferences.useBlockquote = value + updateCurrentPreferences() + } + override var showDescriptionInLists: Boolean get() = userSharedPreferences.showDescriptionInLists set(value) { @@ -197,6 +204,7 @@ class UserDataSource @Inject constructor( alwaysUseSidePanel = alwaysUseSidePanel, followRedirects = followRedirects, autoFillDescription = autoFillDescription, + useBlockquote = useBlockquote, showDescriptionInLists = showDescriptionInLists, defaultPrivate = defaultPrivate ?: false, defaultReadLater = defaultReadLater ?: false, diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserPreferences.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserPreferences.kt index 4833e5ae..fb53e207 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserPreferences.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserPreferences.kt @@ -19,6 +19,7 @@ data class UserPreferences( val alwaysUseSidePanel: Boolean, val followRedirects: Boolean, val autoFillDescription: Boolean, + val useBlockquote: Boolean, val showDescriptionInLists: Boolean, val defaultPrivate: Boolean, val defaultReadLater: Boolean, diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserRepository.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserRepository.kt index aa51f93b..487b035e 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserRepository.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/domain/UserRepository.kt @@ -40,6 +40,8 @@ interface UserRepository { var autoFillDescription: Boolean + var useBlockquote: Boolean + var showDescriptionInLists: Boolean var defaultPrivate: Boolean? diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesProvider.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesProvider.kt index 7c5f6ca2..ea2f18d4 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesProvider.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesProvider.kt @@ -25,6 +25,7 @@ class UserPreferencesProvider : PreviewParameterProvider { alwaysUseSidePanel = true, followRedirects = true, autoFillDescription = true, + useBlockquote = true, showDescriptionInLists = true, defaultPrivate = false, defaultReadLater = false, diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesScreen.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesScreen.kt index 6e438e7d..b9bca2d2 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesScreen.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesScreen.kt @@ -79,7 +79,7 @@ fun UserPreferencesScreen( .windowInsetsPadding( WindowInsets.safeDrawing .only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom), - ), + ), ) { if (maxWidth < 600.dp) { Column( @@ -443,6 +443,7 @@ private fun BookmarkingPreferencesContent( onEditAfterSharingChange = userPreferencesViewModel::saveEditAfterSharing, onFollowRedirectsChange = userPreferencesViewModel::saveFollowRedirects, onAutoFillDescriptionChange = userPreferencesViewModel::saveAutoFillDescription, + onUseBlockquoteChange = userPreferencesViewModel::saveUseBlockquote, onPrivateByDefaultChange = userPreferencesViewModel::saveDefaultPrivate, onReadLaterByDefaultChange = userPreferencesViewModel::saveDefaultReadLater, ) @@ -481,6 +482,7 @@ private fun BookmarkingPreferencesContent( onEditAfterSharingChange: (EditAfterSharing) -> Unit, onFollowRedirectsChange: (Boolean) -> Unit, onAutoFillDescriptionChange: (Boolean) -> Unit, + onUseBlockquoteChange: (Boolean) -> Unit, onPrivateByDefaultChange: (Boolean) -> Unit, onReadLaterByDefaultChange: (Boolean) -> Unit, modifier: Modifier = Modifier, @@ -544,6 +546,20 @@ private fun BookmarkingPreferencesContent( modifier = Modifier.padding(top = 16.dp), ) + AnimatedVisibility( + visible = userPreferences.autoFillDescription, + enter = expandVertically(), + exit = shrinkVertically(), + ) { + SettingToggle( + title = stringResource(id = R.string.user_preferences_use_blockquote), + description = stringResource(id = R.string.user_preferences_use_blockquote_description), + checked = userPreferences.useBlockquote, + onCheckedChange = onUseBlockquoteChange, + modifier = Modifier.padding(top = 16.dp), + ) + } + if (AppMode.NO_API != appMode) { SettingToggle( title = stringResource(id = R.string.user_preferences_default_private_label), @@ -640,6 +656,7 @@ private fun BookmarkingPreferencesContentPreview( onEditAfterSharingChange = {}, onFollowRedirectsChange = {}, onAutoFillDescriptionChange = {}, + onUseBlockquoteChange = {}, onPrivateByDefaultChange = {}, onReadLaterByDefaultChange = {}, ) diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesViewModel.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesViewModel.kt index e8c42275..dd7e2c3f 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesViewModel.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/user/presentation/UserPreferencesViewModel.kt @@ -80,6 +80,10 @@ class UserPreferencesViewModel @Inject constructor( userRepository.autoFillDescription = value } + fun saveUseBlockquote(value: Boolean) { + userRepository.useBlockquote = value + } + fun saveShowDescriptionInLists(value: Boolean) { userRepository.showDescriptionInLists = value } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 61fe0d32..df61c1b3 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -247,6 +247,8 @@ Automatically follow redirects when sharing a bookmark to the app, saving the final URL. Increases the loading time when saving a bookmark via the share action Auto-fill title and description Automatically get the page details when sharing a bookmark to the app. Increases the loading time when saving a bookmark via the share action + Use blockquote + Wrap the description in a blockquote tag Show description in lists Show the first 5 lines of the description when browsing bookmarks Use side panel when available diff --git a/app/src/test/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSourceTest.kt b/app/src/test/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSourceTest.kt index eac89554..4a70df84 100644 --- a/app/src/test/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSourceTest.kt +++ b/app/src/test/kotlin/com/fibelatti/pinboard/features/user/data/UserDataSourceTest.kt @@ -54,6 +54,7 @@ internal class UserDataSourceTest { alwaysUseSidePanel = false, followRedirects = true, autoFillDescription = false, + useBlockquote = false, showDescriptionInLists = false, defaultPrivate = false, defaultReadLater = false,