From c492a74014e095bc7769c52fa29e66134e1f04c4 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 21 Sep 2023 00:27:10 +0930 Subject: [PATCH] Hide set button when disabled --- .../expiration/ExpirationSettings.kt | 2 +- .../expiration/ExpirationSettingsViewModel.kt | 16 ++++-- .../ExpirationSettingsViewModelTest.kt | 54 +++++++++++++++---- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettings.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettings.kt index 2d79c874e9..83f50f98af 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettings.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettings.kt @@ -67,7 +67,7 @@ fun DisappearingMessages( } } - OutlineButton( + if (state.showSetButton) OutlineButton( stringResource(R.string.expiration_settings_set_button_title), modifier = Modifier .align(Alignment.CenterHorizontally) 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 44c4d0ba46..4ffa5cdf2c 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 @@ -182,17 +182,27 @@ class ExpirationSettingsViewModel( data class UiState( val cards: List = emptyList(), - val showGroupFooter: Boolean = false + val showGroupFooter: Boolean = false, + val showSetButton: Boolean = true ) { constructor(state: State): this( cards = listOfNotNull( typeOptions(state)?.let { CardModel(GetString(R.string.activity_expiration_settings_delete_type), it) }, timeOptions(state)?.let { CardModel(GetString(R.string.activity_expiration_settings_timer), it) } ), - showGroupFooter = state.isGroup && state.isNewConfigEnabled + showGroupFooter = state.isGroup && state.isNewConfigEnabled, + showSetButton = state.isSelfAdmin ) - constructor(showGroupFooter: Boolean, vararg cards: CardModel): this(cards.asList(), showGroupFooter) + constructor( + vararg cards: CardModel, + showGroupFooter: Boolean = false, + showSetButton: Boolean = true, + ): this( + cards.asList(), + showGroupFooter, + showSetButton + ) } data class CardModel( diff --git a/app/src/test/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModelTest.kt b/app/src/test/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModelTest.kt index 4c38f5c917..d2f6e650da 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModelTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModelTest.kt @@ -83,7 +83,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_timer, typeOption(ExpiryMode.NONE, selected = true), @@ -123,7 +122,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_timer, typeOption(ExpiryMode.NONE, selected = true), @@ -136,6 +134,47 @@ class ExpirationSettingsViewModelTest { ) } + @Test + fun `group, off, admin, new config`() = runTest { + mockGroup(ExpiryMode.NONE) + + val viewModel = createViewModel() + + advanceUntilIdle() + + assertThat( + viewModel.state.value + ).isEqualTo( + State( + isGroup = true, + isSelfAdmin = false, + address = GROUP_ADDRESS, + isNoteToSelf = false, + expiryMode = ExpiryMode.NONE, + isNewConfigEnabled = true, + persistedMode = ExpiryMode.NONE, + showDebugOptions = false + ) + ) + + assertThat( + viewModel.uiState.value + ).isEqualTo( + UiState( + CardModel( + R.string.activity_expiration_settings_timer, + typeOption(ExpiryMode.NONE, enabled = false, selected = true), + timeOption(ExpiryType.AFTER_SEND, 12.hours, enabled = false), + timeOption(ExpiryType.AFTER_SEND, 1.days, enabled = false), + timeOption(ExpiryType.AFTER_SEND, 7.days, enabled = false), + timeOption(ExpiryType.AFTER_SEND, 14.days, enabled = false) + ), + showGroupFooter = true, + showSetButton = false + ) + ) + } + @Test fun `group, off, not admin, new config`() = runTest { mockGroup(ExpiryMode.NONE) @@ -163,7 +202,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = true, CardModel( R.string.activity_expiration_settings_timer, typeOption(ExpiryMode.NONE, enabled = false, selected = true), @@ -171,7 +209,9 @@ class ExpirationSettingsViewModelTest { timeOption(ExpiryType.AFTER_SEND, 1.days, enabled = false), timeOption(ExpiryType.AFTER_SEND, 7.days, enabled = false), timeOption(ExpiryType.AFTER_SEND, 14.days, enabled = false) - ) + ), + showGroupFooter = true, + showSetButton = false, ) ) } @@ -204,7 +244,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_delete_type, typeOption(ExpiryMode.NONE, selected = true), @@ -244,7 +283,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_delete_type, typeOption(ExpiryMode.NONE), @@ -291,7 +329,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_delete_type, typeOption(ExpiryMode.NONE), @@ -339,7 +376,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_delete_type, typeOption(ExpiryMode.NONE), @@ -387,7 +423,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_delete_type, typeOption(ExpiryMode.NONE), @@ -441,7 +476,6 @@ class ExpirationSettingsViewModelTest { viewModel.uiState.value ).isEqualTo( UiState( - showGroupFooter = false, CardModel( R.string.activity_expiration_settings_delete_type, typeOption(ExpiryMode.NONE),