arblant
FoxyVPN-MultiAcc / app / src / main / java / com / vauth / foxyvpn / ui / screens / AccountHelp.kt
AccountHelp.kt149 lines · 5.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
package com.vauth.foxyvpn.ui.screens

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
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
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.vauth.foxyvpn.ui.l10n.s

const val FIREFOX_SIGNUP_URL = "https://accounts.firefox.com/signup"

/**
 * Help row for the sign-in / add-account surfaces: a "Create Firefox
 * account" link (opens the FxA signup page in the browser) and the
 * Gmail dot-method explainer.
 */
@Composable
fun AccountHelpRow(modifier: Modifier = Modifier) {
    val uriHandler = LocalUriHandler.current
    var showDotMethod by remember { mutableStateOf(false) }

    Row(
        modifier = modifier.fillMaxWidth(),
        horizontalArrangement = Arrangement.SpaceEvenly,
    ) {
        TextButton(onClick = { uriHandler.openUri(FIREFOX_SIGNUP_URL) }) {
            Text(s("Create Firefox account"))
        }
        TextButton(onClick = { showDotMethod = true }) {
            Text(s("Dot method"))
        }
    }

    if (showDotMethod) {
        DotMethodDialog(onDismiss = { showDotMethod = false })
    }
}

@Composable
private fun DotMethodDialog(onDismiss: () -> Unit) {
    val uriHandler = LocalUriHandler.current
    AlertDialog(
        onDismissRequest = onDismiss,
        title = { Text(s("One Gmail, many accounts")) },
        text = {
            Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
                Text(
                    s("Gmail ignores the dots in your address: a.b@gmail.com and ab@gmail.com are the same inbox."),
                    style = MaterialTheme.typography.bodyMedium,
                )
                Text(
                    s("For a Firefox signup, each dotted variation counts as a brand-new email address — but every verification email arrives in that same one inbox."),
                    style = MaterialTheme.typography.bodyMedium,
                )
                DotMethodStep(
                    number = 1,
                    text = s("Create a Firefox account with a new dotted variation of your Gmail address."),
                )
                DotMethodStep(
                    number = 2,
                    text = s("Open the verification email in your one inbox and confirm it, or note the code."),
                )
                DotMethodStep(
                    number = 3,
                    text = s("Come back here and add the account. Repeat for more accounts."),
                )
                Surface(
                    shape = RoundedCornerShape(12.dp),
                    color = MaterialTheme.colorScheme.surfaceVariant,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Column(Modifier.padding(12.dp)) {
                        Text(s("Example"), style = MaterialTheme.typography.labelMedium)
                        Spacer(Modifier.padding(top = 4.dp))
                        Text(
                            "name@gmail.com",
                            style = MaterialTheme.typography.bodySmall,
                            fontFamily = FontFamily.Monospace,
                        )
                        Text(
                            "n.ame@gmail.com · na.me@gmail.com · nam.e@gmail.com",
                            style = MaterialTheme.typography.bodySmall,
                            fontFamily = FontFamily.Monospace,
                            color = MaterialTheme.colorScheme.onSurfaceVariant,
                        )
                    }
                }
            }
        },
        confirmButton = {
            TextButton(onClick = { uriHandler.openUri(FIREFOX_SIGNUP_URL) }) {
                Text(s("Create Firefox account"))
            }
        },
        dismissButton = {
            TextButton(onClick = onDismiss) {
                Text(s("Close"))
            }
        },
    )
}

@Composable
private fun DotMethodStep(number: Int, text: String) {
    Row(verticalAlignment = Alignment.Top) {
        Box(
            modifier = Modifier
                .size(22.dp)
                .background(MaterialTheme.colorScheme.primary, CircleShape),
            contentAlignment = Alignment.Center,
        ) {
            Text(
                number.toString(),
                style = MaterialTheme.typography.labelSmall,
                color = MaterialTheme.colorScheme.onPrimary,
                textAlign = TextAlign.Center,
            )
        }
        Spacer(Modifier.width(10.dp))
        Text(
            text,
            style = MaterialTheme.typography.bodyMedium,
            modifier = Modifier.weight(1f),
        )
    }
}