rename visibility enum properties

This commit is contained in:
Conny Duck 2024-07-17 20:25:43 +02:00
parent 0a24acddba
commit 62aa13b475
No known key found for this signature in database
7 changed files with 24 additions and 27 deletions

View File

@ -390,7 +390,7 @@ class ComposeViewModel @Inject constructor(
val tootToSend = StatusToSend( val tootToSend = StatusToSend(
text = content, text = content,
warningText = spoilerText, warningText = spoilerText,
visibility = _statusVisibility.value.serverString, visibility = _statusVisibility.value.stringValue,
sensitive = attachedMedia.isNotEmpty() && (_markMediaAsSensitive.value || _showContentWarning.value), sensitive = attachedMedia.isNotEmpty() && (_markMediaAsSensitive.value || _showContentWarning.value),
media = attachedMedia, media = attachedMedia,
scheduledAt = _scheduledAt.value, scheduledAt = _scheduledAt.value,
@ -494,8 +494,8 @@ class ComposeViewModel @Inject constructor(
} }
val replyVisibility = composeOptions?.replyVisibility ?: Status.Visibility.UNKNOWN val replyVisibility = composeOptions?.replyVisibility ?: Status.Visibility.UNKNOWN
startingVisibility = Status.Visibility.byNum( startingVisibility = Status.Visibility.fromInt(
preferredVisibility.num.coerceAtLeast(replyVisibility.num) preferredVisibility.int.coerceAtLeast(replyVisibility.int)
) )
modifiedInitialState = composeOptions?.modifiedInitialState == true modifiedInitialState = composeOptions?.modifiedInitialState == true
@ -537,7 +537,7 @@ class ComposeViewModel @Inject constructor(
postLanguage = composeOptions?.language postLanguage = composeOptions?.language
val tootVisibility = composeOptions?.visibility ?: Status.Visibility.UNKNOWN val tootVisibility = composeOptions?.visibility ?: Status.Visibility.UNKNOWN
if (tootVisibility.num != Status.Visibility.UNKNOWN.num) { if (tootVisibility.int != Status.Visibility.UNKNOWN.int) {
startingVisibility = tootVisibility startingVisibility = tootVisibility
} }
_statusVisibility.value = startingVisibility _statusVisibility.value = startingVisibility

View File

@ -185,11 +185,11 @@ class AccountPreferencesFragment : PreferenceFragmentCompat() {
isSingleLineTitle = false isSingleLineTitle = false
setSummaryProvider { entry } setSummaryProvider { entry }
val visibility = accountManager.activeAccount?.defaultPostPrivacy ?: Status.Visibility.PUBLIC val visibility = accountManager.activeAccount?.defaultPostPrivacy ?: Status.Visibility.PUBLIC
value = visibility.serverString value = visibility.stringValue
setIcon(getIconForVisibility(visibility)) setIcon(getIconForVisibility(visibility))
isPersistent = false // its saved to the account and shouldn't be in shared preferences isPersistent = false // its saved to the account and shouldn't be in shared preferences
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val icon = getIconForVisibility(Status.Visibility.byString(newValue as String)) val icon = getIconForVisibility(Status.Visibility.fromStringValue(newValue as String))
setIcon(icon) setIcon(icon)
if (accountManager.activeAccount?.defaultReplyPrivacy == DefaultReplyVisibility.MATCH_DEFAULT_POST_VISIBILITY) { if (accountManager.activeAccount?.defaultReplyPrivacy == DefaultReplyVisibility.MATCH_DEFAULT_POST_VISIBILITY) {
findPreference<ListPreference>(PrefKeys.DEFAULT_REPLY_PRIVACY)?.setIcon(icon) findPreference<ListPreference>(PrefKeys.DEFAULT_REPLY_PRIVACY)?.setIcon(icon)
@ -209,11 +209,11 @@ class AccountPreferencesFragment : PreferenceFragmentCompat() {
isSingleLineTitle = false isSingleLineTitle = false
setSummaryProvider { entry } setSummaryProvider { entry }
val visibility = activeAccount.defaultReplyPrivacy val visibility = activeAccount.defaultReplyPrivacy
value = visibility.string value = visibility.stringValue
setIcon(getIconForVisibility(visibility.toVisibilityOr(activeAccount.defaultPostPrivacy))) setIcon(getIconForVisibility(visibility.toVisibilityOr(activeAccount.defaultPostPrivacy)))
isPersistent = false // its saved to the account and shouldn't be in shared preferences isPersistent = false // its saved to the account and shouldn't be in shared preferences
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val newVisibility = DefaultReplyVisibility.byString(newValue as String) val newVisibility = DefaultReplyVisibility.fromStringValue(newValue as String)
setIcon(getIconForVisibility(newVisibility.toVisibilityOr(activeAccount.defaultPostPrivacy))) setIcon(getIconForVisibility(newVisibility.toVisibilityOr(activeAccount.defaultPostPrivacy)))
activeAccount.defaultReplyPrivacy = newVisibility activeAccount.defaultReplyPrivacy = newVisibility
accountManager.saveAccount(activeAccount) accountManager.saveAccount(activeAccount)

View File

@ -57,22 +57,22 @@ class Converters @Inject constructor(
@TypeConverter @TypeConverter
fun visibilityToInt(visibility: Status.Visibility?): Int { fun visibilityToInt(visibility: Status.Visibility?): Int {
return visibility?.num ?: Status.Visibility.UNKNOWN.num return visibility?.int ?: Status.Visibility.UNKNOWN.int
} }
@TypeConverter @TypeConverter
fun intToVisibility(visibility: Int): Status.Visibility { fun intToVisibility(visibility: Int): Status.Visibility {
return Status.Visibility.byNum(visibility) return Status.Visibility.fromInt(visibility)
} }
@TypeConverter @TypeConverter
fun defaultReplyVisibilityToInt(visibility: DefaultReplyVisibility?): Int { fun defaultReplyVisibilityToInt(visibility: DefaultReplyVisibility?): Int {
return visibility?.num ?: DefaultReplyVisibility.MATCH_DEFAULT_POST_VISIBILITY.num return visibility?.int ?: DefaultReplyVisibility.MATCH_DEFAULT_POST_VISIBILITY.int
} }
@TypeConverter @TypeConverter
fun intToDefaultReplyVisibility(visibility: Int): DefaultReplyVisibility { fun intToDefaultReplyVisibility(visibility: Int): DefaultReplyVisibility {
return DefaultReplyVisibility.byNum(visibility) return DefaultReplyVisibility.fromInt(visibility)
} }
@TypeConverter @TypeConverter

View File

@ -68,7 +68,7 @@ data class Status(
get() = reblog ?: this get() = reblog ?: this
@JsonClass(generateAdapter = false) @JsonClass(generateAdapter = false)
enum class Visibility(val num: Int) { enum class Visibility(val int: Int) {
UNKNOWN(0), UNKNOWN(0),
@Json(name = "public") @Json(name = "public")
@ -83,7 +83,7 @@ data class Status(
@Json(name = "direct") @Json(name = "direct")
DIRECT(4); DIRECT(4);
val serverString: String val stringValue: String
get() = when (this) { get() = when (this) {
PUBLIC -> "public" PUBLIC -> "public"
UNLISTED -> "unlisted" UNLISTED -> "unlisted"
@ -93,10 +93,8 @@ data class Status(
} }
companion object { companion object {
fun fromInt(int: Int): Visibility {
@JvmStatic return when (int) {
fun byNum(num: Int): Visibility {
return when (num) {
4 -> DIRECT 4 -> DIRECT
3 -> PRIVATE 3 -> PRIVATE
2 -> UNLISTED 2 -> UNLISTED
@ -106,8 +104,7 @@ data class Status(
} }
} }
@JvmStatic fun fromStringValue(s: String): Visibility {
fun byString(s: String): Visibility {
return when (s) { return when (s) {
"public" -> PUBLIC "public" -> PUBLIC
"unlisted" -> UNLISTED "unlisted" -> UNLISTED

View File

@ -93,7 +93,7 @@ class SendStatusBroadcastReceiver : BroadcastReceiver() {
StatusToSend( StatusToSend(
text = text, text = text,
warningText = spoiler, warningText = spoiler,
visibility = visibility.serverString, visibility = visibility.stringValue,
sensitive = false, sensitive = false,
media = emptyList(), media = emptyList(),
scheduledAt = null, scheduledAt = null,

View File

@ -393,7 +393,7 @@ class SendStatusService : Service() {
content = status.text, content = status.text,
contentWarning = status.warningText, contentWarning = status.warningText,
sensitive = status.sensitive, sensitive = status.sensitive,
visibility = Status.Visibility.byString(status.visibility), visibility = Status.Visibility.fromStringValue(status.visibility),
mediaUris = status.media.map { it.uri }, mediaUris = status.media.map { it.uri },
mediaDescriptions = status.media.map { it.description }, mediaDescriptions = status.media.map { it.description },
mediaFocus = status.media.map { it.focus }, mediaFocus = status.media.map { it.focus },

View File

@ -2,14 +2,14 @@ package com.keylesspalace.tusky.settings
import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.entity.Status
enum class DefaultReplyVisibility(val num: Int) { enum class DefaultReplyVisibility(val int: Int) {
MATCH_DEFAULT_POST_VISIBILITY(0), MATCH_DEFAULT_POST_VISIBILITY(0),
PUBLIC(1), PUBLIC(1),
UNLISTED(2), UNLISTED(2),
PRIVATE(3), PRIVATE(3),
DIRECT(4); DIRECT(4);
val string: String val stringValue: String
get() = when (this) { get() = when (this) {
MATCH_DEFAULT_POST_VISIBILITY -> "match_default_post_visibility" MATCH_DEFAULT_POST_VISIBILITY -> "match_default_post_visibility"
PUBLIC -> "public" PUBLIC -> "public"
@ -29,8 +29,8 @@ enum class DefaultReplyVisibility(val num: Int) {
} }
companion object { companion object {
fun byNum(num: Int): DefaultReplyVisibility { fun fromInt(int: Int): DefaultReplyVisibility {
return when (num) { return when (int) {
4 -> DIRECT 4 -> DIRECT
3 -> PRIVATE 3 -> PRIVATE
2 -> UNLISTED 2 -> UNLISTED
@ -38,7 +38,7 @@ enum class DefaultReplyVisibility(val num: Int) {
else -> MATCH_DEFAULT_POST_VISIBILITY else -> MATCH_DEFAULT_POST_VISIBILITY
} }
} }
fun byString(s: String): DefaultReplyVisibility { fun fromStringValue(s: String): DefaultReplyVisibility {
return when (s) { return when (s) {
"public" -> PUBLIC "public" -> PUBLIC
"unlisted" -> UNLISTED "unlisted" -> UNLISTED