From d87431bce25de395b1725bf16e706c317534e694 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 6 Mar 2024 16:35:05 -0600 Subject: [PATCH] Add ImportAccountScreen with basic functionality. - Make HomeScreen the default navigator destination - Create reusable TopAppBar component --- .../kotlin/net/agorise/kee/MainActivity.kt | 4 +- .../drawable/compose-multiplatform.xml | 36 ---------- .../composeResources/drawable/logo-dero.xml | 15 ++++ .../commonMain/kotlin/net/agorise/kee/App.kt | 60 ---------------- .../kotlin/net/agorise/kee/Greeting.kt | 9 --- .../kee/ui/component/topappbar/TopAppBar.kt | 24 +++++++ .../agorise/kee/ui/screen/home/HomeScreen.kt | 42 ++++++++++- .../importaccount/ImportAccountScreen.kt | 70 +++++++++++++++++++ .../kee/ui/screen/license/LicenseScreen.kt | 37 ---------- .../kotlin/net/agorise/kee/main.kt | 8 +-- .../src/iosMain/kotlin/MainViewController.kt | 4 +- 11 files changed, 157 insertions(+), 152 deletions(-) delete mode 100644 composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml create mode 100644 composeApp/src/commonMain/composeResources/drawable/logo-dero.xml delete mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/App.kt delete mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/Greeting.kt create mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/ui/component/topappbar/TopAppBar.kt create mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt delete mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt diff --git a/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt b/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt index 9802518..9453f2e 100644 --- a/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt @@ -4,14 +4,14 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import cafe.adriel.voyager.navigator.Navigator -import net.agorise.kee.ui.screen.license.LicenseScreen +import net.agorise.kee.ui.screen.home.HomeScreen class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - Navigator(LicenseScreen()) + Navigator(HomeScreen()) } } } diff --git a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml b/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml deleted file mode 100644 index d7bf795..0000000 --- a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - diff --git a/composeApp/src/commonMain/composeResources/drawable/logo-dero.xml b/composeApp/src/commonMain/composeResources/drawable/logo-dero.xml new file mode 100644 index 0000000..7cb34d8 --- /dev/null +++ b/composeApp/src/commonMain/composeResources/drawable/logo-dero.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/App.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/App.kt deleted file mode 100644 index 9434529..0000000 --- a/composeApp/src/commonMain/kotlin/net/agorise/kee/App.kt +++ /dev/null @@ -1,60 +0,0 @@ -package net.agorise.kee - -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Button -import androidx.compose.material3.Text -import androidx.compose.material3.TextField -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import kotlinx.datetime.* -import org.jetbrains.compose.ui.tooling.preview.Preview -import ui.theme.KeeTheme - -@Composable -@Preview -fun App() { - KeeTheme { - var location by remember { mutableStateOf("Europe/Paris") } - var timeAtLocation by remember { mutableStateOf("No location selected") } - - Column(modifier = Modifier.padding(20.dp)) { - Text( - timeAtLocation, - style = TextStyle(fontSize = 20.sp), - textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth().align(Alignment.CenterHorizontally) - ) - TextField( - value = location, - modifier = Modifier.padding(top = 10.dp), - onValueChange = { location = it } - ) - Button( - modifier = Modifier.padding(top = 10.dp), - onClick = { timeAtLocation = currentTimeAt(location) ?: "Invalid Location" } - ) { - Text("Show Time At Location") - } - } - } -} - -fun currentTimeAt(location: String): String? { - fun LocalTime.formatted() = "$hour:$minute:$second" - - return try { - val time = Clock.System.now() - val zone = TimeZone.of(location) - val localTime = time.toLocalDateTime(zone).time - "The time in $location is ${localTime.formatted()}" - } catch (ex: IllegalTimeZoneException) { - null - } -} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/Greeting.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/Greeting.kt deleted file mode 100644 index 0eea8da..0000000 --- a/composeApp/src/commonMain/kotlin/net/agorise/kee/Greeting.kt +++ /dev/null @@ -1,9 +0,0 @@ -package net.agorise.kee - -class Greeting { - private val platform = getPlatform() - - fun greet(): String { - return "Kee on ${platform.name}!" - } -} diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/component/topappbar/TopAppBar.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/component/topappbar/TopAppBar.kt new file mode 100644 index 0000000..737dda3 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/component/topappbar/TopAppBar.kt @@ -0,0 +1,24 @@ +package net.agorise.kee.ui.component.topappbar + +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults.topAppBarColors +import androidx.compose.runtime.Composable + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun KeeTopAppBar( + title: String, +) { + TopAppBar( + colors = topAppBarColors( + containerColor = MaterialTheme.colorScheme.primaryContainer, + titleContentColor = MaterialTheme.colorScheme.primary + ), + title = { + Text(title) + } + ) +} diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt index 935366c..438030f 100644 --- a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt @@ -1,13 +1,51 @@ package net.agorise.kee.ui.screen.home -import androidx.compose.material3.Text +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.LocalNavigator +import net.agorise.kee.getPlatform +import net.agorise.kee.ui.component.topappbar.KeeTopAppBar +import net.agorise.kee.ui.screen.importaccount.ImportAccountScreen +import org.jetbrains.compose.ui.tooling.preview.Preview class HomeScreen : Screen { @Composable override fun Content() { - Text("Welcome to Home Screen") + HomeScreenContent() } } + +@Composable +private fun HomeScreenContent() { + val navigator = LocalNavigator.current + + Scaffold( + topBar = { KeeTopAppBar("Kee Wallet") } + ) { innerPadding -> + Column( + modifier = Modifier.padding(innerPadding).padding(16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + Text("Welcome to Kee from ${getPlatform().name}") + + Button( + onClick = { navigator?.replace(ImportAccountScreen()) } + ) { + Text("Import Account") + } + } + } +} + +@Preview +@Composable +private fun HomeScreenContentPreview() { + HomeScreenContent() +} diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt new file mode 100644 index 0000000..a756e0c --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/importaccount/ImportAccountScreen.kt @@ -0,0 +1,70 @@ +package net.agorise.kee.ui.screen.importaccount + +import androidx.compose.foundation.layout.* +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.LocalNavigator +import kee.composeapp.generated.resources.Res +import kee.composeapp.generated.resources.logo_dero +import net.agorise.kee.ui.component.topappbar.KeeTopAppBar +import net.agorise.kee.ui.screen.home.HomeScreen +import org.jetbrains.compose.resources.ExperimentalResourceApi +import org.jetbrains.compose.resources.vectorResource +import org.jetbrains.compose.ui.tooling.preview.Preview + +class ImportAccountScreen : Screen { + + @Composable + override fun Content() { + ImportAccountScreenContent() + } +} + +@OptIn(ExperimentalResourceApi::class) +@Composable +private fun ImportAccountScreenContent() { + val navigator = LocalNavigator.current + + Scaffold( + topBar = { KeeTopAppBar("Import Account") } + ) { innerPadding -> + Column( + modifier = Modifier.padding(innerPadding).padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + var recoveryText by remember { mutableStateOf("") } + val recoveryWords = recoveryText.split(" ").filter { it.isNotBlank() } + + Icon( + imageVector = vectorResource(Res.drawable.logo_dero), + contentDescription = null, + tint = MaterialTheme.colorScheme.primary, + modifier = Modifier.size(60.dp) + ) + Text("Enter your recovery words below") + OutlinedTextField( + value = recoveryText, + onValueChange = { recoveryText = it }, + minLines = 3, + modifier = Modifier.fillMaxWidth() + ) + Button( + enabled = recoveryWords.size == 2, + onClick = { navigator?.replace(HomeScreen()) } + ) { + Text("Import Account") + } + } + } +} + +@Preview +@Composable +private fun ImportAccountScreenContentPreview() { + ImportAccountScreenContent() +} diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt deleted file mode 100644 index 2937ea7..0000000 --- a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt +++ /dev/null @@ -1,37 +0,0 @@ -package net.agorise.kee.ui.screen.license - -import androidx.compose.foundation.layout.Column -import androidx.compose.material3.Button -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import cafe.adriel.voyager.core.screen.Screen -import cafe.adriel.voyager.navigator.LocalNavigator -import cafe.adriel.voyager.navigator.currentOrThrow -import net.agorise.kee.ui.screen.home.HomeScreen -import org.jetbrains.compose.ui.tooling.preview.Preview - -class LicenseScreen : Screen { - - @Composable - override fun Content() { - HomeScreenContent() - } -} - -@Composable -fun HomeScreenContent() { - val navigator = LocalNavigator.currentOrThrow - - Column { - Text("Welcome to License Screen") - Button(onClick = { navigator.replace(HomeScreen()) }) { - Text("Accept") - } - } -} - -@Preview -@Composable -fun HomeScreenContentPreview() { - HomeScreenContent() -} diff --git a/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt b/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt index 842c13b..5ffe842 100644 --- a/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt +++ b/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt @@ -7,14 +7,14 @@ import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.application import androidx.compose.ui.window.rememberWindowState import cafe.adriel.voyager.navigator.Navigator -import net.agorise.kee.ui.screen.license.LicenseScreen +import net.agorise.kee.ui.screen.home.HomeScreen fun main() = application { val state = rememberWindowState( - size = DpSize(400.dp, 250.dp), + size = DpSize(420.dp, 880.dp), position = WindowPosition(300.dp, 300.dp) ) - Window(title = "Kee", onCloseRequest = ::exitApplication, state = state) { - Navigator(LicenseScreen()) + Window(title = "", onCloseRequest = ::exitApplication, state = state) { + Navigator(HomeScreen()) } } diff --git a/composeApp/src/iosMain/kotlin/MainViewController.kt b/composeApp/src/iosMain/kotlin/MainViewController.kt index 10867f4..1c76dd8 100644 --- a/composeApp/src/iosMain/kotlin/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/MainViewController.kt @@ -1,5 +1,5 @@ import androidx.compose.ui.window.ComposeUIViewController import cafe.adriel.voyager.navigator.Navigator -import net.agorise.kee.ui.screen.license.LicenseScreen +import net.agorise.kee.ui.screen.home.HomeScreen -fun MainViewController() = ComposeUIViewController { Navigator(LicenseScreen()) } +fun MainViewController() = ComposeUIViewController { Navigator(HomeScreen()) }