From a6f9e1712250307b89e9969e78f25d85fc207da7 Mon Sep 17 00:00:00 2001 From: charles Date: Wed, 14 Dec 2022 13:27:35 +1100 Subject: [PATCH] Legacy settings ui tweaks --- .../expiration/ExpirationSettingsActivity.kt | 88 +++++++++++++++---- .../expiration/ExpirationSettingsViewModel.kt | 4 +- .../preferences/RadioOptionAdapter.kt | 13 ++- .../messages/ExpirationConfiguration.kt | 2 +- .../utilities/UpdateMessageBuilder.kt | 2 +- 5 files changed, 85 insertions(+), 24 deletions(-) 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 ee53e59f54..9ced182699 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 @@ -15,6 +15,7 @@ import kotlinx.coroutines.launch import network.loki.messenger.BuildConfig import network.loki.messenger.R import network.loki.messenger.databinding.ActivityExpirationSettingsBinding +import org.session.libsession.messaging.messages.ExpirationConfiguration import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.database.RecipientDatabase @@ -74,24 +75,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { } } - val deleteTypeOptions = listOf( - RadioOption(value = "-1", title = getString(R.string.expiration_off)), - RadioOption( - value = "0", - title = getString(R.string.expiration_type_disappear_legacy), - subtitle = getString(R.string.expiration_type_disappear_legacy_description) - ), - RadioOption( - value = ExpirationType.DELETE_AFTER_READ_VALUE.toString(), - title = getString(R.string.expiration_type_disappear_after_read), - subtitle = getString(R.string.expiration_type_disappear_after_read_description) - ), - RadioOption( - value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(), - title = getString(R.string.expiration_type_disappear_after_send), - subtitle = getString(R.string.expiration_type_disappear_after_send_description) - ) - ) + val deleteTypeOptions = getDeleteOptions() val deleteTypeOptionAdapter = RadioOptionAdapter { viewModel.onExpirationTypeSelected(it) } @@ -152,6 +136,74 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { } + private fun getDeleteOptions(): List { + if (!viewModel.showExpirationTypeSelector) return emptyList() + + val deleteTypeOptions = mutableListOf() + if (ExpirationConfiguration.isNewConfigEnabled) { + if (viewModel.recipient.value?.isContactRecipient == true && viewModel.recipient.value?.isLocalNumber == false) { + deleteTypeOptions.addAll( + listOf( + RadioOption(value = "-1", title = getString(R.string.expiration_off)), + RadioOption( + value = ExpirationType.DELETE_AFTER_READ_VALUE.toString(), + title = getString(R.string.expiration_type_disappear_after_read), + subtitle = getString(R.string.expiration_type_disappear_after_read_description) + ), + RadioOption( + value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(), + title = getString(R.string.expiration_type_disappear_after_send), + subtitle = getString(R.string.expiration_type_disappear_after_send_description) + ) + ) + ) + } + } else { + if (viewModel.recipient.value?.isContactRecipient == true && viewModel.recipient.value?.isLocalNumber == false) { + deleteTypeOptions.addAll( + listOf( + RadioOption(value = "-1", title = getString(R.string.expiration_off)), + RadioOption( + value = "0", + title = getString(R.string.expiration_type_disappear_legacy), + subtitle = getString(R.string.expiration_type_disappear_legacy_description) + ), + RadioOption( + value = ExpirationType.DELETE_AFTER_READ_VALUE.toString(), + title = getString(R.string.expiration_type_disappear_after_read), + subtitle = getString(R.string.expiration_type_disappear_after_read_description), + enabled = false + ), + RadioOption( + value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(), + title = getString(R.string.expiration_type_disappear_after_send), + subtitle = getString(R.string.expiration_type_disappear_after_send_description), + enabled = false + ) + ) + ) + } else { + deleteTypeOptions.addAll( + listOf( + RadioOption(value = "-1", title = getString(R.string.expiration_off)), + RadioOption( + value = "0", + title = getString(R.string.expiration_type_disappear_legacy), + subtitle = getString(R.string.expiration_type_disappear_legacy_description) + ), + RadioOption( + value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(), + title = getString(R.string.expiration_type_disappear_after_send), + subtitle = getString(R.string.expiration_type_disappear_after_send_description), + enabled = false + ) + ) + ) + } + } + 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 e36972e74a..fd35096894 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 @@ -48,7 +48,7 @@ class ExpirationSettingsViewModel( expirationConfig = storage.getExpirationConfiguration(threadId) val recipient = threadDb.getRecipientForThreadId(threadId) _recipient.value = recipient - showExpirationTypeSelector = recipient?.isContactRecipient == true && recipient.isLocalNumber == false + showExpirationTypeSelector = !ExpirationConfiguration.isNewConfigEnabled || (recipient?.isContactRecipient == true && !recipient.isLocalNumber) if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) { _selectedExpirationType.value = ExpirationType.DELETE_AFTER_SEND } else { @@ -67,7 +67,7 @@ class ExpirationSettingsViewModel( else -> emptyList() } }.onEach { options -> - _expirationTimerOptions.value = if (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true) { + _expirationTimerOptions.value = if (ExpirationConfiguration.isNewConfigEnabled && (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true)) { options } else { options.slice(1 until options.size) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt index cb6a09257c..9bb2f5880b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt @@ -47,11 +47,19 @@ class RadioOptionAdapter( val binding = ItemSelectableBinding.bind(itemView) fun bind(option: RadioOption, isSelected: Boolean, toggleSelection: (RadioOption) -> Unit) { + val alpha = if (option.enabled) 1f else 0.5f + binding.root.isEnabled = option.enabled + binding.titleTextView.alpha = alpha + binding.subtitleTextView.alpha = alpha + binding.selectButton.alpha = alpha + binding.titleTextView.text = option.title binding.subtitleTextView.text = option.subtitle binding.subtitleTextView.isVisible = !option.subtitle.isNullOrEmpty() - binding.root.setOnClickListener { toggleSelection(option) } binding.selectButton.isSelected = isSelected + if (option.enabled) { + binding.root.setOnClickListener { toggleSelection(option) } + } } } @@ -60,5 +68,6 @@ class RadioOptionAdapter( data class RadioOption( val value: String, val title: String, - val subtitle: String? = null + val subtitle: String? = null, + val enabled: Boolean = true ) diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt index 4e1f184a5e..dd2634303c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt @@ -10,6 +10,6 @@ class ExpirationConfiguration( ) { val isEnabled = durationSeconds > 0 companion object { - val isNewConfigEnabled = System.currentTimeMillis() > 1_671_062_400_000 // 15/12/2022 + val isNewConfigEnabled = System.currentTimeMillis() > 1_674_000_000_000 // 18/01/2023 } } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt index 665feda063..9469133fc8 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt @@ -95,7 +95,7 @@ object UpdateMessageBuilder { } } else { if (ExpirationConfiguration.isNewConfigEnabled) { - context.getString(R.string.MessageRecord_s_turned_off_disappearing_messages) + context.getString(R.string.MessageRecord_s_turned_off_disappearing_messages, senderName) } else { context.getString(R.string.MessageRecord_s_disabled_disappearing_messages, senderName) }