Utilise typealias for RadioOptions

This commit is contained in:
andrew 2023-08-21 18:35:37 +09:30
parent 60f396a158
commit 9123dd90a4
2 changed files with 7 additions and 37 deletions

View File

@ -29,8 +29,8 @@ import kotlin.reflect.KClass
class ExpirationSettingsViewModel(
private val threadId: Long,
private val afterReadOptions: List<RadioOption<ExpiryMode>>,
private val afterSendOptions: List<RadioOption<ExpiryMode>>,
private val afterReadOptions: List<ExpirationRadioOption>,
private val afterSendOptions: List<ExpirationRadioOption>,
private val textSecurePreferences: TextSecurePreferences,
private val messageExpirationManager: MessageExpirationManagerProtocol,
private val threadDb: ThreadDatabase,
@ -93,11 +93,11 @@ class ExpirationSettingsViewModel(
}.onEach { options ->
val enabled = _uiState.value.isSelfAdmin || 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)
}
} else {
options.slice(1 until options.size).filterIsInstance<ExpirationRadioOption>().map {
options.slice(1 until options.size).map {
it.copy(enabled = enabled)
}
}

View File

@ -68,7 +68,7 @@ class RadioOptionAdapter<T>(
}
sealed class RadioOption<T>(
data class RadioOption<T>(
val value: T,
val title: String,
val subtitle: String? = null,
@ -76,35 +76,5 @@ sealed class RadioOption<T>(
val contentDescription: String = ""
)
class StringRadioOption(value: String,
title: String,
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)
}
typealias StringRadioOption = RadioOption<String>
typealias ExpirationRadioOption = RadioOption<ExpiryMode>