diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt index 3bc8b8ef43..c249f2ae6f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt @@ -87,7 +87,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { } } - val deleteTypeOptions = getDeleteOptions() + val deleteTypeOptions = viewModel.getDeleteOptions() val deleteTypeOptionAdapter = RadioOptionAdapter { viewModel.onExpirationTypeSelected(it) } @@ -174,93 +174,6 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() } - private fun getDeleteOptions(): List { - if (!viewModel.uiState.value.showExpirationTypeSelector) return emptyList() - - val deleteTypeOptions = mutableListOf() - if (ExpirationConfiguration.isNewConfigEnabled) { - if (viewModel.recipient.value?.isContactRecipient == true && viewModel.recipient.value?.isLocalNumber == false) { - deleteTypeOptions.addAll( - listOf( - radioOption(ExpiryMode.NONE, R.string.expiration_off) { - contentDescription(R.string.AccessibilityId_disable_disappearing_messages) - }, - radioOption(ExpiryMode.AfterRead(0), R.string.expiration_type_disappear_after_read) { - subtitle(R.string.expiration_type_disappear_after_read_description) - contentDescription(R.string.AccessibilityId_disappear_after_read_option) - }, - radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { - subtitle(R.string.expiration_type_disappear_after_send_description) - contentDescription(R.string.AccessibilityId_disappear_after_send_option) - } - ) - ) - } else if (viewModel.recipient.value?.isLocalNumber == true) { - deleteTypeOptions.addAll( - listOf( - radioOption(ExpiryMode.NONE, R.string.expiration_off) { - contentDescription(R.string.AccessibilityId_disable_disappearing_messages) - }, - radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { - subtitle(R.string.expiration_type_disappear_after_send_description) - contentDescription(R.string.AccessibilityId_disappear_after_send_option) - } - ) - ) - } else if (viewModel.recipient.value?.isClosedGroupRecipient == true) { - deleteTypeOptions.addAll( - listOf( - radioOption(ExpiryMode.NONE, R.string.expiration_off) { - contentDescription(R.string.AccessibilityId_disable_disappearing_messages) - }, - radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { - subtitle(R.string.expiration_type_disappear_after_send_description) - contentDescription(R.string.AccessibilityId_disappear_after_send_option) - } - ) - ) - } - } else { - if (viewModel.recipient.value?.isContactRecipient == true && viewModel.recipient.value?.isLocalNumber == false) { - deleteTypeOptions.addAll( - listOf( - radioOption(ExpiryMode.NONE, R.string.expiration_off) { - contentDescription(R.string.AccessibilityId_disable_disappearing_messages) - }, - radioOption(ExpiryMode.Legacy(0), R.string.expiration_type_disappear_legacy) { - subtitle(R.string.expiration_type_disappear_legacy_description) - }, - radioOption(ExpiryMode.AfterRead(0), R.string.expiration_type_disappear_after_read) { - subtitle(R.string.expiration_type_disappear_after_read_description) - enabled = false - contentDescription(R.string.AccessibilityId_disappear_after_read_option) - }, - radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { - subtitle(R.string.expiration_type_disappear_after_send_description) - enabled = false - contentDescription(R.string.AccessibilityId_disappear_after_send_option) - } - ) - ) - } else { - deleteTypeOptions.addAll( - listOf( - radioOption(ExpiryMode.NONE, R.string.expiration_off), - radioOption(ExpiryMode.Legacy(0), R.string.expiration_type_disappear_legacy) { - subtitle(R.string.expiration_type_disappear_legacy_description) - }, - radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { - subtitle(R.string.expiration_type_disappear_after_send_description) - enabled = false - contentDescription(R.string.AccessibilityId_disappear_after_send_option) - } - ) - ) - } - } - return deleteTypeOptions - } - private fun setUpToolbar() { setSupportActionBar(binding.toolbar) val actionBar = supportActionBar ?: return diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt index 394ad5316e..d2fdf0762d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import network.loki.messenger.R import network.loki.messenger.libsession_util.util.ExpiryMode import org.session.libsession.messaging.messages.ExpirationConfiguration import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate @@ -26,6 +27,7 @@ import org.thoughtcrime.securesms.database.Storage import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.preferences.ExpirationRadioOption import org.thoughtcrime.securesms.preferences.RadioOption +import org.thoughtcrime.securesms.preferences.radioOption import kotlin.reflect.KClass @OptIn(ExperimentalCoroutinesApi::class) @@ -150,6 +152,85 @@ class ExpirationSettingsViewModel( } } + fun getDeleteOptions(): List { + if (!uiState.value.showExpirationTypeSelector) return emptyList() + + val recipient = recipient.value + + return if (ExpirationConfiguration.isNewConfigEnabled) { + if (recipient?.isContactRecipient == true && !recipient.isLocalNumber) contactRecipientOptions() + else if (recipient?.isLocalNumber == true) noteToSelfOptions() + else if (recipient?.isClosedGroupRecipient == true) closedGroupRecipientOptions() + else emptyList() + } else if (recipient?.isContactRecipient == true && !recipient.isLocalNumber) oldConfigContactRecipientOptions() + else oldConfigDefaultOptions() + } + + private fun oldConfigDefaultOptions() = listOf( + radioOption(ExpiryMode.NONE, R.string.expiration_off), + radioOption(ExpiryMode.Legacy(0), R.string.expiration_type_disappear_legacy) { + subtitle(R.string.expiration_type_disappear_legacy_description) + }, + radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { + subtitle(R.string.expiration_type_disappear_after_send_description) + enabled = false + contentDescription(R.string.AccessibilityId_disappear_after_send_option) + } + ) + + private fun oldConfigContactRecipientOptions() = listOf( + radioOption(ExpiryMode.NONE, R.string.expiration_off) { + contentDescription(R.string.AccessibilityId_disable_disappearing_messages) + }, + radioOption(ExpiryMode.Legacy(0), R.string.expiration_type_disappear_legacy) { + subtitle(R.string.expiration_type_disappear_legacy_description) + }, + radioOption(ExpiryMode.AfterRead(0), R.string.expiration_type_disappear_after_read) { + subtitle(R.string.expiration_type_disappear_after_read_description) + enabled = false + contentDescription(R.string.AccessibilityId_disappear_after_read_option) + }, + radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { + subtitle(R.string.expiration_type_disappear_after_send_description) + enabled = false + contentDescription(R.string.AccessibilityId_disappear_after_send_option) + } + ) + + private fun contactRecipientOptions() = listOf( + radioOption(ExpiryMode.NONE, R.string.expiration_off) { + contentDescription(R.string.AccessibilityId_disable_disappearing_messages) + }, + radioOption(ExpiryMode.AfterRead(0), R.string.expiration_type_disappear_after_read) { + subtitle(R.string.expiration_type_disappear_after_read_description) + contentDescription(R.string.AccessibilityId_disappear_after_read_option) + }, + radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { + subtitle(R.string.expiration_type_disappear_after_send_description) + contentDescription(R.string.AccessibilityId_disappear_after_send_option) + } + ) + + private fun closedGroupRecipientOptions() = listOf( + radioOption(ExpiryMode.NONE, R.string.expiration_off) { + contentDescription(R.string.AccessibilityId_disable_disappearing_messages) + }, + radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { + subtitle(R.string.expiration_type_disappear_after_send_description) + contentDescription(R.string.AccessibilityId_disappear_after_send_option) + } + ) + + private fun noteToSelfOptions() = listOf( + radioOption(ExpiryMode.NONE, R.string.expiration_off) { + contentDescription(R.string.AccessibilityId_disable_disappearing_messages) + }, + radioOption(ExpiryMode.AfterSend(0), R.string.expiration_type_disappear_after_send) { + subtitle(R.string.expiration_type_disappear_after_send_description) + contentDescription(R.string.AccessibilityId_disappear_after_send_option) + } + ) + @dagger.assisted.AssistedFactory interface AssistedFactory { fun create(