mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Hide set button when disabled
This commit is contained in:
parent
7738b19760
commit
c492a74014
@ -67,7 +67,7 @@ fun DisappearingMessages(
|
||||
}
|
||||
}
|
||||
|
||||
OutlineButton(
|
||||
if (state.showSetButton) OutlineButton(
|
||||
stringResource(R.string.expiration_settings_set_button_title),
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterHorizontally)
|
||||
|
@ -182,17 +182,27 @@ class ExpirationSettingsViewModel(
|
||||
|
||||
data class UiState(
|
||||
val cards: List<CardModel> = 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(
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user