StatusDisplayOptions.kt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2023 Tusky Contributors
  3. *
  4. * This file is a part of Tusky.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under the terms of the
  7. * GNU General Public License as published by the Free Software Foundation; either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  11. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  12. * Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with Tusky; if not,
  15. * see <http://www.gnu.org/licenses>.
  16. */
  17. package com.keylesspalace.tusky.util
  18. import android.content.SharedPreferences
  19. import com.keylesspalace.tusky.db.AccountEntity
  20. import com.keylesspalace.tusky.settings.PrefKeys
  21. data class StatusDisplayOptions(
  22. @get:JvmName("animateAvatars")
  23. val animateAvatars: Boolean,
  24. @get:JvmName("mediaPreviewEnabled")
  25. val mediaPreviewEnabled: Boolean,
  26. @get:JvmName("useAbsoluteTime")
  27. val useAbsoluteTime: Boolean,
  28. @get:JvmName("showBotOverlay")
  29. val showBotOverlay: Boolean,
  30. @get:JvmName("useBlurhash")
  31. val useBlurhash: Boolean,
  32. @get:JvmName("cardViewMode")
  33. val cardViewMode: CardViewMode,
  34. @get:JvmName("confirmReblogs")
  35. val confirmReblogs: Boolean,
  36. @get:JvmName("confirmFavourites")
  37. val confirmFavourites: Boolean,
  38. @get:JvmName("hideStats")
  39. val hideStats: Boolean,
  40. @get:JvmName("animateEmojis")
  41. val animateEmojis: Boolean,
  42. @get:JvmName("showSensitiveMedia")
  43. val showSensitiveMedia: Boolean,
  44. @get:JvmName("openSpoiler")
  45. val openSpoiler: Boolean
  46. ) {
  47. /**
  48. * @return a new StatusDisplayOptions adapted to whichever preference changed.
  49. */
  50. fun make(
  51. preferences: SharedPreferences,
  52. key: String,
  53. account: AccountEntity
  54. ) = when (key) {
  55. PrefKeys.ANIMATE_GIF_AVATARS -> copy(
  56. animateAvatars = preferences.getBoolean(key, false)
  57. )
  58. PrefKeys.MEDIA_PREVIEW_ENABLED -> copy(
  59. mediaPreviewEnabled = account.mediaPreviewEnabled
  60. )
  61. PrefKeys.ABSOLUTE_TIME_VIEW -> copy(
  62. useAbsoluteTime = preferences.getBoolean(key, false)
  63. )
  64. PrefKeys.SHOW_BOT_OVERLAY -> copy(
  65. showBotOverlay = preferences.getBoolean(key, true)
  66. )
  67. PrefKeys.USE_BLURHASH -> copy(
  68. useBlurhash = preferences.getBoolean(key, true)
  69. )
  70. PrefKeys.CONFIRM_FAVOURITES -> copy(
  71. confirmFavourites = preferences.getBoolean(key, false)
  72. )
  73. PrefKeys.CONFIRM_REBLOGS -> copy(
  74. confirmReblogs = preferences.getBoolean(key, true)
  75. )
  76. PrefKeys.WELLBEING_HIDE_STATS_POSTS -> copy(
  77. hideStats = preferences.getBoolean(key, false)
  78. )
  79. PrefKeys.ANIMATE_CUSTOM_EMOJIS -> copy(
  80. animateEmojis = preferences.getBoolean(key, false)
  81. )
  82. PrefKeys.ALWAYS_SHOW_SENSITIVE_MEDIA -> copy(
  83. showSensitiveMedia = account.alwaysShowSensitiveMedia
  84. )
  85. PrefKeys.ALWAYS_OPEN_SPOILER -> copy(
  86. openSpoiler = account.alwaysOpenSpoiler
  87. )
  88. else -> { this }
  89. }
  90. companion object {
  91. /** Preference keys that, if changed, affect StatusDisplayOptions */
  92. val prefKeys = setOf(
  93. PrefKeys.ABSOLUTE_TIME_VIEW,
  94. PrefKeys.ALWAYS_SHOW_SENSITIVE_MEDIA,
  95. PrefKeys.ALWAYS_OPEN_SPOILER,
  96. PrefKeys.ANIMATE_CUSTOM_EMOJIS,
  97. PrefKeys.ANIMATE_GIF_AVATARS,
  98. PrefKeys.CONFIRM_FAVOURITES,
  99. PrefKeys.CONFIRM_REBLOGS,
  100. PrefKeys.MEDIA_PREVIEW_ENABLED,
  101. PrefKeys.SHOW_BOT_OVERLAY,
  102. PrefKeys.USE_BLURHASH,
  103. PrefKeys.WELLBEING_HIDE_STATS_POSTS
  104. )
  105. fun from(preferences: SharedPreferences, account: AccountEntity) = StatusDisplayOptions(
  106. animateAvatars = preferences.getBoolean(PrefKeys.ANIMATE_GIF_AVATARS, false),
  107. animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
  108. mediaPreviewEnabled = account.mediaPreviewEnabled,
  109. useAbsoluteTime = preferences.getBoolean(PrefKeys.ABSOLUTE_TIME_VIEW, false),
  110. showBotOverlay = preferences.getBoolean(PrefKeys.SHOW_BOT_OVERLAY, true),
  111. useBlurhash = preferences.getBoolean(PrefKeys.USE_BLURHASH, true),
  112. cardViewMode = CardViewMode.NONE,
  113. confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
  114. confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
  115. hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
  116. showSensitiveMedia = account.alwaysShowSensitiveMedia,
  117. openSpoiler = account.alwaysOpenSpoiler
  118. )
  119. }
  120. }