Skip to content

Commit

Permalink
Merge branch 'add-copy-icon-button-account-created-screen-droid-316'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Sep 27, 2023
2 parents dab08e9 + d6adb5a commit 6541297
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 162 deletions.
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

0 comments on commit 6541297

Please sign in to comment.