From 4e424384be8b8dcf5402714050bc23123c974f2b Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 31 Aug 2023 12:50:10 +0930 Subject: [PATCH] Improve routing --- .../expiration/ExpirationSettingsActivity.kt | 44 ++----------------- .../expiration/ExpirationSettingsViewModel.kt | 8 ++++ 2 files changed, 12 insertions(+), 40 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 ce193c7f72..5a4178c2af 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 @@ -53,14 +53,12 @@ import kotlinx.coroutines.launch import network.loki.messenger.R import network.loki.messenger.databinding.ActivityExpirationSettingsBinding import network.loki.messenger.libsession_util.util.ExpiryMode -import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.database.RecipientDatabase import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.ui.AppTheme import org.thoughtcrime.securesms.ui.CellNoMargin import org.thoughtcrime.securesms.ui.Divider -import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.LocalExtraColors import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider @@ -98,10 +96,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.event.collect { when (it) { - Event.SUCCESS -> { - ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity) - finish() - } + Event.SUCCESS -> finish() Event.FAIL -> showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated)) } } @@ -112,39 +107,9 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.state.collect { state -> supportActionBar?.subtitle = state.subtitle(this@ExpirationSettingsActivity) - -// val position = deleteTypeOptions.indexOfFirst { it.value == state.selectedExpirationType } -// deleteTypeOptionAdapter.setSelectedPosition(max(0, position)) } } } -// lifecycleScope.launch { -// repeatOnLifecycle(Lifecycle.State.STARTED) { -// viewModel.selectedExpirationType.collect { type -> -// val position = deleteTypeOptions.indexOfFirst { it.value == type } -// deleteTypeOptionAdapter.setSelectedPosition(max(0, position)) -// } -// } -// } -// lifecycleScope.launch { -// repeatOnLifecycle(Lifecycle.State.STARTED) { -// viewModel.selectedExpirationTimer.collect { option -> -// val position = -// viewModel.expirationTimerOptions.value.indexOfFirst { it.value == option?.value } -// timerOptionAdapter.setSelectedPosition(max(0, position)) -// } -// } -// } -// lifecycleScope.launch { -// repeatOnLifecycle(Lifecycle.State.STARTED) { -// viewModel.expirationTimerOptions.collect { options -> -// binding.textViewTimer.isVisible = -// options.isNotEmpty() && viewModel.uiState.value.showExpirationTypeSelector -// binding.layoutTimer.isVisible = options.isNotEmpty() -// timerOptionAdapter.submitList(options) -// } -// } -// } } private fun showToast(message: String) { @@ -167,7 +132,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { fun DisappearingMessagesScreen() { val uiState by viewModel.uiState.collectAsState(UiState()) AppTheme { - DisappearingMessages(uiState, onSetClick = viewModel::onSetClick) + DisappearingMessages(uiState) } } } @@ -175,8 +140,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { @Composable fun DisappearingMessages( state: UiState, - modifier: Modifier = Modifier, - onSetClick: () -> Unit = {} + modifier: Modifier = Modifier ) { val scrollState = rememberScrollState() @@ -209,7 +173,7 @@ fun DisappearingMessages( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(bottom = 20.dp), - onClick = onSetClick + onClick = state.callbacks::onSetClick ) } } 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 0aa1a9093a..65a121c699 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 @@ -1,11 +1,13 @@ package org.thoughtcrime.securesms.conversation.expiration +import android.content.Context import androidx.annotation.StringRes import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import dagger.assisted.Assisted import dagger.assisted.AssistedInject +import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -29,6 +31,7 @@ import org.thoughtcrime.securesms.database.GroupDatabase import org.thoughtcrime.securesms.database.Storage import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.ui.GetString +import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import kotlin.time.Duration import kotlin.time.Duration.Companion.days import kotlin.time.Duration.Companion.hours @@ -68,6 +71,7 @@ object NoOpCallbacks: Callbacks class ExpirationSettingsViewModel( private val threadId: Long, + private val context: Context, private val textSecurePreferences: TextSecurePreferences, private val messageExpirationManager: MessageExpirationManagerProtocol, private val threadDb: ThreadDatabase, @@ -147,6 +151,8 @@ class ExpirationSettingsViewModel( MessageSender.send(message, address) } + ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context) + _event.send(Event.SUCCESS) } @@ -158,6 +164,7 @@ class ExpirationSettingsViewModel( @Suppress("UNCHECKED_CAST") class Factory @AssistedInject constructor( @Assisted private val threadId: Long, + @ApplicationContext private val context: Context, private val textSecurePreferences: TextSecurePreferences, private val messageExpirationManager: MessageExpirationManagerProtocol, private val threadDb: ThreadDatabase, @@ -167,6 +174,7 @@ class ExpirationSettingsViewModel( override fun create(modelClass: Class): T = ExpirationSettingsViewModel( threadId, + context, textSecurePreferences, messageExpirationManager, threadDb,