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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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