mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-09 09:44:22 +01:00
Replace CompanionDeviceManager with Scanner library.
This commit is contained in:
@@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun <T> SpeedUnitRadioGroup(
|
||||
fun <T> SelectItemRadioGroup(
|
||||
currentItem: T,
|
||||
items: List<RadioGroupItem<T>>,
|
||||
onEvent: (RadioGroupItem<T>) -> Unit
|
||||
@@ -22,13 +22,13 @@ fun <T> SpeedUnitRadioGroup(
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
items.forEach {
|
||||
SpeedUnitRadioButton(currentItem, it, onEvent)
|
||||
SelectItemRadioButton(currentItem, it, onEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun <T> SpeedUnitRadioButton(
|
||||
internal fun <T> SelectItemRadioButton(
|
||||
selectedItem: T,
|
||||
displayedItem: RadioGroupItem<T>,
|
||||
onEvent: (RadioGroupItem<T>) -> Unit
|
||||
@@ -0,0 +1,9 @@
|
||||
package no.nordicsemi.android.theme.view.dialog
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
|
||||
@Composable
|
||||
fun String.toAnnotatedString() = buildAnnotatedString {
|
||||
append(this@toAnnotatedString)
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package no.nordicsemi.android.theme.view.dialog
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import no.nordicsemi.android.theme.NordicColors
|
||||
import no.nordicsemi.android.theme.R
|
||||
|
||||
@Composable
|
||||
fun StringListDialog(config: StringListDialogConfig) {
|
||||
Dialog(onDismissRequest = { config.onResult(FlowCanceled) }) {
|
||||
StringListView(config)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun StringListView(config: StringListDialogConfig) {
|
||||
Card(
|
||||
modifier = Modifier.height(300.dp),
|
||||
backgroundColor = NordicColors.NordicGray4.value(),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
elevation = 0.dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
verticalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Text(
|
||||
text = config.title ?: stringResource(id = R.string.dialog).toAnnotatedString(),
|
||||
fontSize = 20.sp
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.8f)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
|
||||
config.items.forEachIndexed { i, entry ->
|
||||
Column(modifier = Modifier.clickable { config.onResult(ItemSelectedResult(i)) }) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Row {
|
||||
config.leftIcon?.let {
|
||||
Image(
|
||||
modifier = Modifier.padding(horizontal = 4.dp),
|
||||
painter = painterResource(it),
|
||||
contentDescription = "Content image",
|
||||
colorFilter = ColorFilter.tint(
|
||||
NordicColors.NordicDarkGray.value()
|
||||
)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = entry,
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
|
||||
if (i != config.items.size - 1) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.End
|
||||
) {
|
||||
TextButton(onClick = { config.onResult(FlowCanceled) }) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.cancel),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package no.nordicsemi.android.theme.view.dialog
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
|
||||
data class StringListDialogConfig(
|
||||
val title: AnnotatedString? = null,
|
||||
@DrawableRes
|
||||
val leftIcon: Int? = null,
|
||||
val items: List<String> = emptyList(),
|
||||
val onResult: (StringListDialogResult) -> Unit
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package no.nordicsemi.android.theme.view.dialog
|
||||
|
||||
sealed class StringListDialogResult
|
||||
|
||||
data class ItemSelectedResult(val index: Int): StringListDialogResult()
|
||||
|
||||
object FlowCanceled : StringListDialogResult()
|
||||
@@ -2,6 +2,9 @@
|
||||
<resources>
|
||||
<string name="app_name">nRF Toolbox</string>
|
||||
|
||||
<string name="dialog">Dialog</string>
|
||||
<string name="cancel">CANCEL</string>
|
||||
|
||||
<string name="close_app">Close the application.</string>
|
||||
<string name="back_screen">Close the current screen.</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user