From 2f556b6dc936249fb2561b8f6570e3714f4bdd8c Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 5 Apr 2020 11:50:47 -0700 Subject: [PATCH] move Users screen to its own file --- .../java/com/geeksville/mesh/ui/MeshApp.kt | 87 +----------------- .../main/java/com/geeksville/mesh/ui/Users.kt | 92 +++++++++++++++++++ 2 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 app/src/main/java/com/geeksville/mesh/ui/Users.kt diff --git a/app/src/main/java/com/geeksville/mesh/ui/MeshApp.kt b/app/src/main/java/com/geeksville/mesh/ui/MeshApp.kt index c87e3a21e..96131613c 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MeshApp.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MeshApp.kt @@ -2,98 +2,19 @@ package com.geeksville.mesh.ui import androidx.compose.Composable import androidx.compose.state -import androidx.ui.core.ContextAmbient import androidx.ui.core.Text -import androidx.ui.layout.* +import androidx.ui.layout.Container +import androidx.ui.layout.LayoutSize import androidx.ui.material.* import androidx.ui.tooling.preview.Preview import androidx.ui.unit.dp import com.geeksville.android.Logging import com.geeksville.mesh.R -import com.geeksville.mesh.model.NodeDB import com.geeksville.mesh.model.UIState -import com.geeksville.mesh.service.MeshService -import com.geeksville.mesh.service.RadioInterfaceService -import com.geeksville.mesh.service.SoftwareUpdateService object UILog : Logging -/// Given a human name, strip out the first letter of the first three words and return that as the initials for -/// that user. -fun getInitials(name: String): String { - val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }.take(3).map { it.first() } - .joinToString("") - - return words -} - -@Composable -fun HomeContent() { - analyticsScreen(name = "users") - - Column { - Row { - fun connected() = UIState.isConnected.value != MeshService.ConnectionState.DISCONNECTED - VectorImage( - id = if (connected()) R.drawable.cloud_on else R.drawable.cloud_off, - tint = palette.onBackground, - modifier = LayoutPadding(start = 8.dp) - ) - - Column { - - Text( - when (UIState.isConnected.value) { - MeshService.ConnectionState.CONNECTED -> "Connected" - MeshService.ConnectionState.DISCONNECTED -> "Disconnected" - MeshService.ConnectionState.DEVICE_SLEEP -> "Power Saving" - }, - modifier = LayoutPadding(start = 8.dp) - ) - - if (false) { // hide the firmware update button for now, it is kinda ugly and users don't need it yet - /// Create a software update button - val context = ContextAmbient.current - RadioInterfaceService.getBondedDeviceAddress(context)?.let { macAddress -> - Button( - onClick = { - SoftwareUpdateService.enqueueWork( - context, - SoftwareUpdateService.startUpdateIntent(macAddress) - ) - } - ) { - Text(text = "Update firmware") - } - } - } - } - } - - NodeDB.nodes.values.forEach { - NodeInfoCard(it) - } - - - /* FIXME - doens't work yet - probably because I'm not using release keys - // If account is null, then show the signin button, otherwise - val context = ambient(ContextAmbient) - val account = GoogleSignIn.getLastSignedInAccount(context) - if (account != null) - Text("We have an account") - else { - Text("No account yet") - if (context is Activity) { - Button("Google sign-in", onClick = { - val signInIntent: Intent = UIState.googleSignInClient.signInIntent - context.startActivityForResult(signInIntent, MainActivity.RC_SIGN_IN) - }) - } - } */ - } -} - val palette = lightColorPalette() // darkColorPalette() @Composable @@ -121,7 +42,7 @@ fun MeshApp() { fun previewView() { // It seems modaldrawerlayout not yet supported in preview MaterialTheme(colors = palette) { - HomeContent() + UsersContent() } } @@ -147,7 +68,7 @@ private fun AppContent(openDrawer: () -> Unit) { when (AppStatus.currentScreen) { Screen.messages -> MessagesContent() Screen.settings -> SettingsContent() - Screen.users -> HomeContent() + Screen.users -> UsersContent() Screen.channel -> ChannelContent(UIState.getChannel()) Screen.map -> MapContent() else -> TODO() diff --git a/app/src/main/java/com/geeksville/mesh/ui/Users.kt b/app/src/main/java/com/geeksville/mesh/ui/Users.kt new file mode 100644 index 000000000..e8cf75640 --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/ui/Users.kt @@ -0,0 +1,92 @@ +package com.geeksville.mesh.ui + +import androidx.compose.Composable +import androidx.ui.core.ContextAmbient +import androidx.ui.core.Text +import androidx.ui.layout.Column +import androidx.ui.layout.LayoutPadding +import androidx.ui.layout.Row +import androidx.ui.material.Button +import androidx.ui.unit.dp +import com.geeksville.mesh.R +import com.geeksville.mesh.model.NodeDB +import com.geeksville.mesh.model.UIState +import com.geeksville.mesh.service.MeshService +import com.geeksville.mesh.service.RadioInterfaceService +import com.geeksville.mesh.service.SoftwareUpdateService + + +/// Given a human name, strip out the first letter of the first three words and return that as the initials for +/// that user. +fun getInitials(name: String): String { + val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }.take(3).map { it.first() } + .joinToString("") + + return words +} + +@Composable +fun UsersContent() { + analyticsScreen(name = "users") + + Column { + Row { + fun connected() = UIState.isConnected.value != MeshService.ConnectionState.DISCONNECTED + VectorImage( + id = if (connected()) R.drawable.cloud_on else R.drawable.cloud_off, + tint = palette.onBackground, + modifier = LayoutPadding(start = 8.dp) + ) + + Column { + + Text( + when (UIState.isConnected.value) { + MeshService.ConnectionState.CONNECTED -> "Connected" + MeshService.ConnectionState.DISCONNECTED -> "Disconnected" + MeshService.ConnectionState.DEVICE_SLEEP -> "Power Saving" + }, + modifier = LayoutPadding(start = 8.dp) + ) + + if (false) { // hide the firmware update button for now, it is kinda ugly and users don't need it yet + /// Create a software update button + val context = ContextAmbient.current + RadioInterfaceService.getBondedDeviceAddress(context)?.let { macAddress -> + Button( + onClick = { + SoftwareUpdateService.enqueueWork( + context, + SoftwareUpdateService.startUpdateIntent(macAddress) + ) + } + ) { + Text(text = "Update firmware") + } + } + } + } + } + + NodeDB.nodes.values.forEach { + NodeInfoCard(it) + } + + + /* FIXME - doens't work yet - probably because I'm not using release keys + // If account is null, then show the signin button, otherwise + val context = ambient(ContextAmbient) + val account = GoogleSignIn.getLastSignedInAccount(context) + if (account != null) + Text("We have an account") + else { + Text("No account yet") + if (context is Activity) { + Button("Google sign-in", onClick = { + val signInIntent: Intent = UIState.googleSignInClient.signInIntent + context.startActivityForResult(signInIntent, MainActivity.RC_SIGN_IN) + }) + } + } */ + } +}