mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-01 22:04:26 +01:00
Refactoring & CR fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="no.nordicsemi.android.theme">
|
||||
<manifest package="no.nordicsemi.android.theme">
|
||||
|
||||
</manifest>
|
||||
@@ -28,16 +28,17 @@ object NordicColors {
|
||||
val TableViewBackground = NeutralColor(Color(0xFFF2F2F6))
|
||||
val TableViewSeparator = NeutralColor(Color(0xFFD2D2D6))
|
||||
|
||||
val Primary = ThemedColor(Color(0xFF00A9CE), Color(0xFF212121))
|
||||
val PrimaryVariant = ThemedColor(Color(0xFF008CD2), Color.Black)
|
||||
val Secondary = ThemedColor(Color(0xFF00A9CE), Color(0xFF008CD2))
|
||||
val SecondaryVariant = ThemedColor(Color(0xFF008CD2), Color(0xFF008CD2))
|
||||
val Primary = ThemedColor(Color(0xFF00A9CE), Color(0xFF00A9CE))
|
||||
val PrimaryVariant = ThemedColor(Color(0xFF008CD2), Color(0xFF00A9CE))
|
||||
val Secondary = ThemedColor(Color(0xFF00A9CE), Color(0xFF00A9CE))
|
||||
val SecondaryVariant = ThemedColor(Color(0xFF008CD2), Color(0xFF00A9CE))
|
||||
val OnPrimary = ThemedColor(Color.White, Color.White)
|
||||
val OnSecondary = ThemedColor(Color.White, Color.White)
|
||||
val OnBackground = ThemedColor(Color.Black, Color.White)
|
||||
val OnSurface = ThemedColor(Color.Black, Color.White)
|
||||
val Background = ThemedColor(Color(0xFFDADADA), Color.Black)
|
||||
val Surface = ThemedColor(Color(0xFFDADADA), Color.Black)
|
||||
val ItemHighlight = ThemedColor(Color.White, Color(0xFF1E1E1E))
|
||||
val Background = ThemedColor(Color(0xFFF5F5F5), Color(0xFF121212))
|
||||
val Surface = ThemedColor(Color(0xFFF5F5F5), Color(0xFF121212))
|
||||
}
|
||||
|
||||
sealed class NordicColor {
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.compose.material.lightColors
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun TestTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
|
||||
fun TestTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
|
||||
|
||||
val darkColorPalette = darkColors(
|
||||
primary = NordicColors.Primary.value(),
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
package no.nordicsemi.android.theme.view
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import no.nordicsemi.android.theme.NordicColors
|
||||
import no.nordicsemi.android.theme.R
|
||||
|
||||
@Composable
|
||||
fun BatteryLevelView(batteryLevel: Int) {
|
||||
Card(
|
||||
backgroundColor = NordicColors.NordicGray4.value(),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
elevation = 0.dp
|
||||
) {
|
||||
Box(modifier = Modifier.padding(16.dp)) {
|
||||
KeyValueField(
|
||||
stringResource(id = R.string.field_battery),
|
||||
"$batteryLevel%"
|
||||
)
|
||||
}
|
||||
ScreenSection {
|
||||
KeyValueField(
|
||||
stringResource(id = R.string.field_battery),
|
||||
"$batteryLevel%"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier
|
||||
import no.nordicsemi.android.theme.NordicColors
|
||||
|
||||
@Composable
|
||||
fun KeyValueField(key: String, value: String) {
|
||||
fun KeyValueField(key: String, value: String) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
package no.nordicsemi.android.theme.view
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import no.nordicsemi.android.theme.NordicColors
|
||||
|
||||
@Composable
|
||||
fun SensorRecordCard(content: @Composable () -> Unit) {
|
||||
fun ScreenSection(content: @Composable () -> Unit) {
|
||||
Card(
|
||||
backgroundColor = NordicColors.NordicGray4.value(),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
backgroundColor = NordicColors.ItemHighlight.value(),
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
elevation = 0.dp
|
||||
) {
|
||||
content()
|
||||
Box(modifier = Modifier.padding(16.dp)) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package no.nordicsemi.android.theme.view
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.RadioButton
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun <T> SpeedUnitRadioGroup(
|
||||
currentItem: T,
|
||||
items: List<RadioGroupItem<T>>,
|
||||
onEvent: (RadioGroupItem<T>) -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
items.forEach {
|
||||
SpeedUnitRadioButton(currentItem, it, onEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun <T> SpeedUnitRadioButton(
|
||||
selectedItem: T,
|
||||
displayedItem: RadioGroupItem<T>,
|
||||
onEvent: (RadioGroupItem<T>) -> Unit
|
||||
) {
|
||||
Row {
|
||||
RadioButton(
|
||||
selected = (selectedItem == displayedItem.unit),
|
||||
onClick = { onEvent(displayedItem) }
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
Text(text = displayedItem.label)
|
||||
}
|
||||
}
|
||||
|
||||
data class RadioGroupItem<T>(val unit: T, val label: String)
|
||||
@@ -0,0 +1,42 @@
|
||||
package no.nordicsemi.android.theme.view
|
||||
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TopAppBar
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import no.nordicsemi.android.theme.R
|
||||
|
||||
@Composable
|
||||
fun CloseIconAppBar(text: String, onClick: () -> Unit) {
|
||||
TopAppBar(
|
||||
title = { Text(text) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { onClick() }) {
|
||||
Icon(
|
||||
Icons.Default.Close,
|
||||
contentDescription = stringResource(id = R.string.close_app),
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BackIconAppBar(text: String, onClick: () -> Unit) {
|
||||
TopAppBar(
|
||||
title = { Text(text) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { onClick() }) {
|
||||
Icon(
|
||||
Icons.Default.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.back_screen),
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package no.nordicsemi.android.theme.viewmodel
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
abstract class CloseableViewModel : ViewModel() {
|
||||
|
||||
var isActive = MutableStateFlow(true)
|
||||
|
||||
protected fun finish() {
|
||||
isActive.tryEmit(false)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,6 @@
|
||||
<color name="colorSecondary">#FF0077c8</color>
|
||||
<color name="colorSecondaryDark">#FF004c97</color>
|
||||
<color name="colorOnSecondary">#FFFFFFFF</color>
|
||||
<color name="background">#FFDADADA</color>
|
||||
<color name="background">#FFF5F5F5</color>
|
||||
<color name="actionBarColor">#FF0090B0</color>
|
||||
</resources>
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
<resources>
|
||||
<string name="app_name">nRF Toolbox</string>
|
||||
|
||||
<string name="disconnect">Disconnect</string>
|
||||
<string name="close_app">Close the application.</string>
|
||||
<string name="back_screen">Close the current screen.</string>
|
||||
|
||||
<string name="disconnect">DISCONNECT</string>
|
||||
<string name="field_battery">Battery</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user