Composables
Docs Login
Vela

Profile

package com.composables.vela

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
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.draw.clip
import androidx.compose.ui.unit.dp
import com.composables.vela.components.AlertDialog
import com.composables.vela.components.Avatar
import com.composables.vela.components.Button
import com.composables.vela.components.ButtonVariant
import com.composables.vela.components.Icon
import com.composables.vela.components.IconButton
import com.composables.vela.components.IconButtonSize
import com.composables.vela.components.OptionRow
import com.composables.vela.components.OptionToggle
import com.composables.vela.components.Page
import com.composables.vela.components.Section
import com.composables.vela.components.Text
import com.composables.vela.components.TextField
import com.composables.vela.components.Toast
import com.composables.vela.theme.Bell
import com.composables.vela.theme.CrownSimple
import com.composables.vela.theme.DeviceMobile
import com.composables.vela.theme.DownloadSimple
import com.composables.vela.theme.Icons
import com.composables.vela.theme.LockSimple
import com.composables.vela.theme.SignOut
import com.composables.vela.theme.Space
import com.composables.vela.theme.Sparkle
import com.composables.vela.theme.Theme
import com.composables.vela.theme.Trash
import com.composables.vela.theme.User
import com.composables.vela.theme.Waveform
import com.composables.vela.theme.X
import kotlinx.coroutines.delay

@Composable
fun SettingsScreen(
    navigateBack: () -> Unit,
    navigateToProfile: () -> Unit,
    navigateToPersonalisation: () -> Unit,
    navigateToNotifications: () -> Unit,
    navigateToPrivacy: () -> Unit,
    navigateToUpgrade: () -> Unit,
    navigateToWelcome: () -> Unit,
    modifier: Modifier = Modifier,
) {
    fun signOut() {
        // sign out here
        navigateToWelcome()
    }

    val voice = rememberVoicePreferences()
    var showVoice by remember { mutableStateOf(false) }
    var haptics by remember { mutableStateOf(true) }
    var showSignOut by remember { mutableStateOf(false) }
    Page(
        title = "Settings",
        onBack = navigateBack,
        backIcon = Icons.X,
        backLabel = "Close",
        modifier = modifier,
        overlay = {
            VoiceSettingsSheet(
                visible = showVoice,
                onDismiss = { showVoice = false },
                preferences = voice,
            )
            AlertDialog(
                visible = showSignOut,
                title = "Sign out of Vela?",
                message = "Your chats stay in your account for when you sign back in.",
                onDismissRequest = { showSignOut = false },
            ) {
                Button(
                    onClick = {
                        showSignOut = false
                        signOut()
                    },
                    variant = ButtonVariant.Destructive,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Sign out")
                }
                Button(
                    onClick = { showSignOut = false },
                    variant = ButtonVariant.Secondary,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Cancel")
                }
            }
        },
    ) {
        Row(
            Modifier.fillMaxWidth().padding(horizontal = Space * 4),
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.spacedBy(Space * 3),
        ) {
            Avatar(Account.nickname)
            Column(Modifier.weight(1f)) {
                Text(Account.name, style = Theme.typography.title)
                Text(Account.email, color = Theme.colors.onBackgroundMuted)
            }
        }
        UpgradeCard(onUpgrade = navigateToUpgrade)
        Section("Account") {
            OptionRow("Profile", onClick = navigateToProfile, icon = Icons.User, navigates = true)
            OptionRow(
                "Personalisation and memory",
                onClick = navigateToPersonalisation,
                icon = Icons.Sparkle,
                navigates = true,
            )
            OptionRow(
                "Notifications",
                onClick = navigateToNotifications,
                icon = Icons.Bell,
                navigates = true,
            )
            OptionRow(
                "Privacy and data",
                onClick = navigateToPrivacy,
                icon = Icons.LockSimple,
                navigates = true,
            )
        }
        Section("App") {
            OptionRow(
                "Voice",
                onClick = { showVoice = true },
                icon = Icons.Waveform,
                value = voice.voice.name,
                navigates = true,
            )
            OptionToggle("Haptic feedback", haptics, { haptics = it }, icon = Icons.DeviceMobile)
        }
        Section(null, footer = "Vela 1.0") {
            OptionRow("Sign out", onClick = { showSignOut = true }, icon = Icons.SignOut)
        }
    }
}

@Composable
private fun UpgradeCard(onUpgrade: () -> Unit) {
    Column(
        Modifier.fillMaxWidth()
            .clip(Theme.shapes.medium)
            .background(Theme.colors.surface)
            .padding(Space * 4),
        verticalArrangement = Arrangement.spacedBy(Space * 3),
    ) {
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.spacedBy(Space * 2),
        ) {
            Icon(
                Icons.CrownSimple,
                contentDescription = null,
                modifier = Modifier.size(20.dp),
                tint = Theme.colors.primary,
            )
            Text("Free plan", style = Theme.typography.label)
        }
        Text(
            "Upgrade for more messages, Vela 4 Pro and projects.",
            color = Theme.colors.onBackgroundMuted,
        )
        Button(onClick = onUpgrade) { Text("Upgrade") }
    }
}

@Composable
fun ProfileScreen(
    navigateBack: () -> Unit,
    navigateToWelcome: () -> Unit,
    modifier: Modifier = Modifier,
) {
    fun deleteAccount() {
        // delete the account here
        navigateToWelcome()
    }

    var name by remember { mutableStateOf(Account.name) }
    var nickname by remember { mutableStateOf(Account.nickname) }
    var showDelete by remember { mutableStateOf(false) }
    Page(
        title = "Profile",
        onBack = navigateBack,
        modifier = modifier,
        overlay = {
            AlertDialog(
                visible = showDelete,
                title = "Delete your account?",
                message = "This deletes your chats, projects and memories. It can't be undone.",
                onDismissRequest = { showDelete = false },
            ) {
                Button(
                    onClick = {
                        showDelete = false
                        deleteAccount()
                    },
                    variant = ButtonVariant.Destructive,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Delete account")
                }
                Button(
                    onClick = { showDelete = false },
                    variant = ButtonVariant.Secondary,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Cancel")
                }
            }
        },
    ) {
        LabelledField("Full name") { TextField(name, { name = it }, label = "Full name") }
        LabelledField("What should Vela call you?", note = "Used in greetings and answers.") {
            TextField(nickname, { nickname = it }, label = "Nickname")
        }
        LabelledField("Email", note = "Sign-in codes are sent here.") {
            Text(
                Account.email,
                modifier =
                    Modifier.fillMaxWidth()
                        .clip(Theme.shapes.small)
                        .background(Theme.colors.surfaceVariant)
                        .padding(horizontal = Space * 4, vertical = Space * 3),
            )
        }
        Section(null) {
            OptionRow(
                "Delete account",
                onClick = { showDelete = true },
                icon = Icons.Trash,
                destructive = true,
            )
        }
    }
}

@Composable
internal fun LabelledField(label: String, note: String? = null, field: @Composable () -> Unit) {
    Column(verticalArrangement = Arrangement.spacedBy(Space * 2)) {
        Text(
            label,
            style = Theme.typography.caption,
            color = Theme.colors.onBackgroundMuted,
            modifier = Modifier.padding(horizontal = Space * 4),
        )
        field()
        if (note != null)
            Text(
                note,
                style = Theme.typography.caption,
                color = Theme.colors.onBackgroundMuted,
                modifier = Modifier.padding(horizontal = Space * 4),
            )
    }
}

@Composable
fun PersonalisationScreen(
    navigateBack: () -> Unit,
    modifier: Modifier = Modifier,
) {
    var instructions by remember {
        mutableStateOf(
            "Keep answers short and lead with a summary. I'm in Lisbon, so use metric units."
        )
    }
    var useMemories by remember { mutableStateOf(true) }
    var useHistory by remember { mutableStateOf(true) }
    val memories = remember { mutableStateListOf(*sampleMemories.toTypedArray()) }
    var showForgetAll by remember { mutableStateOf(false) }
    Page(
        title = "Personalisation",
        onBack = navigateBack,
        modifier = modifier,
        overlay = {
            AlertDialog(
                visible = showForgetAll,
                title = "Forget all memories?",
                message =
                    "Vela will stop using what it has learned about you. Your chats are not deleted.",
                onDismissRequest = { showForgetAll = false },
            ) {
                Button(
                    onClick = {
                        showForgetAll = false
                        memories.clear()
                    },
                    variant = ButtonVariant.Destructive,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Forget all")
                }
                Button(
                    onClick = { showForgetAll = false },
                    variant = ButtonVariant.Secondary,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Cancel")
                }
            }
        },
    ) {
        LabelledField("How should Vela respond?", note = "Applies to new chats.") {
            TextField(
                instructions,
                { instructions = it },
                label = "Custom instructions",
                minLines = 4,
            )
        }
        Section("Memory") {
            OptionToggle(
                "Use saved memories",
                useMemories,
                { useMemories = it },
                description = "Vela remembers useful details you share",
            )
            OptionToggle(
                "Use chat history",
                useHistory,
                { useHistory = it },
                description = "Vela can refer to your recent chats",
            )
        }
        Section(
            "Saved memories",
            footer = if (memories.isEmpty()) "Vela hasn't saved anything yet." else null,
        ) {
            memories.forEach { memory ->
                Row(
                    Modifier.fillMaxWidth()
                        .padding(start = Space * 4, end = Space * 2, top = Space, bottom = Space),
                    verticalAlignment = Alignment.CenterVertically,
                ) {
                    Text(memory, modifier = Modifier.weight(1f))
                    IconButton(
                        onClick = { memories.remove(memory) },
                        contentDescription = "Forget “$memory”",
                        size = IconButtonSize.Small,
                    ) {
                        Icon(
                            Icons.X,
                            contentDescription = null,
                            modifier = Modifier.size(16.dp),
                            tint = Theme.colors.onBackgroundMuted,
                        )
                    }
                }
            }
        }
        if (memories.isNotEmpty()) {
            Section(null) {
                OptionRow(
                    "Forget all memories",
                    onClick = { showForgetAll = true },
                    icon = Icons.Trash,
                    destructive = true,
                )
            }
        }
    }
}

@Composable
fun NotificationSettingsScreen(
    navigateBack: () -> Unit,
    modifier: Modifier = Modifier,
) {
    var responses by remember { mutableStateOf(true) }
    var tasks by remember { mutableStateOf(true) }
    var updates by remember { mutableStateOf(false) }
    Page(title = "Notifications", onBack = navigateBack, modifier = modifier) {
        Section("Chats", footer = "Only for answers that finish while Vela is in the background.") {
            OptionToggle(
                "Finished responses",
                responses,
                { responses = it },
                description = "When a long answer is ready",
            )
            OptionToggle(
                "Reminders you ask for",
                tasks,
                { tasks = it },
                description = "Such as “remind me at six”",
            )
        }
        Section("From Vela") {
            OptionToggle(
                "Product updates",
                updates,
                { updates = it },
                description = "New models and features, a few times a year",
            )
        }
    }
}

@Composable
fun PrivacyScreen(
    navigateBack: () -> Unit,
    modifier: Modifier = Modifier,
) {
    fun exportData() {
        // request a copy of the person's data here
    }

    fun deleteAllChats() {
        // delete every chat here
    }

    var improve by remember { mutableStateOf(false) }
    var history by remember { mutableStateOf(true) }
    var showDelete by remember { mutableStateOf(false) }
    var toast by remember { mutableStateOf<String?>(null) }
    LaunchedEffect(toast) {
        if (toast != null) {
            delay(2000)
            toast = null
        }
    }
    Page(
        title = "Privacy and data",
        onBack = navigateBack,
        modifier = modifier,
        overlay = {
            Toast(
                toast != null,
                toast.orEmpty(),
                Modifier.align(Alignment.TopCenter).padding(top = 96.dp),
            )
            AlertDialog(
                visible = showDelete,
                title = "Delete all chats?",
                message =
                    "Every chat, including those in projects, is deleted. Projects, files and memories stay.",
                onDismissRequest = { showDelete = false },
            ) {
                Button(
                    onClick = {
                        showDelete = false
                        deleteAllChats()
                        toast = "All chats deleted"
                    },
                    variant = ButtonVariant.Destructive,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Delete all")
                }
                Button(
                    onClick = { showDelete = false },
                    variant = ButtonVariant.Secondary,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    Text("Cancel")
                }
            }
        },
    ) {
        Section("Your chats") {
            OptionToggle(
                "Save chat history",
                history,
                { history = it },
                description = "Turned off, new chats are deleted after 30 days",
            )
            OptionToggle(
                "Help improve Vela",
                improve,
                { improve = it },
                description = "Allow your chats to be used for training",
            )
        }
        Section("Your data") {
            OptionRow(
                "Export data",
                onClick = {
                    exportData()
                    toast = "We'll email you a download link"
                },
                icon = Icons.DownloadSimple,
                description = "A copy of your chats and settings",
            )
            OptionRow(
                "Delete all chats",
                onClick = { showDelete = true },
                icon = Icons.Trash,
                destructive = true,
            )
        }
    }
}

More screens from Vela

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements

One Android lesson, every Wednesday

Building Android apps?

What Alex learned building Android apps for 14 years, so you don't have to. Reads in under a minute.

Join 3,500+ Android developers. Unsubscribe any time.

You're subscribed

The next lesson lands in on Wednesday.