mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-24 11:21:27 +00:00
Utilise typealias for RadioOptions
This commit is contained in:
parent
60f396a158
commit
9123dd90a4
app/src/main/java/org/thoughtcrime/securesms
8
app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt
8
app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt
@ -29,8 +29,8 @@ import kotlin.reflect.KClass
|
|||||||
|
|
||||||
class ExpirationSettingsViewModel(
|
class ExpirationSettingsViewModel(
|
||||||
private val threadId: Long,
|
private val threadId: Long,
|
||||||
private val afterReadOptions: List<RadioOption<ExpiryMode>>,
|
private val afterReadOptions: List<ExpirationRadioOption>,
|
||||||
private val afterSendOptions: List<RadioOption<ExpiryMode>>,
|
private val afterSendOptions: List<ExpirationRadioOption>,
|
||||||
private val textSecurePreferences: TextSecurePreferences,
|
private val textSecurePreferences: TextSecurePreferences,
|
||||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||||
private val threadDb: ThreadDatabase,
|
private val threadDb: ThreadDatabase,
|
||||||
@ -93,11 +93,11 @@ class ExpirationSettingsViewModel(
|
|||||||
}.onEach { options ->
|
}.onEach { options ->
|
||||||
val enabled = _uiState.value.isSelfAdmin || recipient.value?.isClosedGroupRecipient == true
|
val enabled = _uiState.value.isSelfAdmin || recipient.value?.isClosedGroupRecipient == true
|
||||||
_expirationTimerOptions.value = if (ExpirationConfiguration.isNewConfigEnabled && (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true)) {
|
_expirationTimerOptions.value = if (ExpirationConfiguration.isNewConfigEnabled && (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true)) {
|
||||||
options.filterIsInstance<ExpirationRadioOption>().map {
|
options.map {
|
||||||
it.copy(enabled = enabled)
|
it.copy(enabled = enabled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
options.slice(1 until options.size).filterIsInstance<ExpirationRadioOption>().map {
|
options.slice(1 until options.size).map {
|
||||||
it.copy(enabled = enabled)
|
it.copy(enabled = enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class RadioOptionAdapter<T>(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class RadioOption<T>(
|
data class RadioOption<T>(
|
||||||
val value: T,
|
val value: T,
|
||||||
val title: String,
|
val title: String,
|
||||||
val subtitle: String? = null,
|
val subtitle: String? = null,
|
||||||
@ -76,35 +76,5 @@ sealed class RadioOption<T>(
|
|||||||
val contentDescription: String = ""
|
val contentDescription: String = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
class StringRadioOption(value: String,
|
typealias StringRadioOption = RadioOption<String>
|
||||||
title: String,
|
typealias ExpirationRadioOption = RadioOption<ExpiryMode>
|
||||||
subtitle: String? = null,
|
|
||||||
enabled: Boolean = true,
|
|
||||||
contentDescription: String = ""): RadioOption<String>(
|
|
||||||
value,
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
enabled,
|
|
||||||
contentDescription
|
|
||||||
)
|
|
||||||
|
|
||||||
class ExpirationRadioOption(
|
|
||||||
value: ExpiryMode,
|
|
||||||
title: String,
|
|
||||||
subtitle: String? = null,
|
|
||||||
enabled: Boolean = true,
|
|
||||||
contentDescription: String = ""
|
|
||||||
): RadioOption<ExpiryMode>(
|
|
||||||
value,
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
enabled,
|
|
||||||
contentDescription
|
|
||||||
) {
|
|
||||||
fun copy(value: ExpiryMode = this.value,
|
|
||||||
title: String = this.title,
|
|
||||||
subtitle: String? = this.subtitle,
|
|
||||||
enabled: Boolean = this.enabled,
|
|
||||||
contentDescription: String = this.contentDescription) =
|
|
||||||
ExpirationRadioOption(value, title, subtitle, enabled, contentDescription)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user