mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-25 20:27:21 +00:00
refactor: use generic option adapters, fix compile issues
This commit is contained in:
parent
317ecf6cee
commit
9faa400a5b
@ -24,12 +24,13 @@ import org.thoughtcrime.securesms.database.GroupDatabase
|
|||||||
import org.thoughtcrime.securesms.database.Storage
|
import org.thoughtcrime.securesms.database.Storage
|
||||||
import org.thoughtcrime.securesms.database.ThreadDatabase
|
import org.thoughtcrime.securesms.database.ThreadDatabase
|
||||||
import org.thoughtcrime.securesms.preferences.ExpirationRadioOption
|
import org.thoughtcrime.securesms.preferences.ExpirationRadioOption
|
||||||
|
import org.thoughtcrime.securesms.preferences.RadioOption
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
class ExpirationSettingsViewModel(
|
class ExpirationSettingsViewModel(
|
||||||
private val threadId: Long,
|
private val threadId: Long,
|
||||||
private val afterReadOptions: List<ExpirationRadioOption>,
|
private val afterReadOptions: List<RadioOption<ExpiryMode>>,
|
||||||
private val afterSendOptions: List<ExpirationRadioOption>,
|
private val afterSendOptions: List<RadioOption<ExpiryMode>>,
|
||||||
private val textSecurePreferences: TextSecurePreferences,
|
private val textSecurePreferences: TextSecurePreferences,
|
||||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||||
private val threadDb: ThreadDatabase,
|
private val threadDb: ThreadDatabase,
|
||||||
@ -49,10 +50,10 @@ class ExpirationSettingsViewModel(
|
|||||||
val selectedExpirationType: StateFlow<ExpiryMode> = _selectedExpirationType
|
val selectedExpirationType: StateFlow<ExpiryMode> = _selectedExpirationType
|
||||||
|
|
||||||
private val _selectedExpirationTimer = MutableStateFlow(afterSendOptions.firstOrNull())
|
private val _selectedExpirationTimer = MutableStateFlow(afterSendOptions.firstOrNull())
|
||||||
val selectedExpirationTimer: StateFlow<ExpirationRadioOption?> = _selectedExpirationTimer
|
val selectedExpirationTimer: StateFlow<RadioOption<ExpiryMode>?> = _selectedExpirationTimer
|
||||||
|
|
||||||
private val _expirationTimerOptions = MutableStateFlow<List<ExpirationRadioOption>>(emptyList())
|
private val _expirationTimerOptions = MutableStateFlow<List<RadioOption<ExpiryMode>>>(emptyList())
|
||||||
val expirationTimerOptions: StateFlow<List<ExpirationRadioOption>> = _expirationTimerOptions
|
val expirationTimerOptions: StateFlow<List<RadioOption<ExpiryMode>>> = _expirationTimerOptions
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// SETUP
|
// SETUP
|
||||||
@ -92,19 +93,23 @@ 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.map { it.copy(enabled = enabled) }
|
options.filterIsInstance<ExpirationRadioOption>().map {
|
||||||
|
it.copy(enabled = enabled)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
options.slice(1 until options.size).map { it.copy(enabled = enabled) }
|
options.slice(1 until options.size).filterIsInstance<ExpirationRadioOption>().map {
|
||||||
|
it.copy(enabled = enabled)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.launchIn(viewModelScope)
|
}.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onExpirationTypeSelected(option: ExpirationRadioOption) {
|
fun onExpirationTypeSelected(option: RadioOption<ExpiryMode>) {
|
||||||
_selectedExpirationType.value = option.value
|
_selectedExpirationType.value = option.value
|
||||||
_selectedExpirationTimer.value = _expirationTimerOptions.value.firstOrNull()
|
_selectedExpirationTimer.value = _expirationTimerOptions.value.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onExpirationTimerSelected(option: ExpirationRadioOption) {
|
fun onExpirationTimerSelected(option: RadioOption<ExpiryMode>) {
|
||||||
_selectedExpirationTimer.value = option
|
_selectedExpirationTimer.value = option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ class ClearAllDataDialog : DialogFragment() {
|
|||||||
|
|
||||||
private fun createView(): View {
|
private fun createView(): View {
|
||||||
binding = DialogClearAllDataBinding.inflate(LayoutInflater.from(requireContext()))
|
binding = DialogClearAllDataBinding.inflate(LayoutInflater.from(requireContext()))
|
||||||
val device = RadioOption("deviceOnly", requireContext().getString(R.string.dialog_clear_all_data_clear_device_only))
|
val device = StringRadioOption("deviceOnly", requireContext().getString(R.string.dialog_clear_all_data_clear_device_only))
|
||||||
val network = RadioOption("deviceAndNetwork", requireContext().getString(R.string.dialog_clear_all_data_clear_device_and_network))
|
val network = StringRadioOption("deviceAndNetwork", requireContext().getString(R.string.dialog_clear_all_data_clear_device_and_network))
|
||||||
var selectedOption = device
|
var selectedOption: RadioOption<String> = device
|
||||||
val optionAdapter = RadioOptionAdapter { selectedOption = it }
|
val optionAdapter = RadioOptionAdapter { selectedOption = it }
|
||||||
binding.recyclerView.apply {
|
binding.recyclerView.apply {
|
||||||
itemAnimator = null
|
itemAnimator = null
|
||||||
|
@ -100,4 +100,11 @@ class ExpirationRadioOption(
|
|||||||
subtitle,
|
subtitle,
|
||||||
enabled,
|
enabled,
|
||||||
contentDescription
|
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