Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dialog for max accounts reached (WPB-1862) #2526

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import com.wire.android.ui.common.WireDialogButtonProperties
import com.wire.android.ui.common.WireDialogButtonType
import com.wire.android.ui.common.dialogs.CustomServerDialog
import com.wire.android.ui.common.dialogs.CustomServerDialogState
import com.wire.android.ui.common.dialogs.MaxAccountAllowedDialogContent
import com.wire.android.ui.common.wireDialogPropertiesBuilder
import com.wire.android.ui.destinations.ConversationScreenDestination
import com.wire.android.ui.home.messagecomposer.SelfDeletionDuration
import com.wire.android.ui.joinConversation.JoinConversationViaCodeState
import com.wire.android.ui.joinConversation.JoinConversationViaDeepLinkDialog
import com.wire.android.ui.joinConversation.JoinConversationViaInviteLinkError
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.userprofile.self.MaxAccountReachedDialog
import com.wire.android.util.formatMediumDateTime
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.UIText
Expand Down Expand Up @@ -231,7 +231,7 @@ fun CustomBackendDialog(
@Composable
fun MaxAccountDialog(shouldShow: Boolean, onConfirm: () -> Unit, onDismiss: () -> Unit) {
if (shouldShow) {
MaxAccountReachedDialog(
MaxAccountAllowedDialogContent(
onConfirm = onConfirm,
onDismiss = onDismiss,
buttonText = R.string.max_account_reached_dialog_button_open_profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import com.wire.android.ui.common.button.WirePrimaryButton
import com.wire.android.ui.common.button.WireSecondaryButton
import com.wire.android.ui.common.dialogs.FeatureDisabledWithProxyDialogContent
import com.wire.android.ui.common.dialogs.FeatureDisabledWithProxyDialogState
import com.wire.android.ui.common.dialogs.MaxAccountsReachedDialogContent
import com.wire.android.ui.common.dialogs.MaxAccountsReachedDialog
import com.wire.android.ui.common.dialogs.MaxAccountsReachedDialogState
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.topappbar.NavigationIconType
Expand Down Expand Up @@ -152,7 +152,7 @@ private fun WelcomeContent(
.padding(internalPadding)
) {
val maxAccountsReachedDialogState = rememberVisibilityState<MaxAccountsReachedDialogState>()
MaxAccountsReachedDialogContent(maxAccountsReachedDialogState) { navigateBack() }
MaxAccountsReachedDialog(dialogState = maxAccountsReachedDialogState) { navigateBack() }
if (maxAccountsReached) {
maxAccountsReachedDialogState.show(maxAccountsReachedDialogState.savedState ?: MaxAccountsReachedDialogState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,68 @@

package com.wire.android.ui.common.dialogs

import androidx.annotation.PluralsRes
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.window.DialogProperties
import com.wire.android.BuildConfig
import com.wire.android.R
import com.wire.android.ui.common.VisibilityState
import com.wire.android.ui.common.WireDialog
import com.wire.android.ui.common.WireDialogButtonProperties
import com.wire.android.ui.common.WireDialogButtonType
import com.wire.android.ui.common.visbility.VisibilityState
import com.wire.android.ui.common.wireDialogPropertiesBuilder
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.ui.PreviewMultipleThemes

// todo: parametrize the dialog with the number of accounts using BuildConfig
@Composable
fun MaxAccountsReachedDialogContent(
fun MaxAccountsReachedDialog(
dialogState: VisibilityState<MaxAccountsReachedDialogState>,
onActionButtonClicked: () -> Unit
onActionButtonClicked: () -> Unit,
) {
VisibilityState(dialogState) { state ->
WireDialog(
title = stringResource(id = R.string.max_account_reached_dialog_title),
text = stringResource(id = R.string.max_account_reached_dialog_message),
VisibilityState(dialogState) { _ ->
MaxAccountAllowedDialogContent(
onConfirm = onActionButtonClicked,
onDismiss = dialogState::dismiss,
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(R.string.label_ok),
onClick = onActionButtonClicked,
type = WireDialogButtonType.Primary
),
properties = wireDialogPropertiesBuilder(
buttonText = R.string.label_ok,
dialogProperties = wireDialogPropertiesBuilder(
dismissOnBackPress = false,
dismissOnClickOutside = false
)
)
}
}

@Composable
fun MaxAccountAllowedDialogContent(
maxAccountsAllowed: Int = BuildConfig.MAX_ACCOUNTS,
@PluralsRes title: Int = R.plurals.max_account_reached_dialog_title,
@PluralsRes message: Int = R.plurals.max_account_reached_dialog_message,
@StringRes buttonText: Int,
dialogProperties: DialogProperties = DialogProperties(usePlatformDefaultWidth = false),
onConfirm: () -> Unit,
onDismiss: () -> Unit,
) {
WireDialog(
title = pluralStringResource(title, maxAccountsAllowed, maxAccountsAllowed),
text = pluralStringResource(message, maxAccountsAllowed, maxAccountsAllowed),
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(buttonText),
onClick = onConfirm,
type = WireDialogButtonType.Primary
),
properties = dialogProperties
)
}

@PreviewMultipleThemes
@Composable
fun PreviewMaxAccountReachedDialogWithOkButton() {
WireTheme {
MaxAccountAllowedDialogContent(onConfirm = { }, onDismiss = { }, buttonText = R.string.label_ok)
}
}

This file was deleted.

10 changes: 8 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,14 @@
<string name="unblock_user_dialog_body">%1$s will be able to contact you or add you to group conversations. You will be able to access a 1:1 conversation with them.</string>
<string name="unblock_user_dialog_confirm_button">Unblock</string>
<!--max account reached dialog-->
<string name="max_account_reached_dialog_title">Three accounts active</string>
<string name="max_account_reached_dialog_message">You can only be logged in with three accounts at once. Log out from one to add another.</string>
<plurals name="max_account_reached_dialog_title">
<item quantity="one">one account active</item>
<item quantity="other">%1$d accounts active</item>
</plurals>
<plurals name="max_account_reached_dialog_message">
<item quantity="one">You can only be logged in with one account at once. Log out from one to add another.</item>
<item quantity="other">You can only be logged in with %1$d accounts at once. Log out from one to add another.</item>
</plurals>
<string name="max_account_reached_dialog_button_open_profile">Open Profile</string>
<string name="cant_switch_account_in_call">You can\'t switch accounts while in a call</string>
<string name="custom_backend_dialog_title">Redirect to an on-premises backend?</string>
Expand Down
Loading