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

Add copy icon button account created screen #5141

Merged
merged 2 commits into from
Sep 27, 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 @@ -8,12 +8,12 @@ import net.mullvad.mullvadvpn.lib.common.util.groupWithSpaces
@Composable
fun AccountNumberView(
accountNumber: String,
doObfuscateWithPasswordDots: Boolean,
obfuscateWithPasswordDots: Boolean,
modifier: Modifier = Modifier
) {
InformationView(
content =
if (doObfuscateWithPasswordDots) accountNumber.groupPasswordModeWithSpaces()
if (obfuscateWithPasswordDots) accountNumber.groupPasswordModeWithSpaces()
else accountNumber.groupWithSpaces(),
modifier = modifier,
whenMissing = MissingPolicy.SHOW_SPINNER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
Expand All @@ -27,42 +29,50 @@ private fun PreviewCopyableObfuscationView() {

@Composable
fun CopyableObfuscationView(content: String) {
val context = LocalContext.current
val shouldObfuscated = remember { mutableStateOf(true) }
var obfuscationEnabled by remember { mutableStateOf(true) }

Row(
verticalAlignment = CenterVertically,
modifier = Modifier.padding(end = Dimens.sideMargin)
) {
AccountNumberView(
accountNumber = content,
doObfuscateWithPasswordDots = shouldObfuscated.value,
obfuscateWithPasswordDots = obfuscationEnabled,
modifier = Modifier.weight(1f)
)
AnimatedIconButton(
defaultIcon = painterResource(id = R.drawable.icon_hide),
secondaryIcon = painterResource(id = R.drawable.icon_show),
isToggleButton = true,
contentDescription = stringResource(id = R.string.hide_account_number),
onClick = { shouldObfuscated.value = shouldObfuscated.value.not() }
)
AnimatedIconButton(
defaultIcon = painterResource(id = R.drawable.icon_copy),
secondaryIcon = painterResource(id = R.drawable.icon_tick),
secondaryIconColorFilter =
ColorFilter.tint(color = MaterialTheme.colorScheme.inversePrimary),
isToggleButton = false,
contentDescription = stringResource(id = R.string.copy_account_number),
onClick = {
context.copyToClipboard(
content = content,
clipboardLabel = context.getString(R.string.mullvad_account_number)
)
SdkUtils.showCopyToastIfNeeded(
context,
context.getString(R.string.copied_mullvad_account_number)
)
}
onClick = { obfuscationEnabled = !obfuscationEnabled }
)

val context = LocalContext.current
val copy = {
context.copyToClipboard(
content = content,
clipboardLabel = context.getString(R.string.mullvad_account_number)
)
SdkUtils.showCopyToastIfNeeded(
context,
context.getString(R.string.copied_mullvad_account_number)
)
}

CopyAnimatedIconButton(onClick = copy)
}
}

@Composable
fun CopyAnimatedIconButton(onClick: () -> Unit) {
AnimatedIconButton(
defaultIcon = painterResource(id = R.drawable.icon_copy),
secondaryIcon = painterResource(id = R.drawable.icon_tick),
secondaryIconColorFilter =
ColorFilter.tint(color = MaterialTheme.colorScheme.inversePrimary),
isToggleButton = false,
contentDescription = stringResource(id = R.string.copy_account_number),
onClick = onClick
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarData
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -34,6 +38,7 @@ fun ScaffoldWithTopBar(
onSettingsClicked: (() -> Unit)?,
onAccountClicked: (() -> Unit)?,
isIconAndLogoVisible: Boolean = true,
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },
content: @Composable (PaddingValues) -> Unit,
) {
val systemUiController = rememberSystemUiController()
Expand All @@ -52,10 +57,21 @@ fun ScaffoldWithTopBar(
isIconAndLogoVisible = isIconAndLogoVisible
)
},
snackbarHost = {
SnackbarHost(
snackbarHostState,
snackbar = { snackbarData -> MullvadSnackbar(snackbarData = snackbarData) }
)
},
content = content
)
}

@Composable
fun MullvadSnackbar(snackbarData: SnackbarData) {
Snackbar(snackbarData = snackbarData, contentColor = MaterialTheme.colorScheme.secondary)
}

@Composable
@OptIn(ExperimentalToolbarApi::class)
fun CollapsableAwareToolbarScaffold(
Expand Down
Loading
Loading