From 63f372b45c0a4223f5a776ad2db8a00221cb774c Mon Sep 17 00:00:00 2001 From: charles Date: Wed, 26 Oct 2022 19:27:22 +1100 Subject: [PATCH] Add expiration settings screen --- app/src/main/AndroidManifest.xml | 3 + .../expiration/ExpirationSettingsActivity.kt | 96 +++++++++++++++ .../conversation/v2/ConversationActivityV2.kt | 18 ++- .../layout/activity_expiration_settings.xml | 113 ++++++++++++++++++ app/src/main/res/values/arrays.xml | 36 ++++++ app/src/main/res/values/strings.xml | 15 +++ app/src/main/res/values/styles.xml | 4 + 7 files changed, 274 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt create mode 100644 app/src/main/res/layout/activity_expiration_settings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 681fc00c17..16a4418724 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -172,6 +172,9 @@ android:screenOrientation="portrait" /> + () + binding.scrollView.saveHierarchyState(scrollParcelArray) + outState.putSparseParcelableArray(SCROLL_PARCEL, scrollParcelArray) + } + + override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) { + super.onCreate(savedInstanceState, ready) + binding = ActivityExpirationSettingsBinding.inflate(layoutInflater) + setContentView(binding.root) + + setUpToolbar() + + savedInstanceState?.let { bundle -> + val scrollStateParcel = bundle.getSparseParcelableArray(SCROLL_PARCEL) + if (scrollStateParcel != null) { + binding.scrollView.restoreHierarchyState(scrollStateParcel) + } + } + + val options = if (expirationType == ExpirationType.DELETE_AFTER_SEND) { + val values = resources.getIntArray(R.array.send_expiration_time_values).map(Int::toString) + val names = resources.getStringArray(R.array.send_expiration_time_names) + values.zip(names) { value, name -> RadioOption(value, name)} + } else { + listOf( + RadioOption("off", getString(R.string.expiration_off)), + RadioOption("read", getString(R.string.expiration_type_disappear_after_read)), + RadioOption("send", getString(R.string.expiration_type_disappear_after_send)) + ) + } + val optionAdapter = RadioOptionAdapter { + + } + binding.textViewDeleteType.isVisible = expirationType == null + binding.textViewTimer.isVisible = expirationType == null + binding.layoutTimer.isVisible = expirationType == null + binding.recyclerView.apply { + adapter = optionAdapter + addItemDecoration(ContextCompat.getDrawable(this@ExpirationSettingsActivity, R.drawable.conversation_menu_divider)!!.let { + DividerItemDecoration(this@ExpirationSettingsActivity, RecyclerView.VERTICAL).apply { + setDrawable(it) + } + }) + setHasFixedSize(true) + } + optionAdapter.submitList(options) + + } + + private fun setUpToolbar() { + setSupportActionBar(binding.toolbar) + val actionBar = supportActionBar ?: return + actionBar.title = getString(R.string.activity_expiration_settings_title) + actionBar.subtitle = if (expirationType == ExpirationType.DELETE_AFTER_SEND) { + getString(R.string.activity_expiration_settings_subtitle_sent) + } else { + getString(R.string.activity_expiration_settings_subtitle) + } + actionBar.setDisplayHomeAsUpEnabled(true) + actionBar.setHomeButtonEnabled(true) + } + companion object { + private const val SCROLL_PARCEL = "scroll_parcel" + const val EXTRA_EXPIRATION_TYPE = "expiration_type" + const val EXTRA_READ_ONLY = "read_only" + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 7fe583ddbc..685939c4ad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -56,7 +56,6 @@ import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.mentions.Mention import org.session.libsession.messaging.mentions.MentionsManager import org.session.libsession.messaging.messages.control.DataExtractionNotification -import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate import org.session.libsession.messaging.messages.signal.OutgoingMediaMessage import org.session.libsession.messaging.messages.signal.OutgoingTextMessage import org.session.libsession.messaging.messages.visible.Reaction @@ -78,18 +77,19 @@ import org.session.libsession.utilities.concurrent.SimpleTask import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.RecipientModifiedListener import org.session.libsignal.crypto.MnemonicCodec +import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType import org.session.libsignal.utilities.IdPrefix import org.session.libsignal.utilities.ListenableFuture import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.guava.Optional import org.session.libsignal.utilities.hexEncodedPrivateKey import org.thoughtcrime.securesms.ApplicationContext -import org.thoughtcrime.securesms.ExpirationDialog import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.attachments.ScreenshotObserver import org.thoughtcrime.securesms.audio.AudioRecorder import org.thoughtcrime.securesms.contacts.SelectContactsActivity.Companion.selectedContactsKey import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher +import org.thoughtcrime.securesms.conversation.expiration.ExpirationSettingsActivity import org.thoughtcrime.securesms.conversation.v2.ConversationReactionOverlay.OnActionSelectedListener import org.thoughtcrime.securesms.conversation.v2.ConversationReactionOverlay.OnReactionSelectedListener import org.thoughtcrime.securesms.conversation.v2.dialogs.BlockedDialog @@ -154,6 +154,7 @@ import org.thoughtcrime.securesms.util.DateUtils import org.thoughtcrime.securesms.util.MediaUtil import org.thoughtcrime.securesms.util.SaveAttachmentTask import org.thoughtcrime.securesms.util.push +import org.thoughtcrime.securesms.util.show import org.thoughtcrime.securesms.util.toPx import java.util.Locale import java.util.concurrent.ExecutionException @@ -988,16 +989,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val group = groupDb.getGroup(thread.address.toGroupString()).orNull() if (group?.isActive == false) { return } } - ExpirationDialog.show(this, thread.expireMessages) { expirationTime: Int -> - recipientDb.setExpireMessages(thread, expirationTime) - val message = ExpirationTimerUpdate(expirationTime) - message.recipient = thread.address.serialize() - message.sentTimestamp = System.currentTimeMillis() - val expiringMessageManager = ApplicationContext.getInstance(this).expiringMessageManager - expiringMessageManager.setExpirationTimer(message) - MessageSender.send(message, thread.address) - invalidateOptionsMenu() + val expirationIntent = Intent(this, ExpirationSettingsActivity::class.java) + if (thread.isLocalNumber || thread.isClosedGroupRecipient) { + expirationIntent.putExtra(ExpirationSettingsActivity.EXTRA_EXPIRATION_TYPE, ExpirationType.DELETE_AFTER_SEND_VALUE) } + show(expirationIntent, true) } override fun unblock() { diff --git a/app/src/main/res/layout/activity_expiration_settings.xml b/app/src/main/res/layout/activity_expiration_settings.xml new file mode 100644 index 0000000000..59d62fcc5c --- /dev/null +++ b/app/src/main/res/layout/activity_expiration_settings.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +