refactor: Ensure `statusDisplayOptions` are created consistently (#92)

Previous code created `statusDisplayOptions` in full each time, risking
the creation of inconsistent states / defaults.

Refactor to use `StatusDisplayOptions.from()` so the user's settings
(and defaults) are always respected.
This commit is contained in:
Nik Clayton 2023-09-24 21:23:07 +02:00 committed by GitHub
parent af7b668476
commit 9b21f3f9bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 67 deletions

View File

@ -48,7 +48,6 @@ import app.pachli.interfaces.ActionButtonActivity
import app.pachli.interfaces.ReselectableFragment
import app.pachli.interfaces.StatusActionListener
import app.pachli.settings.PrefKeys
import app.pachli.util.CardViewMode
import app.pachli.util.StatusDisplayOptions
import app.pachli.util.hide
import app.pachli.util.show
@ -99,20 +98,9 @@ class ConversationsFragment :
val preferences = PreferenceManager.getDefaultSharedPreferences(view.context)
val statusDisplayOptions = StatusDisplayOptions(
animateAvatars = preferences.getBoolean(PrefKeys.ANIMATE_GIF_AVATARS, false),
mediaPreviewEnabled = accountManager.activeAccount?.mediaPreviewEnabled ?: true,
useAbsoluteTime = preferences.getBoolean(PrefKeys.ABSOLUTE_TIME_VIEW, false),
showBotOverlay = preferences.getBoolean(PrefKeys.SHOW_BOT_OVERLAY, true),
useBlurhash = preferences.getBoolean(PrefKeys.USE_BLURHASH, true),
cardViewMode = CardViewMode.NONE,
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false),
showSensitiveMedia = accountManager.activeAccount!!.alwaysShowSensitiveMedia,
openSpoiler = accountManager.activeAccount!!.alwaysOpenSpoiler,
val statusDisplayOptions = StatusDisplayOptions.from(
preferences,
accountManager.activeAccount!!,
)
adapter = ConversationAdapter(statusDisplayOptions, this)

View File

@ -46,8 +46,6 @@ import app.pachli.di.Injectable
import app.pachli.di.ViewModelFactory
import app.pachli.entity.Attachment
import app.pachli.entity.Status
import app.pachli.settings.PrefKeys
import app.pachli.util.CardViewMode
import app.pachli.util.StatusDisplayOptions
import app.pachli.util.viewBinding
import app.pachli.util.visible
@ -146,20 +144,9 @@ class ReportStatusesFragment :
private fun initStatusesView() {
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val statusDisplayOptions = StatusDisplayOptions(
animateAvatars = false,
mediaPreviewEnabled = accountManager.activeAccount?.mediaPreviewEnabled ?: true,
useAbsoluteTime = preferences.getBoolean(PrefKeys.ABSOLUTE_TIME_VIEW, false),
showBotOverlay = false,
useBlurhash = preferences.getBoolean(PrefKeys.USE_BLURHASH, true),
cardViewMode = CardViewMode.NONE,
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false),
showSensitiveMedia = accountManager.activeAccount!!.alwaysShowSensitiveMedia,
openSpoiler = accountManager.activeAccount!!.alwaysOpenSpoiler,
val statusDisplayOptions = StatusDisplayOptions.from(
preferences,
accountManager.activeAccount!!,
)
adapter = StatusesAdapter(statusDisplayOptions, viewModel.statusViewState, this)

View File

@ -51,8 +51,6 @@ import app.pachli.entity.Status
import app.pachli.entity.Status.Mention
import app.pachli.interfaces.AccountSelectionListener
import app.pachli.interfaces.StatusActionListener
import app.pachli.settings.PrefKeys
import app.pachli.util.CardViewMode
import app.pachli.util.StatusDisplayOptions
import app.pachli.util.openLink
import app.pachli.view.showMuteAccountDialog
@ -77,20 +75,9 @@ class SearchStatusesFragment : SearchFragment<StatusViewData>(), StatusActionLis
override fun createAdapter(): PagingDataAdapter<StatusViewData, *> {
val preferences = PreferenceManager.getDefaultSharedPreferences(binding.searchRecyclerView.context)
val statusDisplayOptions = StatusDisplayOptions(
animateAvatars = preferences.getBoolean(PrefKeys.ANIMATE_GIF_AVATARS, false),
mediaPreviewEnabled = viewModel.mediaPreviewEnabled,
useAbsoluteTime = preferences.getBoolean(PrefKeys.ABSOLUTE_TIME_VIEW, false),
showBotOverlay = preferences.getBoolean(PrefKeys.SHOW_BOT_OVERLAY, true),
useBlurhash = preferences.getBoolean(PrefKeys.USE_BLURHASH, true),
cardViewMode = CardViewMode.NONE,
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false),
showSensitiveMedia = accountManager.activeAccount!!.alwaysShowSensitiveMedia,
openSpoiler = accountManager.activeAccount!!.alwaysOpenSpoiler,
val statusDisplayOptions = StatusDisplayOptions.from(
preferences,
accountManager.activeAccount!!,
)
binding.searchRecyclerView.addItemDecoration(

View File

@ -43,8 +43,6 @@ import app.pachli.di.Injectable
import app.pachli.di.ViewModelFactory
import app.pachli.fragment.SFragment
import app.pachli.interfaces.StatusActionListener
import app.pachli.settings.PrefKeys
import app.pachli.util.CardViewMode
import app.pachli.util.ListStatusAccessibilityDelegate
import app.pachli.util.StatusDisplayOptions
import app.pachli.util.hide
@ -97,24 +95,9 @@ class ViewThreadFragment :
thisThreadsStatusId = requireArguments().getString(ID_EXTRA)!!
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val statusDisplayOptions = StatusDisplayOptions(
animateAvatars = preferences.getBoolean(PrefKeys.ANIMATE_GIF_AVATARS, false),
mediaPreviewEnabled = accountManager.activeAccount!!.mediaPreviewEnabled,
useAbsoluteTime = preferences.getBoolean(PrefKeys.ABSOLUTE_TIME_VIEW, false),
showBotOverlay = preferences.getBoolean(PrefKeys.SHOW_BOT_OVERLAY, true),
useBlurhash = preferences.getBoolean(PrefKeys.USE_BLURHASH, true),
cardViewMode = if (preferences.getBoolean(PrefKeys.SHOW_CARDS_IN_TIMELINES, false)) {
CardViewMode.INDENTED
} else {
CardViewMode.NONE
},
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false),
showSensitiveMedia = accountManager.activeAccount!!.alwaysShowSensitiveMedia,
openSpoiler = accountManager.activeAccount!!.alwaysOpenSpoiler,
val statusDisplayOptions = StatusDisplayOptions.from(
preferences,
accountManager.activeAccount!!,
)
adapter = ThreadAdapter(statusDisplayOptions, this)
}