Add module for managing user preferences.
- Navigate to Import Account screen if there is no active account. - Add basic node status placeholder in Import Account screen.
This commit is contained in:
parent
ca86caa72e
commit
34c82ba8f6
8 changed files with 105 additions and 6 deletions
|
@ -36,6 +36,8 @@ kotlin {
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
}
|
}
|
||||||
commonMain.dependencies {
|
commonMain.dependencies {
|
||||||
|
implementation(projects.shared.preferences)
|
||||||
|
|
||||||
implementation(compose.components.resources)
|
implementation(compose.components.resources)
|
||||||
implementation(compose.components.uiToolingPreview)
|
implementation(compose.components.uiToolingPreview)
|
||||||
implementation(compose.foundation)
|
implementation(compose.foundation)
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package net.agorise.kee.ui.component.nodestatus
|
||||||
|
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
|
import ui.theme.KeeTheme
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NodeStatus() {
|
||||||
|
Text("Connected to X.X.X.X", color = MaterialTheme.colorScheme.onBackground)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
private fun NodeStatusLightPreview() = KeeTheme(useDarkTheme = false) {
|
||||||
|
NodeStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
private fun NodeStatusDarkPreview() = KeeTheme(useDarkTheme = true) {
|
||||||
|
NodeStatus()
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import cafe.adriel.voyager.navigator.LocalNavigator
|
||||||
import net.agorise.kee.getPlatform
|
import net.agorise.kee.getPlatform
|
||||||
import net.agorise.kee.ui.component.topappbar.KeeTopAppBar
|
import net.agorise.kee.ui.component.topappbar.KeeTopAppBar
|
||||||
import net.agorise.kee.ui.screen.importaccount.ImportAccountScreen
|
import net.agorise.kee.ui.screen.importaccount.ImportAccountScreen
|
||||||
|
import net.agorise.shared.preferences.KeePreferences
|
||||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
import ui.theme.KeeTheme
|
import ui.theme.KeeTheme
|
||||||
|
|
||||||
|
@ -27,6 +28,11 @@ class HomeScreen : Screen {
|
||||||
private fun HomeScreenContent() {
|
private fun HomeScreenContent() {
|
||||||
val navigator = LocalNavigator.current
|
val navigator = LocalNavigator.current
|
||||||
|
|
||||||
|
// Navigate to Import Account screen immediately if there is no active account
|
||||||
|
if (KeePreferences.isAccountActive().not()) {
|
||||||
|
navigator?.replace(ImportAccountScreen())
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = { KeeTopAppBar("Kee Wallet") }
|
topBar = { KeeTopAppBar("Kee Wallet") }
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
|
|
|
@ -11,6 +11,7 @@ import cafe.adriel.voyager.core.screen.Screen
|
||||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||||
import kee.composeapp.generated.resources.Res
|
import kee.composeapp.generated.resources.Res
|
||||||
import kee.composeapp.generated.resources.logo_kee
|
import kee.composeapp.generated.resources.logo_kee
|
||||||
|
import net.agorise.kee.ui.component.nodestatus.NodeStatus
|
||||||
import net.agorise.kee.ui.component.topappbar.KeeTopAppBar
|
import net.agorise.kee.ui.component.topappbar.KeeTopAppBar
|
||||||
import net.agorise.kee.ui.screen.home.HomeScreen
|
import net.agorise.kee.ui.screen.home.HomeScreen
|
||||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
||||||
|
@ -37,7 +38,10 @@ private fun ImportAccountScreenContent() {
|
||||||
topBar = { KeeTopAppBar("Import Account") }
|
topBar = { KeeTopAppBar("Import Account") }
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(innerPadding).padding(16.dp),
|
modifier = Modifier
|
||||||
|
.padding(innerPadding)
|
||||||
|
.consumeWindowInsets(innerPadding)
|
||||||
|
.padding(top = 16.dp, start = 16.dp, end = 16.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
|
@ -72,6 +76,8 @@ private fun ImportAccountScreenContent() {
|
||||||
) {
|
) {
|
||||||
Text("Import Account")
|
Text("Import Account")
|
||||||
}
|
}
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
NodeStatus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,15 @@ androidx-activityCompose = "1.8.2"
|
||||||
compose = "1.6.2"
|
compose = "1.6.2"
|
||||||
compose-plugin = "1.6.0"
|
compose-plugin = "1.6.0"
|
||||||
kotlin = "1.9.22"
|
kotlin = "1.9.22"
|
||||||
|
multiplatform-settings = "1.1.1"
|
||||||
voyager = "1.0.0"
|
voyager = "1.0.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
|
androidx-activity-compose = { group = "androidx.activity", name ="activity-compose", version.ref = "androidx-activityCompose" }
|
||||||
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
|
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose" }
|
||||||
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
|
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "compose" }
|
||||||
voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" }
|
multiplatform-settings = { group="com.russhwolf", name = "multiplatform-settings-no-arg", version.ref = "multiplatform-settings" }
|
||||||
|
voyager-navigator = { group = "cafe.adriel.voyager", name = "voyager-navigator", version.ref = "voyager" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|
|
@ -18,4 +18,5 @@ dependencyResolutionManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include(":composeApp")
|
include(":composeApp")
|
||||||
|
include(":shared:preferences")
|
||||||
|
|
40
shared/preferences/build.gradle.kts
Normal file
40
shared/preferences/build.gradle.kts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
plugins {
|
||||||
|
alias(libs.plugins.kotlinMultiplatform)
|
||||||
|
alias(libs.plugins.androidLibrary)
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
androidTarget {
|
||||||
|
compilations.all {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "11"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jvm()
|
||||||
|
|
||||||
|
iosX64()
|
||||||
|
iosArm64()
|
||||||
|
iosSimulatorArm64()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain.dependencies {
|
||||||
|
implementation(libs.multiplatform.settings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "net.agorise.shared.preferences"
|
||||||
|
compileSdk = libs.versions.android.compileSdk.get().toInt()
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = libs.versions.android.minSdk.get().toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package net.agorise.shared.preferences
|
||||||
|
|
||||||
|
import com.russhwolf.settings.Settings
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides methods to access preferences on all supported platforms.
|
||||||
|
*/
|
||||||
|
object KeePreferences {
|
||||||
|
// TODO Use a stronger implementation that allows encryption
|
||||||
|
private val settings: Settings = Settings()
|
||||||
|
|
||||||
|
// Keys used to store/retrieve preferences
|
||||||
|
private const val KEY_RECOVERY_WORDS = "key_recovery_words"
|
||||||
|
|
||||||
|
fun isAccountActive(): Boolean {
|
||||||
|
return settings.hasKey(KEY_RECOVERY_WORDS)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue