Skip to content

Commit

Permalink
Make blockquote optional through settings
Browse files Browse the repository at this point in the history
  • Loading branch information
fibelatti committed Nov 17, 2024
1 parent 470ba62 commit 99d1480
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class ShareReceiverViewModel @Inject constructor(
val newPost = Post(
url = finalUrl,
title = title,
description = description?.let { "<blockquote>$it</blockquote>" }.orEmpty(),
description = description
?.let { if (userRepository.useBlockquote) "<blockquote>$it</blockquote>" else it }
.orEmpty(),
private = userRepository.defaultPrivate ?: false,
readLater = userRepository.defaultReadLater ?: false,
tags = userRepository.defaultTags,
Expand All @@ -96,7 +98,9 @@ class ShareReceiverViewModel @Inject constructor(
params = Post(
url = finalUrl,
title = title,
description = description?.let { "<blockquote>$it</blockquote>" }.orEmpty(),
description = description
?.let { if (userRepository.useBlockquote) "<blockquote>$it</blockquote>" else it }
.orEmpty(),
private = userRepository.defaultPrivate,
readLater = userRepository.defaultReadLater,
tags = userRepository.defaultTags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -197,6 +204,7 @@ class UserDataSource @Inject constructor(
alwaysUseSidePanel = alwaysUseSidePanel,
followRedirects = followRedirects,
autoFillDescription = autoFillDescription,
useBlockquote = useBlockquote,
showDescriptionInLists = showDescriptionInLists,
defaultPrivate = defaultPrivate ?: false,
defaultReadLater = defaultReadLater ?: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface UserRepository {

var autoFillDescription: Boolean

var useBlockquote: Boolean

var showDescriptionInLists: Boolean

var defaultPrivate: Boolean?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class UserPreferencesProvider : PreviewParameterProvider<UserPreferences> {
alwaysUseSidePanel = true,
followRedirects = true,
autoFillDescription = true,
useBlockquote = true,
showDescriptionInLists = true,
defaultPrivate = false,
defaultReadLater = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun UserPreferencesScreen(
.windowInsetsPadding(
WindowInsets.safeDrawing
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
),
),
) {
if (maxWidth < 600.dp) {
Column(
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -640,6 +656,7 @@ private fun BookmarkingPreferencesContentPreview(
onEditAfterSharingChange = {},
onFollowRedirectsChange = {},
onAutoFillDescriptionChange = {},
onUseBlockquoteChange = {},
onPrivateByDefaultChange = {},
onReadLaterByDefaultChange = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@
<string name="user_preferences_follow_redirects_description">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</string>
<string name="user_preferences_description_auto_fill">Auto-fill title and description</string>
<string name="user_preferences_description_auto_fill_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</string>
<string name="user_preferences_use_blockquote">Use blockquote</string>
<string name="user_preferences_use_blockquote_description">Wrap the description in a blockquote tag</string>
<string name="user_preferences_description_visible_in_lists">Show description in lists</string>
<string name="user_preferences_description_visible_in_lists_description">Show the first 5 lines of the description when browsing bookmarks</string>
<string name="user_preferences_always_use_side_panel">Use side panel when available</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal class UserDataSourceTest {
alwaysUseSidePanel = false,
followRedirects = true,
autoFillDescription = false,
useBlockquote = false,
showDescriptionInLists = false,
defaultPrivate = false,
defaultReadLater = false,
Expand Down

0 comments on commit 99d1480

Please sign in to comment.