total refactor
This commit is contained in:
parent
435a4db2fb
commit
39297abc6c
|
|
@ -4,7 +4,7 @@
|
|||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-02-12T02:51:30.451430800Z">
|
||||
<DropdownSelection timestamp="2025-06-11T08:44:02.119013Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=BV5900DNS00004122" />
|
||||
|
|
|
|||
|
|
@ -106,11 +106,12 @@ dependencies {
|
|||
ksp(libs.hilt.android.compiler)
|
||||
ksp(libs.androidx.hilt.compiler)
|
||||
|
||||
implementation(libs.scanner)
|
||||
implementation(libs.client)
|
||||
//implementation(libs.scanner)
|
||||
//implementation(libs.client)
|
||||
|
||||
//implementation("no.nordicsemi.kotlin.ble:core:2.0.0-alpha02")
|
||||
implementation("no.nordicsemi.kotlin.ble:client-android:2.0.0-alpha02")
|
||||
implementation("org.slf4j:slf4j-simple:2.1.0-alpha1")
|
||||
|
||||
implementation(libs.accompanist.permissions)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,70 +7,45 @@ import android.bluetooth.BluetoothAdapter
|
|||
import android.bluetooth.BluetoothManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.hardware.camera2.CameraCharacteristics
|
||||
import android.hardware.camera2.CameraManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.SurfaceView
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBars
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.ModalBottomSheetLayout
|
||||
import androidx.compose.material.ModalBottomSheetValue
|
||||
import androidx.compose.material.rememberModalBottomSheetState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.rememberMultiplePermissionsState
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BottomState
|
||||
import llc.arma.ble.app.ui.common.LocalBottomDialogState
|
||||
import llc.arma.ble.app.ui.screen.main.MainScreen
|
||||
import llc.arma.ble.app.ui.theme.BleTheme
|
||||
import org.slf4j.simple.SimpleLogger.DEFAULT_LOG_LEVEL_KEY
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
init {
|
||||
|
||||
System.setProperty(DEFAULT_LOG_LEVEL_KEY, "Debug")
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@OptIn(ExperimentalPermissionsApi::class, ExperimentalMaterialApi::class)
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -78,192 +53,94 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
enableEdgeToEdge()
|
||||
|
||||
//installSplashScreen()
|
||||
installSplashScreen()
|
||||
|
||||
setContent {
|
||||
|
||||
BleTheme {
|
||||
|
||||
val modalState =
|
||||
rememberModalBottomSheetState(
|
||||
skipHalfExpanded = true,
|
||||
initialValue = ModalBottomSheetValue.Hidden
|
||||
)
|
||||
|
||||
var sheetContent by remember() {
|
||||
mutableStateOf<@Composable () -> Unit>({})
|
||||
}
|
||||
|
||||
if(modalState.currentValue == ModalBottomSheetValue.Hidden){
|
||||
sheetContent = {}
|
||||
}
|
||||
|
||||
CompositionLocalProvider(
|
||||
LocalBottomDialogState provides BottomState(
|
||||
sheetState = modalState,
|
||||
setContent = {
|
||||
sheetContent = it
|
||||
}
|
||||
)
|
||||
) {
|
||||
|
||||
BoxWithConstraints(
|
||||
modifier = Modifier.navigationBarsPadding()
|
||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.navigationBarsPadding(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
|
||||
val maxHeight = with(LocalDensity.current) {
|
||||
this@BoxWithConstraints.constraints.maxHeight.toDp()
|
||||
}
|
||||
val multiplePermissionsState =
|
||||
|
||||
ModalBottomSheetLayout(
|
||||
modifier = Modifier,
|
||||
sheetShape = RoundedCornerShape(
|
||||
topStart = 25.dp,
|
||||
topEnd = 25.dp
|
||||
),
|
||||
sheetElevation = 0.dp,
|
||||
sheetState = modalState,
|
||||
sheetContent = {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
|
||||
val statusBarHeight = with(LocalDensity.current) {
|
||||
WindowInsets.statusBars.getTop(this).toDp()
|
||||
rememberMultiplePermissionsState(
|
||||
listOf(
|
||||
Manifest.permission.READ_MEDIA_VIDEO,
|
||||
Manifest.permission.READ_MEDIA_IMAGES,
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.BLUETOOTH_CONNECT
|
||||
)
|
||||
)
|
||||
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
rememberMultiplePermissionsState(
|
||||
listOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.BLUETOOTH_CONNECT
|
||||
)
|
||||
)
|
||||
} else {
|
||||
rememberMultiplePermissionsState(
|
||||
listOf(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
)
|
||||
)
|
||||
}
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
Column(
|
||||
modifier = Modifier.heightIn(max = maxHeight - statusBarHeight),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.navigationBarsPadding()
|
||||
) {
|
||||
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.primary.copy(alpha = 0.7f),
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.size(
|
||||
width = 54.dp,
|
||||
height = 5.dp
|
||||
)
|
||||
|
||||
) {}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
sheetContent()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BackHandler(modalState.isVisible) {
|
||||
scope.launch { modalState.hide() }
|
||||
}
|
||||
|
||||
},
|
||||
content = {
|
||||
|
||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.navigationBarsPadding(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
|
||||
val multiplePermissionsState =
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
|
||||
rememberMultiplePermissionsState(
|
||||
listOf(
|
||||
Manifest.permission.READ_MEDIA_VIDEO,
|
||||
Manifest.permission.READ_MEDIA_IMAGES,
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.BLUETOOTH_CONNECT
|
||||
)
|
||||
)
|
||||
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
rememberMultiplePermissionsState(
|
||||
listOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.BLUETOOTH_CONNECT
|
||||
)
|
||||
)
|
||||
} else {
|
||||
rememberMultiplePermissionsState(
|
||||
listOf(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
var bleEnabled by remember {
|
||||
mutableStateOf(mBluetoothAdapter.isEnabled)
|
||||
}
|
||||
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
val lifecycleState by lifecycleOwner.lifecycle.currentStateFlow.collectAsState()
|
||||
|
||||
LaunchedEffect(lifecycleState) {
|
||||
bleEnabled = mBluetoothAdapter.isEnabled
|
||||
}
|
||||
|
||||
if (multiplePermissionsState.allPermissionsGranted) {
|
||||
|
||||
if (bleEnabled) {
|
||||
|
||||
MainScreen()
|
||||
|
||||
} else {
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
LaunchedEffect(mBluetoothAdapter.isEnabled) {
|
||||
val intent =
|
||||
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
||||
(context as Activity).startActivityForResult(
|
||||
intent,
|
||||
1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
LaunchedEffect(multiplePermissionsState) {
|
||||
multiplePermissionsState.launchMultiplePermissionRequest()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
)
|
||||
var bleEnabled by remember {
|
||||
mutableStateOf(mBluetoothAdapter.isEnabled)
|
||||
}
|
||||
|
||||
val lifecycleOwner = androidx.lifecycle.compose.LocalLifecycleOwner.current
|
||||
val lifecycleState by lifecycleOwner.lifecycle.currentStateFlow.collectAsState()
|
||||
|
||||
LaunchedEffect(lifecycleState) {
|
||||
bleEnabled = mBluetoothAdapter.isEnabled
|
||||
}
|
||||
|
||||
if (multiplePermissionsState.allPermissionsGranted) {
|
||||
|
||||
if (bleEnabled) {
|
||||
|
||||
MainScreen()
|
||||
|
||||
} else {
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
LaunchedEffect(mBluetoothAdapter.isEnabled) {
|
||||
val intent =
|
||||
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
||||
(context as Activity).startActivityForResult(
|
||||
intent,
|
||||
1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
LaunchedEffect(multiplePermissionsState) {
|
||||
multiplePermissionsState.launchMultiplePermissionRequest()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
package llc.arma.ble.app.ui.common
|
||||
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.ModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.remember
|
||||
|
||||
val LocalBottomDialogState = compositionLocalOf<BottomState?> { null }
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
fun rememberBottomDialogState(): BottomDialogState {
|
||||
|
||||
val state = LocalBottomDialogState.current
|
||||
|
||||
return remember {
|
||||
BottomDialogState(
|
||||
sheetState = state?.sheetState,
|
||||
setContent = state?.setContent ?: { }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class BottomState @OptIn(ExperimentalMaterialApi::class) constructor(
|
||||
val sheetState: ModalBottomSheetState?,
|
||||
val setContent: (@Composable () -> Unit) -> Unit,
|
||||
)
|
||||
|
||||
class BottomDialogState @OptIn(ExperimentalMaterialApi::class) constructor(
|
||||
val sheetState: ModalBottomSheetState?,
|
||||
val setContent: (@Composable () -> Unit) -> Unit,
|
||||
) {
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
suspend fun show(
|
||||
content: @Composable () -> Unit
|
||||
){
|
||||
setContent(content)
|
||||
//if(sheetState?.currentValue != ModalBottomSheetValue.Expanded)
|
||||
sheetState?.show()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
suspend fun hide(){
|
||||
sheetState?.hide()
|
||||
setContent { }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package llc.arma.ble.app.ui.common
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
|
||||
suspend inline fun <T> retryUntilNotNull(
|
||||
retryDelay: Long = 10_000,
|
||||
onNewAttempt: (attempt: Int) -> Unit,
|
||||
block: () -> T?
|
||||
) : T {
|
||||
|
||||
var attempt = 0
|
||||
|
||||
var result: T? = null
|
||||
|
||||
while (result == null) {
|
||||
|
||||
result = block()
|
||||
|
||||
if(result == null) {
|
||||
|
||||
onNewAttempt(++attempt)
|
||||
|
||||
delay(retryDelay)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package llc.arma.ble.app.ui.common
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.material3.ContainedLoadingIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun RetryingLoadingTemplate(
|
||||
attempt: Int?,
|
||||
onCancel: () -> Unit,
|
||||
) {
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.widthIn(max = 230.dp)
|
||||
) {
|
||||
|
||||
ContainedLoadingIndicator()
|
||||
|
||||
attempt?.let {
|
||||
|
||||
Spacer(Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = "Повторная попытка ${it}"
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "Во время загрузки произошла ошибка",
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
TextButton(
|
||||
onClick = onCancel
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Отмена"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,394 @@
|
|||
package llc.arma.ble.app.ui.common
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ContainedLoadingIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.max
|
||||
import llc.arma.ble.R
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.ShapeType.Companion.takeShapeType
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInHour
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInMinute
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInSecond
|
||||
import llc.arma.ble.app.ui.screen.locale.localizedName
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
|
||||
class WriteFlowContract {
|
||||
|
||||
sealed class Event : ViewEvent {
|
||||
|
||||
data object OnWrite : Event()
|
||||
|
||||
data object OnNavigateUp : Event()
|
||||
|
||||
}
|
||||
|
||||
sealed class State : ViewState {
|
||||
|
||||
data object Loading : State()
|
||||
|
||||
data class Display(
|
||||
val items: List<WriteItemData>
|
||||
) : State()
|
||||
|
||||
data object Writing : State()
|
||||
|
||||
data object Success : State()
|
||||
|
||||
data object Error : State()
|
||||
|
||||
}
|
||||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
sealed class Navigation : Effect(){
|
||||
|
||||
data object Up : Navigation()
|
||||
|
||||
data object UpSuccess : Navigation()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun WriteFlow(
|
||||
state: WriteFlowContract.State,
|
||||
onEvent: (event: WriteFlowContract.Event) -> Unit
|
||||
) {
|
||||
|
||||
when(state){
|
||||
is WriteFlowContract.State.Display -> DisplayState(state, onEvent)
|
||||
is WriteFlowContract.State.Error -> ErrorState(state, onEvent)
|
||||
is WriteFlowContract.State.Loading -> LoadingState()
|
||||
is WriteFlowContract.State.Success -> SuccessState(state, onEvent)
|
||||
is WriteFlowContract.State.Writing -> WritingState(state, onEvent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LoadingState(){}
|
||||
|
||||
data class WriteItemData(
|
||||
val title: String,
|
||||
val subtitle: String
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun DisplayState(
|
||||
state: WriteFlowContract.State.Display,
|
||||
onEvent: (event: WriteFlowContract.Event) -> Unit
|
||||
){
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Запись изменений",
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
|
||||
Column (
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
modifier = Modifier.heightIn(max = 400.dp).verticalScroll(rememberScrollState())
|
||||
) {
|
||||
|
||||
val items = state.items
|
||||
|
||||
items.forEach {
|
||||
WriteItem(
|
||||
shapeType = items.takeShapeType(it),
|
||||
itemData = it
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.align(Alignment.End)
|
||||
) {
|
||||
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
onEvent(WriteFlowContract.Event.OnNavigateUp)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Отменить"
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
onEvent(WriteFlowContract.Event.OnWrite)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Записать"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun WritingState(
|
||||
state: WriteFlowContract.State.Writing,
|
||||
onEvent: (event: WriteFlowContract.Event) -> Unit
|
||||
){
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Запись изменений",
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(120.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
){
|
||||
|
||||
ContainedLoadingIndicator()
|
||||
|
||||
}
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.align(Alignment.End)
|
||||
) {
|
||||
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
onEvent(WriteFlowContract.Event.OnNavigateUp)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Отменить"
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
enabled = false,
|
||||
onClick = {}
|
||||
) {
|
||||
Text(
|
||||
text = "Записать"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ErrorState(
|
||||
state: WriteFlowContract.State.Error,
|
||||
onEvent: (event: WriteFlowContract.Event) -> Unit
|
||||
){
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Запись изменений",
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(120.dp)
|
||||
.padding(8.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
){
|
||||
|
||||
Image(
|
||||
|
||||
painter = painterResource(R.drawable.ic_error),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.weight(1f).aspectRatio(1f),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Ошибка записи"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.align(Alignment.End)
|
||||
) {
|
||||
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
onEvent(WriteFlowContract.Event.OnNavigateUp)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Отменить"
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
onEvent(WriteFlowContract.Event.OnWrite)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Повторить"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SuccessState(
|
||||
state: WriteFlowContract.State.Success,
|
||||
onEvent: (event: WriteFlowContract.Event) -> Unit
|
||||
){
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Запись изменений",
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(120.dp)
|
||||
.padding(8.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
){
|
||||
|
||||
Image(
|
||||
|
||||
painter = painterResource(R.drawable.ic_done),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.weight(1f).aspectRatio(1f),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Успешно завершено"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.align(Alignment.End)
|
||||
) {
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
onEvent(WriteFlowContract.Event.OnNavigateUp)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Ок"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WriteItem(
|
||||
shapeType: ShapeType,
|
||||
itemData: WriteItemData
|
||||
){
|
||||
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
shape = shapeType.shape
|
||||
) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(
|
||||
vertical = 8.dp,
|
||||
horizontal = 16.dp
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
|
||||
Text(text = itemData.title)
|
||||
|
||||
Text(
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
text = itemData.subtitle
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
package llc.arma.ble.app.ui.mapper
|
||||
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import javax.inject.Inject
|
||||
|
||||
class BleMapper @Inject constructor(
|
||||
private val txMapper: TxMapper
|
||||
) : Mapper<Ble, BleView> {
|
||||
|
||||
override fun map(input: Ble): BleView {
|
||||
return when(input){
|
||||
is Ble.Beacon -> {
|
||||
BleView.Beacon(
|
||||
info = input.info,
|
||||
state = BleView.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
)
|
||||
)
|
||||
}
|
||||
is Ble.Thermometer -> {
|
||||
BleView.Thermometer(
|
||||
info = input.info,
|
||||
state = BleView.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
),
|
||||
thermometerState = BleView.Thermometer.ThermometerState(
|
||||
temperature = BleView.Thermometer.ThermometerState.TemperatureState(input.thermometerState.temperature, false),
|
||||
historyInterval = input.thermometerState.historyInterval,
|
||||
saveHistory = input.thermometerState.saveHistory
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
is Ble.Accelerometer -> {
|
||||
BleView.Accelerometer(
|
||||
info = input.info,
|
||||
state = BleView.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
),
|
||||
accelerometerState = BleView.Accelerometer.AccelerometerState(
|
||||
saveHistorySettings = input.accelerometerState.saveHistorySettings,
|
||||
historyInterval = input.accelerometerState.historyInterval,
|
||||
readInterval = input.accelerometerState.readInterval
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
is Ble.Gate -> {
|
||||
BleView.Gate(
|
||||
info = input.info,
|
||||
state = BleView.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
),
|
||||
hostState = BleView.Gate.HostState(
|
||||
historyInterval = input.gateState.historyInterval,
|
||||
readInterval = input.gateState.readInterval
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
package llc.arma.ble.app.ui.mapper
|
||||
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import javax.inject.Inject
|
||||
|
||||
class BleViewMapper @Inject constructor(
|
||||
private val txMapper: TxViewMapper
|
||||
) : Mapper<BleView, Ble> {
|
||||
|
||||
override fun map(input: BleView): Ble {
|
||||
return when(input){
|
||||
is BleView.Beacon -> {
|
||||
Ble.Beacon(
|
||||
info = input.info,
|
||||
state = Ble.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
)
|
||||
)
|
||||
}
|
||||
is BleView.Thermometer -> {
|
||||
Ble.Thermometer(
|
||||
info = input.info,
|
||||
state = Ble.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
),
|
||||
thermometerState = Ble.Thermometer.ThermometerState(
|
||||
temperature = input.thermometerState.temperature.value,
|
||||
historyInterval = input.thermometerState.historyInterval,
|
||||
saveHistory = input.thermometerState.saveHistory
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
is BleView.Accelerometer -> {
|
||||
Ble.Accelerometer(
|
||||
info = input.info,
|
||||
state = Ble.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
),
|
||||
accelerometerState = Ble.Accelerometer.AccelerometerState(
|
||||
saveHistorySettings = input.accelerometerState.saveHistory,
|
||||
historyInterval = input.accelerometerState.historyInterval,
|
||||
readInterval = input.accelerometerState.readInterval
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
is BleView.Gate -> {
|
||||
Ble.Gate(
|
||||
info = input.info,
|
||||
state = Ble.BleState(
|
||||
tx = txMapper.map(input.state.tx),
|
||||
version = input.state.version
|
||||
),
|
||||
gateState = Ble.Gate.HostState(
|
||||
historyInterval = input.hostState.historyInterval,
|
||||
readInterval = input.hostState.readInterval
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package llc.arma.ble.app.ui.mapper
|
||||
|
||||
interface Mapper<I, O> {
|
||||
|
||||
fun map(input: I): O
|
||||
|
||||
fun map(input: List<I>): List<O> = input.map { map(it) }
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package llc.arma.ble.app.ui.mapper
|
||||
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import javax.inject.Inject
|
||||
|
||||
class TxMapper @Inject constructor() : Mapper<Ble.BleState.TX, BleView.BleState.TX> {
|
||||
|
||||
override fun map(input: Ble.BleState.TX): BleView.BleState.TX {
|
||||
return when(input){
|
||||
Ble.BleState.TX.MINUS_40 -> BleView.BleState.TX.MINUS_40
|
||||
Ble.BleState.TX.MINUS_20 -> BleView.BleState.TX.MINUS_20
|
||||
Ble.BleState.TX.MINUS_16 -> BleView.BleState.TX.MINUS_16
|
||||
Ble.BleState.TX.MINUS_12 -> BleView.BleState.TX.MINUS_12
|
||||
Ble.BleState.TX.MINUS_8 -> BleView.BleState.TX.MINUS_8
|
||||
Ble.BleState.TX.MINUS_4 -> BleView.BleState.TX.MINUS_4
|
||||
Ble.BleState.TX.ZERO -> BleView.BleState.TX.ZERO
|
||||
Ble.BleState.TX.PLUS_3 -> BleView.BleState.TX.PLUS_3
|
||||
Ble.BleState.TX.PLUS_4 -> BleView.BleState.TX.PLUS_4
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package llc.arma.ble.app.ui.mapper
|
||||
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import javax.inject.Inject
|
||||
|
||||
class TxViewMapper @Inject constructor() : Mapper<BleView.BleState.TX, Ble.BleState.TX> {
|
||||
|
||||
override fun map(input: BleView.BleState.TX): Ble.BleState.TX {
|
||||
return when(input){
|
||||
BleView.BleState.TX.MINUS_40 -> Ble.BleState.TX.MINUS_40
|
||||
BleView.BleState.TX.MINUS_20 -> Ble.BleState.TX.MINUS_20
|
||||
BleView.BleState.TX.MINUS_16 -> Ble.BleState.TX.MINUS_16
|
||||
BleView.BleState.TX.MINUS_12 -> Ble.BleState.TX.MINUS_12
|
||||
BleView.BleState.TX.MINUS_8 -> Ble.BleState.TX.MINUS_8
|
||||
BleView.BleState.TX.MINUS_4 -> Ble.BleState.TX.MINUS_4
|
||||
BleView.BleState.TX.ZERO -> Ble.BleState.TX.ZERO
|
||||
BleView.BleState.TX.PLUS_3 -> Ble.BleState.TX.PLUS_3
|
||||
BleView.BleState.TX.PLUS_4 -> Ble.BleState.TX.PLUS_4
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
package llc.arma.ble.app.ui.model
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import llc.arma.ble.data.repository.BleRepositoryImpl
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
|
||||
sealed class BleView(
|
||||
val info: BleInfo
|
||||
) {
|
||||
|
||||
class Accelerometer(
|
||||
info: BleInfo,
|
||||
val state: BleState,
|
||||
val accelerometerState: AccelerometerState
|
||||
) : BleView(info) {
|
||||
|
||||
class AccelerometerState(
|
||||
saveHistorySettings: Ble.Accelerometer.HistorySettings,
|
||||
historyInterval: Long,
|
||||
readInterval: Long
|
||||
) {
|
||||
var saveHistory by mutableStateOf(saveHistorySettings)
|
||||
var historyInterval by mutableLongStateOf(historyInterval)
|
||||
var readInterval by mutableLongStateOf(readInterval)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Beacon(
|
||||
info: BleInfo,
|
||||
val state: BleState
|
||||
) : BleView(info)
|
||||
|
||||
class Thermometer(
|
||||
info: BleInfo,
|
||||
val state: BleState,
|
||||
val thermometerState: ThermometerState
|
||||
) : BleView(info) {
|
||||
|
||||
class ThermometerState(
|
||||
temperature: TemperatureState,
|
||||
saveHistory: Boolean,
|
||||
historyInterval: Long
|
||||
) {
|
||||
|
||||
class TemperatureState(
|
||||
val value: Float,
|
||||
val loading: Boolean
|
||||
)
|
||||
|
||||
var temperature by mutableStateOf(temperature)
|
||||
var saveHistory by mutableStateOf(saveHistory)
|
||||
var historyInterval by mutableLongStateOf(historyInterval)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Gate(
|
||||
info: BleInfo,
|
||||
val state: BleState,
|
||||
val hostState: HostState
|
||||
) : BleView(info) {
|
||||
|
||||
class HostState(
|
||||
historyInterval: Long,
|
||||
readInterval: Long
|
||||
) {
|
||||
var historyInterval by mutableLongStateOf(historyInterval)
|
||||
var readInterval by mutableLongStateOf(readInterval)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BleState(
|
||||
tx: TX,
|
||||
val version: BleRepositoryImpl.Version
|
||||
){
|
||||
|
||||
var tx by mutableStateOf(tx)
|
||||
|
||||
enum class TX(val value: Int) {
|
||||
MINUS_40(-40),
|
||||
MINUS_20(-20),
|
||||
MINUS_16(-16),
|
||||
MINUS_12(-12),
|
||||
MINUS_8(-8),
|
||||
MINUS_4(-4),
|
||||
ZERO(0),
|
||||
PLUS_3(3),
|
||||
PLUS_4(4);
|
||||
|
||||
val powerPercentage: Int
|
||||
get() {
|
||||
return when(this){
|
||||
MINUS_40 -> 1
|
||||
MINUS_20 -> 5
|
||||
MINUS_16 -> 7
|
||||
MINUS_12 -> 10
|
||||
MINUS_8 -> 16
|
||||
MINUS_4 -> 20
|
||||
ZERO -> 40
|
||||
PLUS_3 -> 80
|
||||
PLUS_4 -> 100
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ import androidx.compose.material3.MaterialTheme
|
|||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package llc.arma.ble.app.ui.screen.ble
|
|||
import llc.arma.ble.app.ui.common.ViewEvent
|
||||
import llc.arma.ble.app.ui.common.ViewSideEffect
|
||||
import llc.arma.ble.app.ui.common.ViewState
|
||||
import llc.arma.ble.domain.model.BleFilter
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
|
||||
class BleListContract {
|
||||
|
|
@ -22,8 +21,18 @@ class BleListContract {
|
|||
|
||||
data class State(
|
||||
val bleList: List<BleInfo>,
|
||||
val bleFilter: BleFilter
|
||||
) : ViewState
|
||||
val filterIsEmpty: Boolean,
|
||||
val summary: BleSummary
|
||||
) : ViewState {
|
||||
|
||||
data class BleSummary(
|
||||
val all: Int,
|
||||
val lowBattery: Int,
|
||||
val lost: Int,
|
||||
val active: Int
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package llc.arma.ble.app.ui.screen.ble
|
||||
|
||||
import android.os.SystemClock
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
|
|
@ -20,17 +19,21 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.ContentAlpha
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowRightAlt
|
||||
import androidx.compose.material.icons.rounded.Battery1Bar
|
||||
import androidx.compose.material.icons.rounded.BatteryFull
|
||||
import androidx.compose.material.icons.rounded.CompareArrows
|
||||
import androidx.compose.material.icons.rounded.Bluetooth
|
||||
import androidx.compose.material.icons.rounded.FilterAlt
|
||||
import androidx.compose.material.icons.rounded.Link
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowDown
|
||||
import androidx.compose.material.icons.rounded.Summarize
|
||||
import androidx.compose.material.icons.rounded.TimerOff
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.FilledIconToggleButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
|
@ -38,21 +41,22 @@ import androidx.compose.material3.Scaffold
|
|||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
|
@ -63,25 +67,20 @@ import com.ramcosta.composedestinations.generated.destinations.AccelerometerScre
|
|||
import com.ramcosta.composedestinations.generated.destinations.BeaconScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.BleFilterScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.GateScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.ThermometerHistoryScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.ThermometerScreenDestination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.SignalLevel
|
||||
import llc.arma.ble.app.ui.common.rememberBottomDialogState
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.ShapeType.Companion.takeShapeType
|
||||
import llc.arma.ble.app.ui.screen.locale.icon
|
||||
import llc.arma.ble.domain.model.BleFilter
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
import llc.arma.ble.domain.model.ConnectedBleInfo
|
||||
import kotlin.math.pow
|
||||
|
||||
@Destination<RootGraph>(start = true)
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun BleListScreen(
|
||||
//onNavigationEvent: (BleListContract.Effect.Navigation) -> Unit
|
||||
|
|
@ -131,47 +130,16 @@ fun BleListScreen(
|
|||
},
|
||||
actions = {
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 8.dp)
|
||||
.align(Alignment.CenterVertically)
|
||||
) {
|
||||
|
||||
Text(text = "${state.bleList.size}")
|
||||
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
Text(text = "${state.bleList.filter {
|
||||
it.batteryLevel == 100
|
||||
}.filterNot { SystemClock.elapsedRealtime() - it.scanTime > 10_000 }.size}")
|
||||
|
||||
Text(text = " | ")
|
||||
|
||||
Text(
|
||||
text = "${state.bleList.filter { SystemClock.elapsedRealtime() - it.scanTime > 10_000 }.size}",
|
||||
color = LocalContentColor.current.copy(alpha = ContentAlpha.disabled)
|
||||
)
|
||||
|
||||
Text(text = " | ")
|
||||
|
||||
Text(
|
||||
text = "${state.bleList.filter { it.batteryLevel < 100 }.size}",
|
||||
color = MaterialTheme.colorScheme.error
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
FilledIconToggleButton(
|
||||
checked = state.filterIsEmpty.not(),
|
||||
onCheckedChange = {
|
||||
viewModel.setEvent(BleListContract.Event.OnShowFilter)
|
||||
}
|
||||
) {
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.FilterAlt,
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -183,39 +151,9 @@ fun BleListScreen(
|
|||
modifier = Modifier.padding(it)
|
||||
) {
|
||||
|
||||
val filteredData = remember(state.bleList, state.bleFilter) {
|
||||
var showSummary by remember { mutableStateOf(false) }
|
||||
|
||||
state.bleList.filter {
|
||||
(it.type == state.bleFilter.bleType || state.bleFilter.bleType == null) &&
|
||||
it.name.contains(state.bleFilter.name) &&
|
||||
it.serial.contains(state.bleFilter.mac) &&
|
||||
state.bleFilter.rssi.contains(it.rssi?.toFloat() ?: Float.MIN_VALUE) &&
|
||||
state.bleFilter.battery.contains(it.batteryLevel.toFloat())
|
||||
}.let {
|
||||
when (state.bleFilter.sortField) {
|
||||
BleFilter.Field.Name -> it.sortedBy { it.name }
|
||||
BleFilter.Field.Mac -> it.sortedBy { it.serial }
|
||||
BleFilter.Field.Distance -> it.sortedBy {
|
||||
10.0.pow(
|
||||
(it.tx.toDouble() - (it.rssi?.toDouble() ?: 0.0) - 74) / 20
|
||||
).toFloat()
|
||||
}
|
||||
|
||||
BleFilter.Field.Dbm -> it.sortedBy { it.rssi ?: 0 }
|
||||
BleFilter.Field.Battery -> it.sortedBy { it.batteryLevel }
|
||||
}
|
||||
}.let {
|
||||
|
||||
when (state.bleFilter.sortOrder) {
|
||||
BleFilter.Order.Asc -> it
|
||||
BleFilter.Order.Desc -> it.reversed()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(filteredData.isEmpty()){
|
||||
if(state.bleList.isEmpty()){
|
||||
LinearProgressIndicator(
|
||||
strokeCap = StrokeCap.Round,
|
||||
modifier = Modifier
|
||||
|
|
@ -224,7 +162,7 @@ fun BleListScreen(
|
|||
)
|
||||
}
|
||||
|
||||
if(filteredData.isEmpty()){
|
||||
if(state.bleList.isEmpty()){
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()){
|
||||
Text(
|
||||
|
|
@ -242,14 +180,130 @@ fun BleListScreen(
|
|||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
|
||||
item {
|
||||
|
||||
SummaryItem(
|
||||
shape = if(showSummary) ShapeType.Start else ShapeType.Singleton,
|
||||
onClick = { showSummary = showSummary.not() }
|
||||
) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
) {
|
||||
|
||||
if(showSummary) {
|
||||
|
||||
Text("Итоги")
|
||||
|
||||
} else {
|
||||
|
||||
Text("${state.summary.all} - ${state.summary.active} | ")
|
||||
|
||||
Text(
|
||||
text = "${state.summary.lost}",
|
||||
color = LocalContentColor.current.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
Text(" | ")
|
||||
|
||||
Text(
|
||||
text = "${state.summary.lowBattery}",
|
||||
color = MaterialTheme.colorScheme.error
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Spacer(
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.KeyboardArrowDown,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.rotate(if(showSummary) 180f else 0f)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(showSummary) {
|
||||
|
||||
item {
|
||||
|
||||
SummaryItem(
|
||||
shape = ShapeType.Middle,
|
||||
icon = Icons.Rounded.Summarize,
|
||||
onClick = { showSummary = true }
|
||||
) {
|
||||
|
||||
Text("Всего: ${state.summary.all}")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
item {
|
||||
|
||||
SummaryItem(
|
||||
shape = ShapeType.Middle,
|
||||
icon = Icons.Rounded.Bluetooth
|
||||
) {
|
||||
|
||||
Text("Активные: ${state.summary.active}")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
item {
|
||||
|
||||
SummaryItem(
|
||||
shape = ShapeType.Middle,
|
||||
icon = Icons.Rounded.TimerOff,
|
||||
contentColor = LocalContentColor.current.copy(alpha = 0.7f)
|
||||
) {
|
||||
|
||||
Text(
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
text = "Потерянные: ${state.summary.lost}"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
item {
|
||||
|
||||
SummaryItem(
|
||||
contentColor = MaterialTheme.colorScheme.error,
|
||||
shape = ShapeType.End,
|
||||
icon = Icons.Rounded.Battery1Bar
|
||||
) {
|
||||
Text("Разряженные: ${state.summary.lowBattery}")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
item {
|
||||
Spacer(
|
||||
modifier = Modifier.height(12.dp)
|
||||
)
|
||||
}
|
||||
|
||||
items(
|
||||
items = filteredData,
|
||||
items = state.bleList,
|
||||
key = { it.serial }
|
||||
) {
|
||||
|
||||
BleItem(
|
||||
ble = it,
|
||||
shapeType = filteredData.takeShapeType(it),
|
||||
shapeType = state.bleList.takeShapeType(it),
|
||||
onClick = {
|
||||
viewModel.setEvent(BleListContract.Event.OnConnectToBle(it.serial))
|
||||
}
|
||||
|
|
@ -264,7 +318,48 @@ fun BleListScreen(
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SummaryItem(
|
||||
shape: ShapeType,
|
||||
icon: ImageVector? = null,
|
||||
contentColor: Color = Color.Unspecified,
|
||||
onClick: (() -> Unit)? = null,
|
||||
label: @Composable () -> Unit
|
||||
){
|
||||
|
||||
Surface(
|
||||
shape = shape.shape,
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
|
||||
CompositionLocalProvider(LocalContentColor provides contentColor) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.clickable { onClick?.invoke() }.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
) {
|
||||
|
||||
if(icon != null) {
|
||||
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
label()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -301,6 +396,7 @@ private fun Int.toSignalLevel(): Int {
|
|||
fun BleItem(
|
||||
shapeType: ShapeType,
|
||||
ble: BleInfo,
|
||||
checked: Boolean,
|
||||
onClick: () -> Unit
|
||||
){
|
||||
|
||||
|
|
@ -313,7 +409,6 @@ fun BleItem(
|
|||
val highAlpha = ContentAlpha.high
|
||||
val disabledAlpha = ContentAlpha.disabled
|
||||
|
||||
|
||||
var time by remember {
|
||||
mutableLongStateOf(
|
||||
SystemClock.elapsedRealtime()
|
||||
|
|
@ -333,27 +428,118 @@ fun BleItem(
|
|||
highAlpha
|
||||
}
|
||||
|
||||
Surface(
|
||||
shape = shapeType.shape,
|
||||
color = color,
|
||||
onClick = onClick,
|
||||
modifier = Modifier
|
||||
.alpha(alpha)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(
|
||||
horizontal = 16.dp,
|
||||
vertical = 12.dp
|
||||
)
|
||||
) {
|
||||
|
||||
BleItemContent(
|
||||
ble = ble,
|
||||
color = color,
|
||||
time = time,
|
||||
)
|
||||
|
||||
Checkbox(
|
||||
checked = checked,
|
||||
onCheckedChange = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BleItem(
|
||||
shapeType: ShapeType,
|
||||
ble: BleInfo,
|
||||
onClick: () -> Unit
|
||||
){
|
||||
|
||||
val color = if(ble.batteryLevel < 100){
|
||||
MaterialTheme.colorScheme.errorContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.surfaceContainer
|
||||
}
|
||||
|
||||
var time by remember {
|
||||
mutableLongStateOf(
|
||||
SystemClock.elapsedRealtime()
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(ble.scanTime) {
|
||||
while(true) {
|
||||
time = SystemClock.elapsedRealtime()
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
|
||||
val alpha = if(time - ble.scanTime > 10_000){
|
||||
ContentAlpha.disabled
|
||||
} else {
|
||||
ContentAlpha.high
|
||||
}
|
||||
|
||||
Surface(
|
||||
shape = shapeType.shape,
|
||||
color = color,
|
||||
onClick = onClick,
|
||||
modifier = Modifier
|
||||
.alpha(alpha)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
|
||||
BleItemContent(
|
||||
ble = ble,
|
||||
color = color,
|
||||
time = time,
|
||||
modifier = Modifier.padding(
|
||||
horizontal = 16.dp, vertical = 12.dp
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BleItemContent(
|
||||
ble: BleInfo,
|
||||
color: Color,
|
||||
time: Long,
|
||||
modifier: Modifier = Modifier
|
||||
){
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(shapeType.shape)
|
||||
.background(color)
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||
.alpha(alpha)
|
||||
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Box {
|
||||
|
||||
ItemIcon {
|
||||
|
||||
Icon(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
imageVector = ble.type.icon,
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
if(ble.tableStatus !== BleInfo.HistoryTableStatus.DISABLED){
|
||||
|
|
@ -403,7 +589,7 @@ fun BleItem(
|
|||
modifier = Modifier.alpha(0.7f)
|
||||
) {
|
||||
|
||||
val color = if(ble.batteryLevel < 100){
|
||||
val contentColor = if(ble.batteryLevel < 100){
|
||||
MaterialTheme.colorScheme.error
|
||||
} else {
|
||||
LocalContentColor.current
|
||||
|
|
@ -413,7 +599,7 @@ fun BleItem(
|
|||
modifier = Modifier.size(16.dp),
|
||||
imageVector = Icons.Rounded.BatteryFull,
|
||||
contentDescription = null,
|
||||
tint = color
|
||||
tint = contentColor
|
||||
)
|
||||
|
||||
Box {
|
||||
|
|
@ -427,7 +613,7 @@ fun BleItem(
|
|||
Text(
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
text = ble.batteryLevel.toString() + " %",
|
||||
color = color
|
||||
color = contentColor
|
||||
)
|
||||
|
||||
}
|
||||
|
|
@ -447,16 +633,8 @@ fun BleItem(
|
|||
modifier = Modifier.alpha(0.7f)
|
||||
) {
|
||||
|
||||
Icon(
|
||||
modifier = Modifier.size(16.dp),
|
||||
imageVector = Icons.Rounded.CompareArrows,
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
|
||||
val distance = remember(ble.rssi, ble.tx) {
|
||||
String.format("%.3f", (10.0.pow((ble.tx.toDouble() - (ble.rssi?.toDouble() ?: 0.0) - 74) / 20))) + " м."
|
||||
String.format("%.2f", (10.0.pow((ble.tx.toDouble() - (ble.rssi?.toDouble() ?: 0.0) - 74) / 20))) + " м."
|
||||
}
|
||||
|
||||
Text(
|
||||
|
|
@ -474,7 +652,7 @@ fun BleItem(
|
|||
SignalLevel(level = ble.rssi?.toSignalLevel() ?: 0)
|
||||
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
|
||||
|
||||
Box {
|
||||
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
package llc.arma.ble.app.ui.screen.ble
|
||||
|
||||
import android.os.SystemClock
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.domain.model.BleFilter
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
import llc.arma.ble.domain.usecase.GetBleAroundFlow
|
||||
import llc.arma.ble.domain.usecase.filter.GetFilterFlow
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.pow
|
||||
|
||||
@HiltViewModel
|
||||
class BleListViewModel @Inject constructor(
|
||||
|
|
@ -19,25 +20,8 @@ class BleListViewModel @Inject constructor(
|
|||
private val getBleAroundFlow: GetBleAroundFlow
|
||||
) : BaseViewModel<BleListContract.State, BleListContract.Event, BleListContract.Effect>() {
|
||||
|
||||
private var scannerJob: Job? = null
|
||||
|
||||
init {
|
||||
|
||||
viewModelScope.launch {
|
||||
|
||||
getFilterFlow.invoke().onEach {
|
||||
setState {
|
||||
copy(
|
||||
bleFilter = it
|
||||
)
|
||||
}
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun setInitialState(): BleListContract.State =
|
||||
BleListContract.State(emptyList(), BleFilter())
|
||||
BleListContract.State(emptyList(), false, BleListContract.State.BleSummary(0,0,0,0))
|
||||
|
||||
override fun handleEvents(event: BleListContract.Event) {
|
||||
when(event){
|
||||
|
|
@ -86,6 +70,8 @@ class BleListViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private var scannerJob: Job? = null
|
||||
|
||||
private fun reduce(
|
||||
state: BleListContract.State,
|
||||
event: BleListContract.Event.OnResetScanner
|
||||
|
|
@ -93,12 +79,50 @@ class BleListViewModel @Inject constructor(
|
|||
|
||||
scannerJob?.cancel()
|
||||
|
||||
scannerJob = getBleAroundFlow().onEach {
|
||||
scannerJob = getFilterFlow().combine(getBleAroundFlow()){ filter, ble ->
|
||||
|
||||
val bleList = ble.filter {
|
||||
(it.type == filter.bleType || filter.bleType == null) &&
|
||||
it.name.contains(filter.name) &&
|
||||
it.serial.contains(filter.mac) &&
|
||||
filter.rssi.contains(it.rssi?.toFloat() ?: Float.MIN_VALUE) &&
|
||||
filter.battery.contains(it.batteryLevel.toFloat())
|
||||
}.let {
|
||||
when (filter.sortField) {
|
||||
BleFilter.Field.Name -> it.sortedBy { it.name }
|
||||
BleFilter.Field.Mac -> it.sortedBy { it.serial }
|
||||
BleFilter.Field.Distance -> it.sortedBy {
|
||||
10.0.pow(
|
||||
(it.tx.toDouble() - (it.rssi?.toDouble() ?: 0.0) - 74) / 20
|
||||
).toFloat()
|
||||
}
|
||||
|
||||
BleFilter.Field.Dbm -> it.sortedBy { it.rssi ?: 0 }
|
||||
BleFilter.Field.Battery -> it.sortedBy { it.batteryLevel }
|
||||
}
|
||||
}.let {
|
||||
|
||||
when (filter.sortOrder) {
|
||||
BleFilter.Order.Asc -> it
|
||||
BleFilter.Order.Desc -> it.reversed()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setState {
|
||||
copy(
|
||||
bleList = it
|
||||
BleListContract.State(
|
||||
bleList,
|
||||
filter == BleFilter(),
|
||||
BleListContract.State.BleSummary(
|
||||
all = ble.size,
|
||||
active = ble.filter { it.batteryLevel == 100 }
|
||||
.filterNot { SystemClock.elapsedRealtime() - it.scanTime > 10_000 }.size,
|
||||
lost = ble.count { SystemClock.elapsedRealtime() - it.scanTime > 10_000 },
|
||||
lowBattery = ble.count { it.batteryLevel < 100 }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,129 +0,0 @@
|
|||
package llc.arma.ble.app.ui.screen.connection
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import llc.arma.ble.app.ui.common.ViewEvent
|
||||
import llc.arma.ble.app.ui.common.ViewSideEffect
|
||||
import llc.arma.ble.app.ui.common.ViewState
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.main.GateContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.main.ThermometerContract
|
||||
import llc.arma.ble.domain.common.BleException
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
import llc.arma.ble.domain.usecase.FftFrequency
|
||||
import llc.arma.ble.domain.usecase.FftViewMode
|
||||
|
||||
class ConnectionContract {
|
||||
|
||||
sealed class Event : ViewEvent {
|
||||
|
||||
data object RefreshBle : Event()
|
||||
|
||||
data object OnNavigateUp : Event()
|
||||
|
||||
data class OnBeaconNavigationEvent(
|
||||
val event: BeaconContract.Effect.Navigation
|
||||
) : Event()
|
||||
|
||||
data class OnHostNavigationEvent(
|
||||
val event: GateContract.Effect.Navigation
|
||||
) : Event()
|
||||
|
||||
data class OnThermometerNavigationEvent(
|
||||
val event: ThermometerContract.Effect.Navigation
|
||||
) : Event()
|
||||
|
||||
data class OnAccelNavigationEvent(
|
||||
val event: AccelerometerContract.Effect.Navigation
|
||||
) : Event()
|
||||
|
||||
|
||||
}
|
||||
|
||||
sealed class State : ViewState {
|
||||
|
||||
data object Loading : State()
|
||||
|
||||
data class DisplayException(
|
||||
val tries: Long,
|
||||
val exception: BleException
|
||||
) : State()
|
||||
|
||||
data class Display(
|
||||
val ble: Ble
|
||||
) : State()
|
||||
|
||||
}
|
||||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
sealed class Navigation : Effect() {
|
||||
|
||||
data object NavigateUp : Navigation()
|
||||
|
||||
data class NavigateToChangePassword(
|
||||
val serial: String
|
||||
) : Navigation()
|
||||
|
||||
data class NavigateToRotationsStatistic(
|
||||
val serial: String
|
||||
) : Navigation()
|
||||
|
||||
data class NavigateToThermometerHistory(
|
||||
val bleSerial: String
|
||||
) : Navigation()
|
||||
|
||||
}
|
||||
|
||||
sealed class InnerNavigation : Effect() {
|
||||
|
||||
@Parcelize
|
||||
data class NavigateToAccelHistory(
|
||||
val ble: BleInfo,
|
||||
val accelScale: AccelScale,
|
||||
val accelMode: AccelViewMode,
|
||||
val fftAxis: FftAxis,
|
||||
val fftMode: FftViewMode,
|
||||
val frequency: FftFrequency
|
||||
) : InnerNavigation(), Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class NavigateToAccelRealtime(
|
||||
val ble: BleInfo,
|
||||
val accelScale: AccelScale,
|
||||
val accelMode: AccelViewMode,
|
||||
val fftAxis: FftAxis,
|
||||
val fftMode: FftViewMode,
|
||||
val frequency: FftFrequency
|
||||
) : InnerNavigation(), Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class NavigateToAccelSpectre(
|
||||
val ble: BleInfo,
|
||||
val accelScale: AccelScale,
|
||||
val accelMode: AccelViewMode,
|
||||
val fftAxis: FftAxis,
|
||||
val fftMode: FftViewMode,
|
||||
val frequency: FftFrequency
|
||||
) : InnerNavigation(), Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class NavigateToHostHistory(
|
||||
val ble: BleInfo
|
||||
) : InnerNavigation(), Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class NavigateHostToBleTable(
|
||||
val serial: String
|
||||
) : InnerNavigation(), Parcelable
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,326 +0,0 @@
|
|||
package llc.arma.ble.app.ui.screen.connection
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.SizeTransform
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material3.ContainedLoadingIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import llc.arma.ble.app.ui.common.SmallPrimaryButton
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ConnectionScreen(
|
||||
onNavigationEvent: (ConnectionContract.Effect.Navigation) -> Unit
|
||||
) {
|
||||
|
||||
val viewModel = hiltViewModel<ConnectionViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
var innerScreen by rememberSaveable {
|
||||
mutableStateOf<ConnectionContract.Effect.InnerNavigation?>(null)
|
||||
}
|
||||
|
||||
BackHandler(innerScreen != null) {
|
||||
innerScreen = null
|
||||
}
|
||||
|
||||
LaunchedEffect("effect"){
|
||||
viewModel.effect.onEach {
|
||||
when(it){
|
||||
is ConnectionContract.Effect.Navigation -> onNavigationEvent(it)
|
||||
is ConnectionContract.Effect.InnerNavigation -> {
|
||||
innerScreen = it
|
||||
}
|
||||
}
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
TopAppBar(
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
if(innerScreen != null) {
|
||||
innerScreen = null
|
||||
} else {
|
||||
viewModel.setEvent(ConnectionContract.Event.OnNavigateUp)
|
||||
}
|
||||
},
|
||||
content = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.ArrowBack,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
title = {
|
||||
|
||||
AnimatedContent(
|
||||
targetState = when (state) {
|
||||
is ConnectionContract.State.Display -> state.ble.info.name
|
||||
is ConnectionContract.State.DisplayException -> "Исключение"
|
||||
is ConnectionContract.State.Loading -> "Соединение.."
|
||||
},
|
||||
transitionSpec = {
|
||||
((slideInVertically { height -> height } + fadeIn()).togetherWith(
|
||||
slideOutVertically { height -> -height } + fadeOut())).using(
|
||||
SizeTransform(clip = false)
|
||||
)
|
||||
}
|
||||
) { targetText ->
|
||||
Text(
|
||||
text = targetText
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
/*when (state) {
|
||||
is ConnectionContract.State.DisplayException -> DisplayException(
|
||||
viewState = state,
|
||||
onEvent = viewModel::setEvent
|
||||
)
|
||||
|
||||
is ConnectionContract.State.Loading -> LoadingState()
|
||||
is ConnectionContract.State.Display -> {
|
||||
when (state.ble) {
|
||||
is Ble.Beacon -> BeaconScreen(
|
||||
null,
|
||||
onNavigationEvent = {
|
||||
viewModel.setEvent(
|
||||
ConnectionContract.Event.OnBeaconNavigationEvent(
|
||||
it
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
is Ble.Thermometer -> {
|
||||
|
||||
ThermometerScreen(
|
||||
txSelectResult = null,
|
||||
//ble = state.ble,
|
||||
onNavigationEvent = {
|
||||
viewModel.setEvent(
|
||||
ConnectionContract.Event.OnThermometerNavigationEvent(
|
||||
it
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
is Ble.Accelerometer -> {
|
||||
/*AccelerometerScreen {
|
||||
viewModel.setEvent(
|
||||
ConnectionContract.Event.OnAccelNavigationEvent(it)
|
||||
)
|
||||
}*/
|
||||
}
|
||||
|
||||
is Ble.Gate -> {
|
||||
GateScreen(
|
||||
null,
|
||||
null,
|
||||
onNavigationEvent = {
|
||||
viewModel.setEvent(
|
||||
ConnectionContract.Event.OnHostNavigationEvent(it)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
innerScreen?.let {
|
||||
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
|
||||
when(it){
|
||||
is ConnectionContract.Effect.InnerNavigation.NavigateToAccelHistory -> {
|
||||
|
||||
AccelerometerHistory(
|
||||
ble = it.ble,
|
||||
accelMode = it.accelMode,
|
||||
fftAxis = it.fftAxis,
|
||||
fftMode = it.fftMode,
|
||||
frequency = it.frequency,
|
||||
accelScale = it.accelScale,
|
||||
onDismiss = {
|
||||
innerScreen = null
|
||||
}
|
||||
){
|
||||
onNavigationEvent(ConnectionContract.Effect.Navigation.NavigateToRotationsStatistic(it.ble.serial))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
is ConnectionContract.Effect.InnerNavigation.NavigateToAccelRealtime -> {
|
||||
AccelerometerRealtime(
|
||||
ble = it.ble,
|
||||
accelMode = it.accelMode,
|
||||
fftAxis = it.fftAxis,
|
||||
fftMode = it.fftMode,
|
||||
frequency = it.frequency,
|
||||
accelScale = it.accelScale,
|
||||
onDismiss = {
|
||||
innerScreen = null
|
||||
}
|
||||
)
|
||||
}
|
||||
is ConnectionContract.Effect.InnerNavigation.NavigateToAccelSpectre -> {
|
||||
AccelerometerSpectre(
|
||||
ble = it.ble,
|
||||
accelMode = it.accelMode,
|
||||
fftAxis = it.fftAxis,
|
||||
fftMode = it.fftMode,
|
||||
frequency = it.frequency,
|
||||
accelScale = it.accelScale,
|
||||
onDismiss = {
|
||||
innerScreen = null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
is ConnectionContract.Effect.InnerNavigation.NavigateToHostHistory -> {
|
||||
/*GateHistoryScreen(
|
||||
ble = it.ble,
|
||||
onDismiss = {
|
||||
innerScreen = null
|
||||
}
|
||||
)*/
|
||||
|
||||
}
|
||||
|
||||
is ConnectionContract.Effect.InnerNavigation.NavigateHostToBleTable -> {
|
||||
|
||||
GateBleTableScreen {
|
||||
when(it){
|
||||
GateBleTableContract.Effect.Navigation.Up -> {
|
||||
innerScreen = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
private fun LoadingState(){
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
ContainedLoadingIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
private fun DisplayException(
|
||||
viewState: ConnectionContract.State.DisplayException,
|
||||
onEvent: (ConnectionContract.Event) -> Unit
|
||||
){
|
||||
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.align(Alignment.Center).widthIn(max = 270.dp)
|
||||
) {
|
||||
|
||||
|
||||
ContainedLoadingIndicator()
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
text = "Повторная попытка ${viewState.tries}"
|
||||
)
|
||||
|
||||
Text(
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
text = "Неудалось соединится с устройством"
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
|
||||
SmallPrimaryButton(
|
||||
label = "Отмена"
|
||||
) {
|
||||
onEvent(ConnectionContract.Event.OnNavigateUp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,240 +0,0 @@
|
|||
package llc.arma.ble.app.ui.screen.connection
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
|
||||
import llc.arma.ble.domain.usecase.GetBleBySerial
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class ConnectionViewModel @Inject constructor(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
private val getBleBySerial: GetBleBySerial,
|
||||
) : BaseViewModel<ConnectionContract.State, ConnectionContract.Event, ConnectionContract.Effect>() {
|
||||
|
||||
init {
|
||||
refreshBle()
|
||||
}
|
||||
|
||||
override fun setInitialState() = ConnectionContract.State.Loading
|
||||
|
||||
override fun handleEvents(event: ConnectionContract.Event) {
|
||||
when(event){
|
||||
is ConnectionContract.Event.OnBeaconNavigationEvent -> reduce(viewState.value, event)
|
||||
is ConnectionContract.Event.OnHostNavigationEvent -> reduce(viewState.value, event)
|
||||
is ConnectionContract.Event.OnNavigateUp -> reduce(viewState.value, event)
|
||||
is ConnectionContract.Event.OnThermometerNavigationEvent -> reduce(viewState.value, event)
|
||||
is ConnectionContract.Event.RefreshBle -> reduce(viewState.value, event)
|
||||
is ConnectionContract.Event.OnAccelNavigationEvent -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: ConnectionContract.State,
|
||||
event: ConnectionContract.Event.OnHostNavigationEvent
|
||||
) {
|
||||
/*when(event.event){
|
||||
GateContract.Effect.Navigation.Up -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateUp
|
||||
}
|
||||
}
|
||||
is GateContract.Effect.Navigation.ChangePassword -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateToChangePassword(savedStateHandle.get<String>("serial")!!)
|
||||
}
|
||||
}
|
||||
|
||||
is GateContract.Effect.Navigation.GateHistory -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.InnerNavigation.NavigateToHostHistory(
|
||||
event.event.ble
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is GateContract.Effect.Navigation.BleTable -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.InnerNavigation.NavigateHostToBleTable(
|
||||
event.event.serial
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is GateContract.Effect.Navigation.TxSelector -> TODO()
|
||||
is GateContract.Effect.Navigation.ReadIntervalSelector -> TODO()
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: ConnectionContract.State,
|
||||
event: ConnectionContract.Event.OnBeaconNavigationEvent
|
||||
) {
|
||||
when(event.event){
|
||||
BeaconContract.Effect.Navigation.Up -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateUp
|
||||
}
|
||||
}
|
||||
is BeaconContract.Effect.Navigation.PasswordForm -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateToChangePassword(savedStateHandle.get<String>("serial")!!)
|
||||
}
|
||||
}
|
||||
|
||||
is BeaconContract.Effect.Navigation.TxSelector -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: ConnectionContract.State,
|
||||
event: ConnectionContract.Event.OnThermometerNavigationEvent
|
||||
) {
|
||||
/*(event.event){
|
||||
ThermometerContract.Effect.Navigation.Up -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateUp
|
||||
}
|
||||
}
|
||||
ThermometerContract.Effect.Navigation.ChangePassword -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateToChangePassword(savedStateHandle.get<String>("serial")!!)
|
||||
}
|
||||
}
|
||||
|
||||
is ThermometerContract.Effect.Navigation.ThermometerHistory -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateToThermometerHistory(event.event.bleSerial)
|
||||
}
|
||||
}
|
||||
|
||||
is ThermometerContract.Effect.Navigation.TxSelector -> TODO()
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: ConnectionContract.State,
|
||||
event: ConnectionContract.Event.OnAccelNavigationEvent
|
||||
) {
|
||||
/*when(event.event){
|
||||
is AccelerometerContract.Effect.Navigation.ChangePassword -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateToChangePassword(savedStateHandle.get<String>("serial")!!)
|
||||
}
|
||||
}
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.AccelHistory -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.InnerNavigation.NavigateToAccelHistory(
|
||||
event.event.ble,
|
||||
event.event.accelScale,
|
||||
event.event.accelMode,
|
||||
event.event.fftAxis,
|
||||
event.event.fftMode,
|
||||
event.event.frequency
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.AccelRealtime -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.InnerNavigation.NavigateToAccelRealtime(
|
||||
event.event.ble,
|
||||
event.event.accelScale,
|
||||
event.event.accelMode,
|
||||
event.event.fftAxis,
|
||||
event.event.fftMode,
|
||||
event.event.frequency
|
||||
)
|
||||
}
|
||||
}
|
||||
is AccelerometerContract.Effect.Navigation.AccelSpectre -> {
|
||||
setEffect {
|
||||
ConnectionContract.Effect.InnerNavigation.NavigateToAccelSpectre(
|
||||
event.event.ble,
|
||||
event.event.accelScale,
|
||||
event.event.accelMode,
|
||||
event.event.fftAxis,
|
||||
event.event.fftMode,
|
||||
event.event.frequency
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.TxPowerSelector -> TODO()
|
||||
is AccelerometerContract.Effect.Navigation.ReadIntervalSelector -> TODO()
|
||||
is AccelerometerContract.Effect.Navigation.SaveIntervalSelector -> TODO()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: ConnectionContract.State,
|
||||
event: ConnectionContract.Event.OnNavigateUp
|
||||
) {
|
||||
|
||||
setEffect {
|
||||
ConnectionContract.Effect.Navigation.NavigateUp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: ConnectionContract.State,
|
||||
event: ConnectionContract.Event.RefreshBle
|
||||
) {
|
||||
|
||||
refreshBle()
|
||||
|
||||
}
|
||||
|
||||
private fun refreshBle(){
|
||||
/*val serial = savedStateHandle.get<String>("serial")
|
||||
|
||||
if(serial != null){
|
||||
|
||||
viewModelScope.launch {
|
||||
|
||||
setState {
|
||||
ConnectionContract.State.Loading
|
||||
}
|
||||
|
||||
var tries = 0L
|
||||
|
||||
while (true) {
|
||||
|
||||
getBleBySerial(serial, this).fold(
|
||||
onSuccess = {
|
||||
|
||||
it.onEach {
|
||||
setState {
|
||||
ConnectionContract.State.Display(
|
||||
ble = it
|
||||
)
|
||||
}
|
||||
}.launchIn(viewModelScope)
|
||||
|
||||
return@launch
|
||||
|
||||
},
|
||||
onFailure = {
|
||||
setState {
|
||||
tries += 1
|
||||
ConnectionContract.State.DisplayException(tries, it)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw IllegalArgumentException("serial arg must not be null")
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ class BleFilterContract {
|
|||
data object Loading : State()
|
||||
|
||||
data class Display(
|
||||
val origin: BleFilter,
|
||||
val filter: BleFilter
|
||||
) : State()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package llc.arma.ble.app.ui.screen.filter
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -152,399 +153,447 @@ private fun DisplayState(
|
|||
state: BleFilterContract.State.Display
|
||||
){
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
Column {
|
||||
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 16.dp)
|
||||
.padding(bottom = 16.dp)
|
||||
) {
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.padding(16.dp)
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
val sortTextFileState = TextFieldState(
|
||||
state.filter.sortField.localized,
|
||||
TextRange(state.filter.sortField.localized.length)
|
||||
)
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 8.dp),
|
||||
expanded = expanded,
|
||||
onExpandedChange = {
|
||||
expanded = it
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
OutlinedTextField(
|
||||
state = sortTextFileState,
|
||||
readOnly = true,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
label = { Text("Сортировка") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.Sort,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
ExposedDropdownMenu(
|
||||
val sortTextFileState = remember(state.filter.sortField) {
|
||||
TextFieldState(
|
||||
state.filter.sortField.localized,
|
||||
TextRange(state.filter.sortField.localized.length)
|
||||
)
|
||||
}
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 8.dp),
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
onExpandedChange = {
|
||||
expanded = it
|
||||
}
|
||||
) {
|
||||
|
||||
BleFilter.Field.entries.forEach { selectionOption ->
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(
|
||||
sortField = selectionOption
|
||||
OutlinedTextField(
|
||||
state = sortTextFileState,
|
||||
readOnly = true,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
label = { Text("Сортировка") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.Sort,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
|
||||
ExposedDropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
) {
|
||||
|
||||
BleFilter.Field.entries.forEach { selectionOption ->
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(
|
||||
sortField = selectionOption
|
||||
)
|
||||
)
|
||||
)
|
||||
))
|
||||
expanded = false
|
||||
},
|
||||
text = {
|
||||
Text(text = selectionOption.localized)
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
expanded = false
|
||||
},
|
||||
text = {
|
||||
Text(text = selectionOption.localized)
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val sortTextFieldState = TextFieldState(
|
||||
state.filter.sortOrder.localized,
|
||||
TextRange(state.filter.sortOrder.localized.length)
|
||||
)
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 8.dp),
|
||||
expanded = expanded,
|
||||
onExpandedChange = {
|
||||
expanded = it
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
OutlinedTextField(
|
||||
state = sortTextFieldState,
|
||||
readOnly = true,
|
||||
label = { Text("Напрвление сортировки") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.SortByAlpha,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
ExposedDropdownMenu(
|
||||
val sortTextFieldState = remember(state.filter.sortOrder) {
|
||||
TextFieldState(
|
||||
state.filter.sortOrder.localized,
|
||||
TextRange(state.filter.sortOrder.localized.length)
|
||||
)
|
||||
}
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 8.dp),
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
onExpandedChange = {
|
||||
expanded = it
|
||||
}
|
||||
) {
|
||||
|
||||
BleFilter.Order.entries.forEach { selectionOption ->
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(sortOrder = selectionOption)
|
||||
))
|
||||
expanded = false
|
||||
},
|
||||
text = {
|
||||
Text(text = selectionOption.localized)
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
OutlinedTextField(
|
||||
state = sortTextFieldState,
|
||||
readOnly = true,
|
||||
label = { Text("Напрвление сортировки") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.SortByAlpha,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
|
||||
ExposedDropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
) {
|
||||
|
||||
BleFilter.Order.entries.forEach { selectionOption ->
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(sortOrder = selectionOption)
|
||||
)
|
||||
)
|
||||
expanded = false
|
||||
},
|
||||
text = {
|
||||
Text(text = selectionOption.localized)
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val typeTextFiledState = TextFieldState(
|
||||
state.filter.bleType.localized,
|
||||
TextRange(state.filter.bleType.localized.length)
|
||||
)
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 8.dp),
|
||||
expanded = expanded,
|
||||
onExpandedChange = {
|
||||
expanded = it
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
OutlinedTextField(
|
||||
state = typeTextFiledState,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
readOnly = true,
|
||||
label = { Text("Тип") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Bluetooth,
|
||||
contentDescription = null
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
ExposedDropdownMenu(
|
||||
val typeTextFiledState = remember(state.filter.bleType) {
|
||||
TextFieldState(
|
||||
state.filter.bleType.localized,
|
||||
TextRange(state.filter.bleType.localized.length)
|
||||
)
|
||||
}
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 8.dp),
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
onExpandedChange = {
|
||||
expanded = it
|
||||
}
|
||||
) {
|
||||
|
||||
mutableListOf<BleInfo.Type?>(null).apply {
|
||||
addAll(BleInfo.Type.entries.toTypedArray())
|
||||
}.forEach { selectionOption ->
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(bleType = selectionOption)
|
||||
))
|
||||
expanded = false
|
||||
},
|
||||
text = {
|
||||
Text(text = selectionOption.localized)
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
OutlinedTextField(
|
||||
state = typeTextFiledState,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
readOnly = true,
|
||||
label = { Text("Тип") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Bluetooth,
|
||||
contentDescription = null
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||
expanded = expanded
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
|
||||
ExposedDropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
) {
|
||||
|
||||
mutableListOf<BleInfo.Type?>(null).apply {
|
||||
addAll(BleInfo.Type.entries.toTypedArray())
|
||||
}.forEach { selectionOption ->
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(bleType = selectionOption)
|
||||
)
|
||||
)
|
||||
expanded = false
|
||||
},
|
||||
text = {
|
||||
Text(text = selectionOption.localized)
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = state.filter.name,
|
||||
singleLine = true,
|
||||
onValueChange = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(name = it)
|
||||
)
|
||||
)
|
||||
},
|
||||
label = { Text(text = "Имя") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Search,
|
||||
contentDescription = null
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
|
||||
if (state.filter.name.isNotEmpty()) {
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(name = "")
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Close,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
.fillMaxWidth()
|
||||
|
||||
)
|
||||
|
||||
OutlinedTextField(
|
||||
value = state.filter.mac,
|
||||
singleLine = true,
|
||||
onValueChange = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(mac = it)
|
||||
)
|
||||
)
|
||||
},
|
||||
label = { Text(text = "Mac") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.ShortText,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
|
||||
if (state.filter.mac.isNotEmpty()) {
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(mac = "")
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Close,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
.fillMaxWidth()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = state.filter.name,
|
||||
singleLine = true,
|
||||
onValueChange = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(name = it)
|
||||
))
|
||||
},
|
||||
label = { Text(text = "Имя") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Search,
|
||||
contentDescription = null
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
|
||||
if(state.filter.name.isNotEmpty()) {
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(name = "")
|
||||
))
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Close,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
.fillMaxWidth()
|
||||
|
||||
)
|
||||
|
||||
OutlinedTextField(
|
||||
value = state.filter.mac,
|
||||
singleLine = true,
|
||||
onValueChange = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(mac = it)
|
||||
))
|
||||
},
|
||||
label = { Text(text = "Mac") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.ShortText,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
|
||||
if (state.filter.mac.isNotEmpty()) {
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(mac = "")
|
||||
))
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Close,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
.fillMaxWidth()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
) {
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.SignalCellularAlt,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
|
||||
Column {
|
||||
|
||||
RangeSlider(
|
||||
value = state.filter.rssi,
|
||||
onValueChange = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(rssi = it)
|
||||
)
|
||||
)
|
||||
},
|
||||
valueRange = (-100f)..(-10f),
|
||||
colors = SliderDefaults.colors(
|
||||
activeTickColor = MaterialTheme.colorScheme.primary,
|
||||
inactiveTickColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.38f)
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.SignalCellularAlt,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
|
||||
Row {
|
||||
Column {
|
||||
|
||||
Text(text = state.filter.rssi.start.toInt().toString() + " dBm")
|
||||
var sliderState by remember(state.filter.rssi) {
|
||||
mutableStateOf(state.filter.rssi)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
RangeSlider(
|
||||
value = sliderState,
|
||||
onValueChange = {
|
||||
sliderState = it
|
||||
},
|
||||
onValueChangeFinished = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(rssi = sliderState)
|
||||
)
|
||||
)
|
||||
},
|
||||
valueRange = (-100f)..(-10f),
|
||||
colors = SliderDefaults.colors(
|
||||
activeTickColor = MaterialTheme.colorScheme.primary,
|
||||
inactiveTickColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.38f)
|
||||
)
|
||||
)
|
||||
|
||||
Text(text = state.filter.rssi.endInclusive.toInt().toString() + " dBm")
|
||||
Row {
|
||||
|
||||
Text(text = state.filter.rssi.start.toInt().toString() + " dBm")
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Text(
|
||||
text = state.filter.rssi.endInclusive.toInt()
|
||||
.toString() + " dBm"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.BatteryFull,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
|
||||
RangeSlider(
|
||||
value = state.filter.battery,
|
||||
onValueChange = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(battery = it)
|
||||
)
|
||||
)
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
colors = SliderDefaults.colors(
|
||||
activeTickColor = MaterialTheme.colorScheme.primary,
|
||||
inactiveTickColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.38f)
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.BatteryFull,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
|
||||
Row {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
|
||||
Text(text = state.filter.battery.start.toInt().toString() + " %")
|
||||
var sliderState by remember(state.filter.battery) {
|
||||
mutableStateOf(state.filter.battery)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
RangeSlider(
|
||||
value = sliderState,
|
||||
onValueChange = {
|
||||
sliderState = it
|
||||
},
|
||||
onValueChangeFinished = {
|
||||
viewModel.setEvent(
|
||||
BleFilterContract.Event.OnFilterChanged(
|
||||
state.filter.copy(battery = sliderState)
|
||||
)
|
||||
)
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
colors = SliderDefaults.colors(
|
||||
activeTickColor = MaterialTheme.colorScheme.primary,
|
||||
inactiveTickColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.38f)
|
||||
)
|
||||
)
|
||||
|
||||
Text(text = state.filter.battery.endInclusive.toInt().toString() + " %")
|
||||
Row {
|
||||
|
||||
Text(text = state.filter.battery.start.toInt().toString() + " %")
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Text(
|
||||
text = state.filter.battery.endInclusive.toInt()
|
||||
.toString() + " %"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -556,17 +605,28 @@ private fun DisplayState(
|
|||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnSave)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth().animateContentSize()
|
||||
) {
|
||||
Text(
|
||||
text = "Применить"
|
||||
)
|
||||
|
||||
if(state.filter != state.origin) {
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
viewModel.setEvent(BleFilterContract.Event.OnSave)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Применить"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class BleFilterViewModel @Inject constructor(
|
|||
|
||||
val filter = getFilterFlow.invoke().firstOrNull() ?: BleFilter()
|
||||
|
||||
setState { BleFilterContract.State.Display(filter) }
|
||||
setState { BleFilterContract.State.Display(filter, filter) }
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,15 @@ class BleFilterViewModel @Inject constructor(
|
|||
state: BleFilterContract.State,
|
||||
event: BleFilterContract.Event.OnFilterChanged,
|
||||
) {
|
||||
setState { BleFilterContract.State.Display(event.filter) }
|
||||
if(state is BleFilterContract.State.Display) {
|
||||
|
||||
setState {
|
||||
state.copy(
|
||||
filter = event.filter
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ import androidx.compose.material3.IconButton
|
|||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
|
|
@ -335,8 +338,6 @@ private fun DisplayState(
|
|||
labelRotationDegrees = -90f,
|
||||
)
|
||||
|
||||
val scrollState = rememberChartScrollState()
|
||||
|
||||
when(lastMeasure){
|
||||
is Ble.Accelerometer.HistoryPoint.Acceleration,
|
||||
is Ble.Accelerometer.HistoryPoint.Angle -> {
|
||||
|
|
|
|||
|
|
@ -3,40 +3,42 @@ package llc.arma.ble.app.ui.screen.inspection.accelerometer.main
|
|||
import llc.arma.ble.app.ui.common.ViewEvent
|
||||
import llc.arma.ble.app.ui.common.ViewSideEffect
|
||||
import llc.arma.ble.app.ui.common.ViewState
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.RealtimeViewMode
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
import llc.arma.ble.domain.usecase.FftFrequency
|
||||
import llc.arma.ble.domain.usecase.FftViewMode
|
||||
|
||||
class AccelerometerContract {
|
||||
|
||||
sealed class Event : ViewEvent {
|
||||
|
||||
data object OnShowChart : Event()
|
||||
data object OnNavigateUp : Event()
|
||||
|
||||
data object OnRestart : Event()
|
||||
|
||||
data object OnShowAccelerometerHistory : Event()
|
||||
|
||||
data object OnShowRealtimeForm : Event()
|
||||
|
||||
data object OnPowerEdit : Event()
|
||||
|
||||
data object OnShowWriteBlePreview : Event()
|
||||
|
||||
data object OnWriteBle : Event()
|
||||
|
||||
data object OnChangePassword : Event()
|
||||
|
||||
data object OnSaveIntervalEdit : Event()
|
||||
|
||||
data class OnSaveIntervalChanged(
|
||||
val interval: Long
|
||||
) : Event()
|
||||
|
||||
data object OnReadIntervalEdit : Event()
|
||||
|
||||
data class OnReadIntervalChanged(
|
||||
val interval: Long
|
||||
) : Event()
|
||||
|
||||
data object OnPowerEdit : Event()
|
||||
|
||||
data class OnPowerChanged(
|
||||
val tx: BleView.BleState.TX
|
||||
val tx: Ble.BleState.TX
|
||||
) : Event()
|
||||
|
||||
data object OnShowHistoryForm : Event()
|
||||
|
|
@ -48,59 +50,30 @@ class AccelerometerContract {
|
|||
val scale: AccelScale
|
||||
) : Event()
|
||||
|
||||
data class OnSaveIntervalChanged(
|
||||
val interval: Long
|
||||
) : Event()
|
||||
|
||||
data class OnReadIntervalChanged(
|
||||
val interval: Long
|
||||
) : Event()
|
||||
|
||||
}
|
||||
|
||||
sealed class State : ViewState {
|
||||
|
||||
data object Loading : State()
|
||||
data class Loading(
|
||||
val attempt: Int?
|
||||
) : State()
|
||||
|
||||
data class Display(
|
||||
val origin: Ble.Accelerometer,
|
||||
val accelerometer: BleView.Accelerometer,
|
||||
val writeState: WriteState?,
|
||||
val accelViewMode: AccelViewMode,
|
||||
val accelRealtimeViewMode: RealtimeViewMode,
|
||||
val accelScale: AccelScale,
|
||||
val fftViewMode: FftViewMode,
|
||||
val fftAxis: FftAxis,
|
||||
val fftFrequency: FftFrequency,
|
||||
) : State() {
|
||||
|
||||
sealed class WriteState {
|
||||
|
||||
data class DisplayPreview(
|
||||
val writeRequest: Ble.Accelerometer.WriteRequest
|
||||
) : WriteState()
|
||||
|
||||
data class Writing(
|
||||
val writeRequest: Ble.Accelerometer.WriteRequest
|
||||
) : WriteState()
|
||||
|
||||
data object Success : WriteState()
|
||||
|
||||
data object Failure : WriteState()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
val accelerometer: Ble.Accelerometer
|
||||
) : State()
|
||||
|
||||
}
|
||||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
|
||||
object ShowWriteBle : Effect()
|
||||
|
||||
sealed class Navigation : Effect() {
|
||||
|
||||
data class Write(
|
||||
val serial: String,
|
||||
val request: Ble.Accelerometer.WriteRequest
|
||||
) : Effect()
|
||||
|
||||
data object ShowRealtimeForm : Effect()
|
||||
|
||||
data object ShowHistoryForm : Effect()
|
||||
|
|
@ -114,7 +87,7 @@ class AccelerometerContract {
|
|||
) : Navigation()
|
||||
|
||||
data class TxPowerSelector(
|
||||
val tx: BleView.BleState.TX
|
||||
val tx: Ble.BleState.TX
|
||||
) : Navigation()
|
||||
|
||||
data class ChangePassword(
|
||||
|
|
@ -122,14 +95,11 @@ class AccelerometerContract {
|
|||
) : Navigation()
|
||||
|
||||
data class AccelHistory(
|
||||
val ble: BleInfo,
|
||||
val accelScale: AccelScale,
|
||||
val accelMode: AccelViewMode,
|
||||
val fftAxis: FftAxis,
|
||||
val fftMode: FftViewMode,
|
||||
val frequency: FftFrequency
|
||||
val serial: String
|
||||
) : Navigation()
|
||||
|
||||
data object Up : Navigation()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,17 @@ package llc.arma.ble.app.ui.screen.inspection.accelerometer.main
|
|||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.ModalBottomSheetValue
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.Refresh
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
|
|
@ -26,30 +20,23 @@ import com.ramcosta.composedestinations.annotation.RootGraph
|
|||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerHistoryDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerHistoryFormDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerRealtimeFormDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerWriteScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.ChangePasswordScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.DurationSelectorScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.TxPowerSelectorScreenDestination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import com.ramcosta.composedestinations.result.ResultRecipient
|
||||
import com.ramcosta.composedestinations.result.onResult
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.rememberBottomDialogState
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.history.form.AccelerometerHistoryFormData
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.DisplayState
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.LoadingState
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.Write
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.DurationSelectResult
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
|
||||
enum class SheetPage {
|
||||
WRITE
|
||||
}
|
||||
|
||||
@Destination<RootGraph>
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -57,19 +44,14 @@ fun AccelerometerScreen(
|
|||
navigator: DestinationsNavigator,
|
||||
bleSerial: String,
|
||||
historyFormResult: ResultRecipient<AccelerometerHistoryFormDestination, AccelerometerHistoryFormData>,
|
||||
txSelectResult: ResultRecipient<TxPowerSelectorScreenDestination, BleView.BleState.TX>,
|
||||
txSelectResult: ResultRecipient<TxPowerSelectorScreenDestination, Ble.BleState.TX>,
|
||||
readDurationSelectResult: ResultRecipient<DurationSelectorScreenDestination, DurationSelectResult>,
|
||||
writeResult: ResultRecipient<AccelerometerWriteScreenDestination, Boolean>,
|
||||
) {
|
||||
|
||||
val viewModel = hiltViewModel<AccelerometerViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
val bottomDialog = rememberBottomDialogState()
|
||||
|
||||
var sheetPage by rememberSaveable {
|
||||
mutableStateOf<SheetPage?>(null)
|
||||
}
|
||||
|
||||
historyFormResult.onResult {
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnEnableSaveHistory(it.mode, it.scale))
|
||||
}
|
||||
|
|
@ -90,65 +72,16 @@ fun AccelerometerScreen(
|
|||
|
||||
}
|
||||
|
||||
LaunchedEffect(
|
||||
key1 = bottomDialog.sheetState?.currentValue,
|
||||
block = {
|
||||
if(bottomDialog.sheetState?.currentValue == ModalBottomSheetValue.Hidden) {
|
||||
bottomDialog.setContent {}
|
||||
sheetPage = null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
LaunchedEffect(sheetPage) {
|
||||
when (sheetPage) {
|
||||
SheetPage.WRITE -> bottomDialog.show {
|
||||
|
||||
val currentState = viewModel.viewState.value
|
||||
|
||||
if (currentState is AccelerometerContract.State.Display) {
|
||||
|
||||
currentState.writeState?.let {
|
||||
|
||||
Write(
|
||||
state = it,
|
||||
onEvent = viewModel::setEvent
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
null -> {
|
||||
bottomDialog.hide()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
writeResult.onResult {
|
||||
if(it) viewModel.setEvent(AccelerometerContract.Event.OnRestart)
|
||||
}
|
||||
|
||||
DisposableEffect(Unit){
|
||||
onDispose {
|
||||
scope.launch {
|
||||
bottomDialog.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect("effect"){
|
||||
LaunchedEffect(Unit){
|
||||
viewModel.effect.onEach {
|
||||
when(it){
|
||||
|
||||
is AccelerometerContract.Effect.ShowWriteBle -> launch {
|
||||
sheetPage = null
|
||||
delay(100)
|
||||
sheetPage = SheetPage.WRITE
|
||||
}
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.AccelHistory ->
|
||||
navigator.navigate(AccelerometerHistoryDestination(it.ble.serial))
|
||||
navigator.navigate(AccelerometerHistoryDestination(it.serial))
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.ChangePassword ->
|
||||
navigator.navigate(ChangePasswordScreenDestination(it.serial))
|
||||
|
|
@ -156,13 +89,14 @@ fun AccelerometerScreen(
|
|||
is AccelerometerContract.Effect.Navigation.ReadIntervalSelector ->
|
||||
navigator.navigate(DurationSelectorScreenDestination(
|
||||
qualifier = "ReadIntervalSelector",
|
||||
duration = it.interval
|
||||
duration = it.interval,
|
||||
minimum = 1000
|
||||
))
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.SaveIntervalSelector ->
|
||||
navigator.navigate(DurationSelectorScreenDestination(
|
||||
qualifier = "SaveIntervalSelector",
|
||||
duration = it.interval
|
||||
duration = it.interval,
|
||||
))
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.TxPowerSelector ->
|
||||
|
|
@ -173,6 +107,15 @@ fun AccelerometerScreen(
|
|||
|
||||
AccelerometerContract.Effect.Navigation.ShowRealtimeForm ->
|
||||
navigator.navigate(AccelerometerRealtimeFormDestination(bleSerial))
|
||||
|
||||
is AccelerometerContract.Effect.Navigation.Write ->
|
||||
navigator.navigate(AccelerometerWriteScreenDestination(
|
||||
bleSerial = it.serial,
|
||||
writeRequest = it.request
|
||||
))
|
||||
|
||||
AccelerometerContract.Effect.Navigation.Up ->
|
||||
navigator.navigateUp()
|
||||
}
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
|
@ -194,6 +137,20 @@ fun AccelerometerScreen(
|
|||
},
|
||||
title = {
|
||||
Text(text = BleInfo.Type.ACCELEROMETER.localized)
|
||||
},
|
||||
actions = {
|
||||
if(state is AccelerometerContract.State.Display){
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnRestart)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Refresh,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -205,13 +162,11 @@ fun AccelerometerScreen(
|
|||
|
||||
when(state){
|
||||
is AccelerometerContract.State.Display -> {
|
||||
DisplayState(
|
||||
origin = state.origin,
|
||||
ble = state.accelerometer,
|
||||
onEvent = viewModel::setEvent
|
||||
)
|
||||
DisplayState(viewModel, state)
|
||||
}
|
||||
is AccelerometerContract.State.Loading -> LoadingState()
|
||||
is AccelerometerContract.State.Loading -> LoadingState(
|
||||
viewModel, state
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,12 @@ import androidx.lifecycle.SavedStateHandle
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerScreenDestination
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.app.ui.mapper.BleMapper
|
||||
import llc.arma.ble.app.ui.mapper.BleViewMapper
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.RealtimeViewMode
|
||||
import llc.arma.ble.app.ui.common.retryUntilNotNull
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
import llc.arma.ble.domain.usecase.FftFrequency
|
||||
import llc.arma.ble.domain.usecase.FftViewMode
|
||||
import llc.arma.ble.domain.usecase.GetBleBySerial
|
||||
import llc.arma.ble.domain.usecase.WriteBle
|
||||
import javax.inject.Inject
|
||||
|
|
@ -23,66 +17,21 @@ import javax.inject.Inject
|
|||
@HiltViewModel
|
||||
class AccelerometerViewModel @Inject constructor(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
getBleBySerial: GetBleBySerial,
|
||||
private val bleMapper: BleMapper,
|
||||
private val bleViewMapper: BleViewMapper,
|
||||
private val writeBle: WriteBle
|
||||
private val getBleBySerial: GetBleBySerial,
|
||||
) : BaseViewModel<AccelerometerContract.State, AccelerometerContract.Event, AccelerometerContract.Effect>() {
|
||||
|
||||
init {
|
||||
|
||||
val params = AccelerometerScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
viewModelScope.launch {
|
||||
|
||||
val ble = getBleBySerial.invoke(params.bleSerial, this).fold(
|
||||
onSuccess = { it },
|
||||
onFailure = { null }
|
||||
)
|
||||
|
||||
if(ble != null && ble is Ble.Accelerometer){
|
||||
setState {
|
||||
|
||||
when(this){
|
||||
is AccelerometerContract.State.Display -> {
|
||||
copy(
|
||||
origin = Ble.Accelerometer(
|
||||
info = ble.info,
|
||||
state = origin.state,
|
||||
accelerometerState = origin.accelerometerState
|
||||
)
|
||||
)
|
||||
}
|
||||
AccelerometerContract.State.Loading -> {
|
||||
AccelerometerContract.State.Display(
|
||||
origin = ble,
|
||||
accelerometer = bleMapper.map(ble) as BleView.Accelerometer,
|
||||
writeState = null,
|
||||
accelViewMode = AccelViewMode.ACCELERATION,
|
||||
accelRealtimeViewMode = RealtimeViewMode.Accel(
|
||||
AccelViewMode.ACCELERATION
|
||||
),
|
||||
fftAxis = FftAxis.AUTO,
|
||||
fftFrequency = FftFrequency.F_400,
|
||||
fftViewMode = FftViewMode.SPECTRE,
|
||||
accelScale = AccelScale.S_2
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
loadData()
|
||||
|
||||
}
|
||||
|
||||
override fun setInitialState() = AccelerometerContract.State.Loading
|
||||
override fun setInitialState() = AccelerometerContract.State.Loading(null)
|
||||
|
||||
override fun handleEvents(event: AccelerometerContract.Event) {
|
||||
when(event){
|
||||
is AccelerometerContract.Event.OnPowerChanged -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnPowerEdit -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnShowWriteBlePreview -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnWriteBle -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnDisableSaveHistory -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnShowAccelerometerHistory -> reduce(viewState.value, event)
|
||||
|
|
@ -93,22 +42,32 @@ class AccelerometerViewModel @Inject constructor(
|
|||
is AccelerometerContract.Event.OnReadIntervalEdit -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnEnableSaveHistory -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnShowHistoryForm -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnShowChart -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnShowRealtimeForm -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnRestart -> reduce(viewState.value, event)
|
||||
is AccelerometerContract.Event.OnNavigateUp -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: AccelerometerContract.State,
|
||||
event: AccelerometerContract.Event.OnShowChart
|
||||
event: AccelerometerContract.Event.OnNavigateUp
|
||||
) {
|
||||
|
||||
setEffect {
|
||||
AccelerometerContract.Effect.Navigation.ShowHistoryForm
|
||||
AccelerometerContract.Effect.Navigation.Up
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: AccelerometerContract.State,
|
||||
event: AccelerometerContract.Event.OnRestart
|
||||
) {
|
||||
|
||||
loadData()
|
||||
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: AccelerometerContract.State,
|
||||
event: AccelerometerContract.Event.OnShowRealtimeForm
|
||||
|
|
@ -138,7 +97,15 @@ class AccelerometerViewModel @Inject constructor(
|
|||
|
||||
if(state is AccelerometerContract.State.Display) {
|
||||
|
||||
state.accelerometer.accelerometerState.readInterval = event.interval
|
||||
setState {
|
||||
state.copy(
|
||||
accelerometer = state.accelerometer.copy(
|
||||
accelerometerState = state.accelerometer.accelerometerState.copy(
|
||||
readInterval = event.interval
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +151,15 @@ class AccelerometerViewModel @Inject constructor(
|
|||
|
||||
if(state is AccelerometerContract.State.Display) {
|
||||
|
||||
state.accelerometer.accelerometerState.historyInterval = event.interval
|
||||
setState {
|
||||
state.copy(
|
||||
accelerometer = state.accelerometer.copy(
|
||||
accelerometerState = state.accelerometer.accelerometerState.copy(
|
||||
historyInterval = event.interval
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +187,15 @@ class AccelerometerViewModel @Inject constructor(
|
|||
|
||||
if(state is AccelerometerContract.State.Display) {
|
||||
|
||||
state.accelerometer.accelerometerState.saveHistory = Ble.Accelerometer.HistorySettings.Disabled
|
||||
setState {
|
||||
state.copy(
|
||||
accelerometer = state.accelerometer.copy(
|
||||
accelerometerState = state.accelerometer.accelerometerState.copy(
|
||||
saveHistorySettings = Ble.Accelerometer.HistorySettings.Disabled
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -225,11 +208,19 @@ class AccelerometerViewModel @Inject constructor(
|
|||
|
||||
if(state is AccelerometerContract.State.Display) {
|
||||
|
||||
state.accelerometer.accelerometerState.saveHistory = Ble.Accelerometer.HistorySettings.Enabled(
|
||||
scale = event.scale,
|
||||
mode = event.mode,
|
||||
detailed = true
|
||||
)
|
||||
setState {
|
||||
state.copy(
|
||||
accelerometer = state.accelerometer.copy(
|
||||
accelerometerState = state.accelerometer.accelerometerState.copy(
|
||||
saveHistorySettings = Ble.Accelerometer.HistorySettings.Enabled(
|
||||
scale = event.scale,
|
||||
mode = event.mode,
|
||||
detailed = true
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -246,12 +237,7 @@ class AccelerometerViewModel @Inject constructor(
|
|||
setEffect {
|
||||
|
||||
AccelerometerContract.Effect.Navigation.AccelHistory(
|
||||
ble = state.accelerometer.info,
|
||||
accelMode = state.origin.accelerometerState.saveHistorySettings.mode,
|
||||
fftAxis = state.fftAxis,
|
||||
fftMode = state.fftViewMode,
|
||||
frequency = state.fftFrequency,
|
||||
accelScale = state.accelScale
|
||||
serial = state.accelerometer.info.serial
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -261,12 +247,12 @@ class AccelerometerViewModel @Inject constructor(
|
|||
|
||||
private fun reduce(
|
||||
state: AccelerometerContract.State,
|
||||
event: AccelerometerContract.Event.OnShowWriteBlePreview
|
||||
event: AccelerometerContract.Event.OnWriteBle
|
||||
) {
|
||||
|
||||
if(state is AccelerometerContract.State.Display){
|
||||
|
||||
val newBle = bleViewMapper.map(state.accelerometer) as Ble.Accelerometer
|
||||
val newBle = state.accelerometer
|
||||
|
||||
val writeRequest = Ble.Accelerometer.WriteRequest(
|
||||
tx = if(newBle.state.tx == state.origin.state.tx) null else newBle.state.tx,
|
||||
|
|
@ -275,16 +261,8 @@ class AccelerometerViewModel @Inject constructor(
|
|||
readInterval = if(newBle.accelerometerState.readInterval == state.origin.accelerometerState.readInterval) null else newBle.accelerometerState.readInterval,
|
||||
)
|
||||
|
||||
setState {
|
||||
state.copy(
|
||||
writeState = AccelerometerContract.State.Display.WriteState.DisplayPreview(
|
||||
writeRequest
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
setEffect {
|
||||
AccelerometerContract.Effect.ShowWriteBle
|
||||
AccelerometerContract.Effect.Navigation.Write(state.accelerometer.info.serial, writeRequest)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -298,7 +276,15 @@ class AccelerometerViewModel @Inject constructor(
|
|||
|
||||
if(state is AccelerometerContract.State.Display) {
|
||||
|
||||
state.accelerometer.state.tx = event.tx
|
||||
setState {
|
||||
state.copy(
|
||||
accelerometer = state.accelerometer.copy(
|
||||
state = state.accelerometer.state.copy(
|
||||
tx = event.tx
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -318,68 +304,50 @@ class AccelerometerViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: AccelerometerContract.State,
|
||||
event: AccelerometerContract.Event.OnWriteBle
|
||||
) {
|
||||
private var loadJob: Job? = null
|
||||
|
||||
if(state is AccelerometerContract.State.Display){
|
||||
private fun loadData(){
|
||||
|
||||
state.writeState?.let { request ->
|
||||
val params = AccelerometerScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
if(request is AccelerometerContract.State.Display.WriteState.DisplayPreview) {
|
||||
loadJob?.cancel()
|
||||
loadJob = viewModelScope.launch {
|
||||
|
||||
viewModelScope.launch {
|
||||
setState {
|
||||
AccelerometerContract.State.Loading(null)
|
||||
}
|
||||
|
||||
setState {
|
||||
state.copy(
|
||||
writeState = AccelerometerContract.State.Display.WriteState.Writing(
|
||||
request.writeRequest
|
||||
val ble = retryUntilNotNull(
|
||||
onNewAttempt = {
|
||||
setState {
|
||||
AccelerometerContract.State.Loading(it)
|
||||
}
|
||||
}
|
||||
){
|
||||
getBleBySerial.invoke(params.bleSerial, this).getOrNull()
|
||||
}
|
||||
|
||||
if( ble is Ble.Accelerometer){
|
||||
setState {
|
||||
|
||||
when(this){
|
||||
is AccelerometerContract.State.Display -> {
|
||||
copy(
|
||||
origin = Ble.Accelerometer(
|
||||
info = ble.info,
|
||||
state = origin.state,
|
||||
accelerometerState = origin.accelerometerState
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
writeBle(state.accelerometer.info.serial, request.writeRequest).fold(
|
||||
onSuccess = {
|
||||
|
||||
val currentState = viewState.value
|
||||
|
||||
if(currentState is AccelerometerContract.State.Display) {
|
||||
|
||||
val newBleObject = Ble.Accelerometer(
|
||||
info = currentState.origin.info,
|
||||
state = currentState.origin.state.copy(
|
||||
tx = request.writeRequest.tx ?: state.origin.state.tx
|
||||
),
|
||||
accelerometerState = currentState.origin.accelerometerState.copy(
|
||||
saveHistorySettings = request.writeRequest.saveHistorySettings
|
||||
?: currentState.origin.accelerometerState.saveHistorySettings
|
||||
)
|
||||
)
|
||||
|
||||
setState {
|
||||
currentState.copy(
|
||||
origin = newBleObject,
|
||||
writeState = AccelerometerContract.State.Display.WriteState.Success
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
onFailure = {
|
||||
setState {
|
||||
state.copy(
|
||||
writeState = AccelerometerContract.State.Display.WriteState.Failure
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
is AccelerometerContract.State.Loading -> {
|
||||
AccelerometerContract.State.Display(
|
||||
origin = ble,
|
||||
accelerometer = ble
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import llc.arma.ble.app.ui.common.PrimaryButton
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
|
||||
@Composable
|
||||
fun SelectorItem(
|
||||
label: String,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit
|
||||
){
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.clickable(onClick = onClick)
|
||||
.padding(4.dp)
|
||||
) {
|
||||
|
||||
RadioButton(
|
||||
selected = selected,
|
||||
onClick = onClick
|
||||
)
|
||||
|
||||
Text(text = label)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,6 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.serialization.Serializable
|
||||
import llc.arma.ble.app.ui.common.PrimaryButton
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
|
||||
@Serializable
|
||||
|
|
|
|||
|
|
@ -1,28 +1,31 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowDown
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import llc.arma.ble.app.ui.common.PrimaryButton
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.BleInfoView
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerViewModel
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.main.BleMenuItem
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.app.ui.screen.locale.value
|
||||
import llc.arma.ble.data.repository.BleRepositoryImpl
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import kotlin.time.DurationUnit
|
||||
|
|
@ -30,9 +33,8 @@ import kotlin.time.toDuration
|
|||
|
||||
@Composable
|
||||
fun DisplayState(
|
||||
onEvent: (AccelerometerContract.Event) -> Unit,
|
||||
origin: Ble.Accelerometer,
|
||||
ble: BleView.Accelerometer
|
||||
viewModel: AccelerometerViewModel,
|
||||
state: AccelerometerContract.State.Display
|
||||
) {
|
||||
|
||||
val scrollState = rememberScrollState()
|
||||
|
|
@ -48,8 +50,8 @@ fun DisplayState(
|
|||
) {
|
||||
|
||||
BleInfoView(
|
||||
bleInfo = origin.info,
|
||||
version = origin.state.version
|
||||
bleInfo = state.origin.info,
|
||||
version = state.origin.state.version
|
||||
)
|
||||
|
||||
Column(
|
||||
|
|
@ -59,7 +61,7 @@ fun DisplayState(
|
|||
BleMenuItem(
|
||||
shapeType = ShapeType.Start,
|
||||
title = "Мощность",
|
||||
subtitle = "${ble.state.tx.value} db",
|
||||
subtitle = "${state.accelerometer.state.tx.value} db",
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.KeyboardArrowDown,
|
||||
|
|
@ -67,10 +69,10 @@ fun DisplayState(
|
|||
)
|
||||
}
|
||||
) {
|
||||
onEvent(AccelerometerContract.Event.OnPowerEdit)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnPowerEdit)
|
||||
}
|
||||
|
||||
val history = ble.accelerometerState.saveHistory
|
||||
val history = state.accelerometer.accelerometerState.saveHistorySettings
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Middle,
|
||||
|
|
@ -82,12 +84,12 @@ fun DisplayState(
|
|||
},
|
||||
icon = {
|
||||
Switch(
|
||||
checked = ble.accelerometerState.saveHistory is Ble.Accelerometer.HistorySettings.Enabled,
|
||||
checked = state.accelerometer.accelerometerState.saveHistorySettings is Ble.Accelerometer.HistorySettings.Enabled,
|
||||
onCheckedChange = {
|
||||
if(it){
|
||||
onEvent(AccelerometerContract.Event.OnShowHistoryForm)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnShowHistoryForm)
|
||||
} else {
|
||||
onEvent(AccelerometerContract.Event.OnDisableSaveHistory)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnDisableSaveHistory)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -95,12 +97,12 @@ fun DisplayState(
|
|||
}
|
||||
)
|
||||
|
||||
if (ble.accelerometerState.saveHistory is Ble.Accelerometer.HistorySettings.Enabled) {
|
||||
if (state.accelerometer.accelerometerState.saveHistorySettings is Ble.Accelerometer.HistorySettings.Enabled) {
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Middle,
|
||||
title = "Интервал измерений",
|
||||
subtitle = ble.accelerometerState.historyInterval
|
||||
subtitle = state.accelerometer.accelerometerState.historyInterval
|
||||
.toDuration(DurationUnit.MILLISECONDS).toComponents { hours, minutes, seconds, _ ->
|
||||
"$hours ч. $minutes мин. $seconds сек." },
|
||||
icon = {
|
||||
|
|
@ -111,20 +113,20 @@ fun DisplayState(
|
|||
}
|
||||
) {
|
||||
|
||||
onEvent(AccelerometerContract.Event.OnSaveIntervalEdit)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnSaveIntervalEdit)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ble.state.version > BleRepositoryImpl.Version.fromString("0.0.0-0")) {
|
||||
if (state.accelerometer.state.version > BleRepositoryImpl.Version.fromString("0.0.0-0")) {
|
||||
|
||||
if (ble.accelerometerState.saveHistory is Ble.Accelerometer.HistorySettings.Enabled) {
|
||||
if (state.accelerometer.accelerometerState.saveHistorySettings is Ble.Accelerometer.HistorySettings.Enabled) {
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Middle,
|
||||
title = "Интервал чтения",
|
||||
subtitle = ble.accelerometerState.readInterval
|
||||
subtitle = state.accelerometer.accelerometerState.readInterval
|
||||
.toDuration(DurationUnit.MILLISECONDS).toComponents { hours, minutes, seconds, _ ->
|
||||
"$hours ч. $minutes мин. $seconds сек." },
|
||||
icon = {
|
||||
|
|
@ -135,7 +137,7 @@ fun DisplayState(
|
|||
}
|
||||
) {
|
||||
|
||||
onEvent(AccelerometerContract.Event.OnReadIntervalEdit)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnReadIntervalEdit)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -154,12 +156,12 @@ fun DisplayState(
|
|||
}
|
||||
) {
|
||||
|
||||
when (origin.accelerometerState.saveHistorySettings) {
|
||||
when (state.origin.accelerometerState.saveHistorySettings) {
|
||||
is Ble.Accelerometer.HistorySettings.Disabled ->
|
||||
onEvent(AccelerometerContract.Event.OnShowRealtimeForm)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnShowRealtimeForm)
|
||||
|
||||
is Ble.Accelerometer.HistorySettings.Enabled ->
|
||||
onEvent(AccelerometerContract.Event.OnShowAccelerometerHistory)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnShowAccelerometerHistory)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -174,25 +176,36 @@ fun DisplayState(
|
|||
)
|
||||
}
|
||||
) {
|
||||
onEvent(AccelerometerContract.Event.OnChangePassword)
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnChangePassword)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PrimaryButton(
|
||||
modifier = Modifier.shadow(
|
||||
if(scrollState.canScrollForward){
|
||||
8.dp
|
||||
} else {
|
||||
0.dp
|
||||
}
|
||||
).background(MaterialTheme.colorScheme.background),
|
||||
label = "Сохранить"
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth().animateContentSize()
|
||||
) {
|
||||
|
||||
onEvent(AccelerometerContract.Event.OnShowWriteBlePreview)
|
||||
if(state.origin != state.accelerometer) {
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnWriteBle)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Сохранить"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,23 +2,30 @@ package llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view
|
|||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ContainedLoadingIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import llc.arma.ble.app.ui.common.RetryingLoadingTemplate
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerViewModel
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun LoadingState(){
|
||||
fun LoadingState(
|
||||
viewModel: AccelerometerViewModel,
|
||||
state: AccelerometerContract.State.Loading
|
||||
){
|
||||
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
|
||||
ContainedLoadingIndicator()
|
||||
RetryingLoadingTemplate(state.attempt) {
|
||||
viewModel.setEvent(AccelerometerContract.Event.OnNavigateUp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,262 +0,0 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import llc.arma.ble.R
|
||||
import llc.arma.ble.app.ui.common.PrimaryButton
|
||||
import llc.arma.ble.app.ui.common.SecondaryButton
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInHour
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInMinute
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInSecond
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.main.BleMenuItem
|
||||
import llc.arma.ble.app.ui.screen.locale.localizedName
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
|
||||
@Composable
|
||||
fun Write(
|
||||
state: AccelerometerContract.State.Display.WriteState,
|
||||
onEvent: (AccelerometerContract.Event) -> Unit
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.animateContentSize()
|
||||
) {
|
||||
|
||||
Text(
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
text = "Запись изменений",
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
when (state) {
|
||||
is AccelerometerContract.State.Display.WriteState.DisplayPreview -> {
|
||||
|
||||
if(
|
||||
state.writeRequest.tx != null ||
|
||||
state.writeRequest.saveHistorySettings != null ||
|
||||
state.writeRequest.historyInterval != null ||
|
||||
state.writeRequest.readInterval != null
|
||||
) {
|
||||
|
||||
state.writeRequest.tx?.let {
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Singleton,
|
||||
title = "Мощность",
|
||||
subtitle = "${it.localizedName} db",
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
state.writeRequest.saveHistorySettings?.let {
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Singleton,
|
||||
title = "Сохранять историю измерений",
|
||||
subtitle = when(it){
|
||||
Ble.Accelerometer.HistorySettings.Disabled -> "Выключено"
|
||||
is Ble.Accelerometer.HistorySettings.Enabled -> "Включено"
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
state.writeRequest.historyInterval?.let {
|
||||
|
||||
val hours = it / millisInHour
|
||||
val minutes = (it - (hours * millisInHour)) / millisInMinute
|
||||
val seconds = (it - (hours * millisInHour) - (minutes * millisInMinute)) / millisInSecond
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Singleton,
|
||||
title = "Интервал измерений",
|
||||
subtitle = "$hours ч. $minutes мин. $seconds сек."
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
state.writeRequest.readInterval?.let {
|
||||
|
||||
val hours = it / millisInHour
|
||||
val minutes = (it - (hours * millisInHour)) / millisInMinute
|
||||
val seconds = (it - (hours * millisInHour) - (minutes * millisInMinute)) / millisInSecond
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Singleton,
|
||||
title = "Интервал чтения",
|
||||
subtitle = "$hours ч. $minutes мин. $seconds сек."
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Записать"
|
||||
) {
|
||||
onEvent(AccelerometerContract.Event.OnWriteBle)
|
||||
}
|
||||
|
||||
SecondaryButton(
|
||||
label = "Отменить"
|
||||
) {
|
||||
//onEvent(AccelerometerContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Spacer(modifier = Modifier.height(38.dp))
|
||||
|
||||
Text(
|
||||
text = "Нет изменений",
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(64.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Ок"
|
||||
) {
|
||||
//onEvent(AccelerometerContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
is AccelerometerContract.State.Display.WriteState.Writing -> {
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
Spacer(modifier = Modifier.height(28.dp))
|
||||
|
||||
CircularProgressIndicator(
|
||||
strokeCap = StrokeCap.Round,
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(48.dp))
|
||||
|
||||
SecondaryButton(
|
||||
label = "Отменить"
|
||||
) {
|
||||
//onEvent(AccelerometerContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
AccelerometerContract.State.Display.WriteState.Success -> {
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Image(
|
||||
modifier = Modifier
|
||||
.size(125.dp)
|
||||
.align(Alignment.Center),
|
||||
painter = painterResource(R.drawable.ic_done),
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Успешно завершено"
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Ок"
|
||||
) {
|
||||
//onEvent(AccelerometerContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
AccelerometerContract.State.Display.WriteState.Failure -> {
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Image(
|
||||
modifier = Modifier
|
||||
.size(125.dp)
|
||||
.align(Alignment.Center),
|
||||
painter = painterResource(R.drawable.ic_error),
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Ошибка записи"
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Ок"
|
||||
) {
|
||||
//onEvent(AccelerometerContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,33 +4,54 @@ import llc.arma.ble.app.ui.common.ViewEvent
|
|||
import llc.arma.ble.app.ui.common.ViewSideEffect
|
||||
import llc.arma.ble.app.ui.common.ViewState
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
import llc.arma.ble.domain.usecase.FftFrequency
|
||||
import llc.arma.ble.domain.usecase.FftViewMode
|
||||
|
||||
class AccelerometerAccelContract {
|
||||
|
||||
sealed class Event : ViewEvent {
|
||||
|
||||
data object OnNavigateUp : Event()
|
||||
|
||||
data object OnRefresh : Event()
|
||||
|
||||
}
|
||||
|
||||
sealed class State : ViewState {
|
||||
|
||||
data class Display(
|
||||
val mode: AccelViewMode,
|
||||
val measureHistory : List<Ble.Accelerometer.RealtimePoint>
|
||||
data class Loading(
|
||||
val attempt: Int?
|
||||
) : State()
|
||||
|
||||
data object Exception : State()
|
||||
data class DisplayCommon(
|
||||
val mode: AccelViewMode,
|
||||
val measureHistory : List<Ble.Accelerometer.RealtimePoint.Common>
|
||||
) : State()
|
||||
|
||||
data class DisplayAngle(
|
||||
val mode: AccelViewMode,
|
||||
val measureHistory : List<Ble.Accelerometer.RealtimePoint.Angle>
|
||||
) : State()
|
||||
|
||||
data class DisplayRotation(
|
||||
val mode: AccelViewMode,
|
||||
val measureHistory : List<Ble.Accelerometer.RealtimePoint.Rotation>
|
||||
) : State()
|
||||
|
||||
data class DisplayVibration(
|
||||
val mode: AccelViewMode,
|
||||
val measureHistory : List<Ble.Accelerometer.RealtimePoint.Vibration>
|
||||
) : State()
|
||||
|
||||
}
|
||||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
sealed class Navigation : Effect() {
|
||||
|
||||
data object Up : Navigation()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,11 +9,11 @@ import kotlinx.coroutines.flow.launchIn
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.app.ui.common.retryUntilNotNull
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
import llc.arma.ble.domain.usecase.FftFrequency
|
||||
import llc.arma.ble.domain.usecase.FftViewMode
|
||||
import llc.arma.ble.domain.usecase.GetAccelerometerMeasureBySerialFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -26,17 +26,15 @@ class AccelerometerAccelViewModel @Inject constructor(
|
|||
private var measureJob: Job? = null
|
||||
|
||||
init {
|
||||
startReadMeasure(false)
|
||||
startReadMeasure()
|
||||
}
|
||||
|
||||
override fun setInitialState() = AccelerometerAccelContract.State.Display(
|
||||
mode = AccelViewMode.ACCELERATION,
|
||||
measureHistory = emptyList()
|
||||
)
|
||||
override fun setInitialState() = AccelerometerAccelContract.State.Loading(null)
|
||||
|
||||
override fun handleEvents(event: AccelerometerAccelContract.Event) {
|
||||
when(event){
|
||||
is AccelerometerAccelContract.Event.OnRefresh -> reduce(viewState.value, event)
|
||||
is AccelerometerAccelContract.Event.OnNavigateUp -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,26 +42,36 @@ class AccelerometerAccelViewModel @Inject constructor(
|
|||
state: AccelerometerAccelContract.State,
|
||||
event: AccelerometerAccelContract.Event.OnRefresh
|
||||
) {
|
||||
startReadMeasure(true)
|
||||
startReadMeasure()
|
||||
}
|
||||
|
||||
private fun startReadMeasure(
|
||||
restartJob: Boolean
|
||||
){
|
||||
private fun reduce(
|
||||
state: AccelerometerAccelContract.State,
|
||||
event: AccelerometerAccelContract.Event.OnNavigateUp
|
||||
) {
|
||||
|
||||
setEffect { AccelerometerAccelContract.Effect.Navigation.Up }
|
||||
|
||||
}
|
||||
|
||||
private fun startReadMeasure() {
|
||||
|
||||
val params = AccelerometerRealtimeDestination.argsFrom(savedStateHandle)
|
||||
|
||||
if(restartJob || measureJob == null) {
|
||||
measureJob?.cancel()
|
||||
measureJob = null
|
||||
measureJob = viewModelScope.launch {
|
||||
setState {
|
||||
AccelerometerAccelContract.State.Loading(null)
|
||||
}
|
||||
|
||||
setState {
|
||||
AccelerometerAccelContract.State.Display(
|
||||
mode = AccelViewMode.ACCELERATION,
|
||||
measureHistory = emptyList()
|
||||
)
|
||||
measureJob?.cancel()
|
||||
measureJob = viewModelScope.launch {
|
||||
|
||||
val flow = retryUntilNotNull(
|
||||
onNewAttempt = {
|
||||
setState {
|
||||
AccelerometerAccelContract.State.Loading(it)
|
||||
}
|
||||
}
|
||||
) {
|
||||
|
||||
getAccelerometerMeasureBySerialFlow(
|
||||
params.bleSerial,
|
||||
|
|
@ -71,44 +79,73 @@ class AccelerometerAccelViewModel @Inject constructor(
|
|||
params.accelMode,
|
||||
params.fftAxis,
|
||||
params.fftMode,
|
||||
params.frequency
|
||||
).onEach {
|
||||
it.fold(
|
||||
onSuccess = {
|
||||
setState {
|
||||
when (this) {
|
||||
is AccelerometerAccelContract.State.Display -> {
|
||||
var dataList = this.measureHistory.toMutableList().apply {
|
||||
add(it)
|
||||
}
|
||||
if(params.accelMode != AccelViewMode.ANGLE) {
|
||||
dataList = dataList.takeLast(100).toMutableList()
|
||||
}
|
||||
AccelerometerAccelContract.State.Display(
|
||||
params.accelMode,
|
||||
dataList
|
||||
)
|
||||
}
|
||||
|
||||
AccelerometerAccelContract.State.Exception -> {
|
||||
AccelerometerAccelContract.State.Display(
|
||||
params.accelMode,
|
||||
listOf(it)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onFailure = {
|
||||
setState {
|
||||
AccelerometerAccelContract.State.Exception
|
||||
}
|
||||
}
|
||||
)
|
||||
}.launchIn(this)
|
||||
FftFrequency.F_400
|
||||
).getOrNull()
|
||||
|
||||
}
|
||||
|
||||
flow.onEach {
|
||||
|
||||
val state = viewState.value
|
||||
|
||||
val newState = when (it) {
|
||||
is Ble.Accelerometer.RealtimePoint.Angle -> {
|
||||
if (state is AccelerometerAccelContract.State.DisplayAngle) {
|
||||
state.copy(
|
||||
measureHistory = (state.measureHistory + it).takeLast(100)
|
||||
)
|
||||
} else {
|
||||
AccelerometerAccelContract.State.DisplayAngle(
|
||||
params.accelMode,
|
||||
listOf(it)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is Ble.Accelerometer.RealtimePoint.Common -> {
|
||||
if (state is AccelerometerAccelContract.State.DisplayCommon) {
|
||||
state.copy(
|
||||
measureHistory = (state.measureHistory + it).takeLast(100)
|
||||
)
|
||||
} else {
|
||||
AccelerometerAccelContract.State.DisplayCommon(
|
||||
params.accelMode,
|
||||
listOf(it)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is Ble.Accelerometer.RealtimePoint.Rotation -> {
|
||||
if (state is AccelerometerAccelContract.State.DisplayRotation) {
|
||||
state.copy(
|
||||
measureHistory = (state.measureHistory + it).takeLast(100)
|
||||
)
|
||||
} else {
|
||||
AccelerometerAccelContract.State.DisplayRotation(
|
||||
params.accelMode,
|
||||
listOf(it)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is Ble.Accelerometer.RealtimePoint.Vibration -> {
|
||||
if (state is AccelerometerAccelContract.State.DisplayVibration) {
|
||||
state.copy(
|
||||
measureHistory = (state.measureHistory + it).takeLast(100)
|
||||
)
|
||||
} else {
|
||||
AccelerometerAccelContract.State.DisplayVibration(
|
||||
params.accelMode,
|
||||
listOf(it)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
setState { newState }
|
||||
}.launchIn(this)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.rt
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
|
|
@ -13,6 +14,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.Refresh
|
||||
|
|
@ -26,7 +28,9 @@ import androidx.compose.material3.Scaffold
|
|||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
|
|
@ -44,6 +48,8 @@ import com.patrykandpatrick.vico.compose.component.textComponent
|
|||
import com.patrykandpatrick.vico.core.chart.decoration.ThresholdLine
|
||||
import com.patrykandpatrick.vico.core.chart.scale.AutoScaleUp
|
||||
import com.patrykandpatrick.vico.core.component.marker.MarkerComponent
|
||||
import com.patrykandpatrick.vico.core.component.shape.ShapeComponent
|
||||
import com.patrykandpatrick.vico.core.component.text.TextComponent
|
||||
import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer
|
||||
import com.patrykandpatrick.vico.core.entry.FloatEntry
|
||||
import com.patrykandpatrick.vico.core.scroll.AutoScrollCondition
|
||||
|
|
@ -51,9 +57,10 @@ import com.patrykandpatrick.vico.core.scroll.InitialScroll
|
|||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootGraph
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import llc.arma.ble.app.ui.common.RetryingLoadingTemplate
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
|
|
@ -76,6 +83,15 @@ fun AccelerometerRealtime(
|
|||
val viewModel = hiltViewModel<AccelerometerAccelViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.effect.collect {
|
||||
when (it) {
|
||||
AccelerometerAccelContract.Effect.Navigation.Up ->
|
||||
navigator.navigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
|
|
@ -96,38 +112,226 @@ fun AccelerometerRealtime(
|
|||
)
|
||||
},
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(AccelerometerAccelContract.Event.OnRefresh)
|
||||
},
|
||||
enabled = true
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Refresh,
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
if((state is AccelerometerAccelContract.State.Loading).not()) {
|
||||
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(AccelerometerAccelContract.Event.OnRefresh)
|
||||
},
|
||||
enabled = true
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Refresh,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
Box(modifier = Modifier.padding(it)) {
|
||||
Box(
|
||||
modifier = Modifier.padding(it)
|
||||
) {
|
||||
|
||||
when (state) {
|
||||
is AccelerometerAccelContract.State.Display -> DisplayState(state = state)
|
||||
is AccelerometerAccelContract.State.Exception -> ExceptionState()
|
||||
is AccelerometerAccelContract.State.DisplayAngle -> DisplayAngleState(state)
|
||||
is AccelerometerAccelContract.State.DisplayCommon -> DisplayCommonState(state)
|
||||
is AccelerometerAccelContract.State.DisplayRotation -> DisplayRotationState(state)
|
||||
is AccelerometerAccelContract.State.DisplayVibration -> DisplayVibrationState(state)
|
||||
is AccelerometerAccelContract.State.Loading -> LoadingState(viewModel, state)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun DisplayState(
|
||||
state: AccelerometerAccelContract.State.Display
|
||||
private fun DisplayCommonState(
|
||||
state: AccelerometerAccelContract.State.DisplayCommon
|
||||
) {
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.padding(bottom = 16.dp)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
|
||||
val xProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
val yProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
val zProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
xProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.x)
|
||||
})
|
||||
|
||||
yProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.y)
|
||||
})
|
||||
|
||||
zProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.z)
|
||||
})
|
||||
|
||||
val lineChart = lineChart(
|
||||
decorations = listOf(
|
||||
ThresholdLine(
|
||||
lineComponent = ShapeComponent(color = Color.TRANSPARENT),
|
||||
thresholdValue = 0f
|
||||
)
|
||||
),
|
||||
persistentMarkers = mapOf(
|
||||
xProducer.getModel().maxX to MarkerComponent(
|
||||
label = textComponent(),
|
||||
indicator = null,
|
||||
guideline = axisGuidelineComponent()
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
val marker = MarkerComponent(
|
||||
label = textComponent(),
|
||||
indicator = null,
|
||||
guideline = axisGuidelineComponent()
|
||||
)
|
||||
|
||||
Surface(
|
||||
shape = ShapeType.Start.shape,
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
.padding(top = 8.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Ось X",
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = xProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Surface(
|
||||
shape = ShapeType.Middle.shape,
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Ось Y",
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = yProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Surface(
|
||||
shape = ShapeType.End.shape,
|
||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
.padding(bottom = 8.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Ось Z",
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = zProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayAngleState(
|
||||
state: AccelerometerAccelContract.State.DisplayAngle
|
||||
) {
|
||||
|
||||
Box(modifier = Modifier
|
||||
|
|
@ -159,42 +363,123 @@ private fun DisplayState(
|
|||
}
|
||||
|
||||
xProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
when(measurePoint){
|
||||
is Ble.Accelerometer.RealtimePoint.Common ->
|
||||
FloatEntry(index.toFloat(), measurePoint.x )
|
||||
is Ble.Accelerometer.RealtimePoint.Vibration ->
|
||||
FloatEntry(index.toFloat(), measurePoint.value)
|
||||
is Ble.Accelerometer.RealtimePoint.Angle ->
|
||||
FloatEntry(index.toFloat(), measurePoint.x )
|
||||
is Ble.Accelerometer.RealtimePoint.Rotation ->
|
||||
FloatEntry(index.toFloat(), measurePoint.angle )
|
||||
}
|
||||
FloatEntry(index.toFloat(), measurePoint.x )
|
||||
})
|
||||
|
||||
yProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
when(measurePoint){
|
||||
is Ble.Accelerometer.RealtimePoint.Common ->
|
||||
FloatEntry(index.toFloat(), measurePoint.y )
|
||||
is Ble.Accelerometer.RealtimePoint.Vibration ->
|
||||
FloatEntry(index.toFloat(), measurePoint.value)
|
||||
is Ble.Accelerometer.RealtimePoint.Angle ->
|
||||
FloatEntry(index.toFloat(), measurePoint.y)
|
||||
is Ble.Accelerometer.RealtimePoint.Rotation ->
|
||||
FloatEntry(index.toFloat(), measurePoint.tmp)
|
||||
}
|
||||
FloatEntry(index.toFloat(), measurePoint.y)
|
||||
})
|
||||
|
||||
zProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
when(measurePoint){
|
||||
is Ble.Accelerometer.RealtimePoint.Common ->
|
||||
FloatEntry(index.toFloat(), measurePoint.z)
|
||||
is Ble.Accelerometer.RealtimePoint.Vibration ->
|
||||
FloatEntry(index.toFloat(), measurePoint.value)
|
||||
is Ble.Accelerometer.RealtimePoint.Angle ->
|
||||
FloatEntry(index.toFloat(), measurePoint.z)
|
||||
is Ble.Accelerometer.RealtimePoint.Rotation ->
|
||||
FloatEntry(index.toFloat(), measurePoint.turnovers.toFloat())
|
||||
FloatEntry(index.toFloat(), measurePoint.z)
|
||||
})
|
||||
|
||||
|
||||
val lastMeasure = state.measureHistory.last()
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(text = "Ось X: ${lastMeasure.x}")
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Angle(
|
||||
angle = lastMeasure.x,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(text = "Ось Y: ${lastMeasure.y}")
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Angle(
|
||||
modifier = Modifier.weight(1f),
|
||||
angle = lastMeasure.y
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(text = "Ось Z: ${lastMeasure.z}")
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Angle(
|
||||
modifier = Modifier.weight(1f),
|
||||
angle = lastMeasure.z
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayRotationState(
|
||||
state: AccelerometerAccelContract.State.DisplayRotation
|
||||
) {
|
||||
|
||||
Box(modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
|
||||
|
||||
if (state.measureHistory.isEmpty()) {
|
||||
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
strokeCap = StrokeCap.Round
|
||||
)
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
val xProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
val yProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
val zProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
xProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.angle )
|
||||
})
|
||||
|
||||
yProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.tmp)
|
||||
})
|
||||
|
||||
zProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.turnovers.toFloat())
|
||||
})
|
||||
|
||||
val lineChart = lineChart(
|
||||
|
|
@ -216,217 +501,67 @@ private fun DisplayState(
|
|||
guideline = axisGuidelineComponent()
|
||||
)
|
||||
|
||||
val lastMeasure = state.measureHistory.lastOrNull()
|
||||
val lastMeasure = state.measureHistory.last()
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
when(lastMeasure){
|
||||
is Ble.Accelerometer.RealtimePoint.Angle -> {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Положение: ${lastMeasure.angle}")
|
||||
|
||||
Text(text = "Ось X: ${lastMeasure.x}")
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Angle(
|
||||
angle = lastMeasure.angle,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
|
||||
Angle(
|
||||
angle = lastMeasure.x,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(text = "Ось Y: ${lastMeasure.y}")
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Angle(
|
||||
modifier = Modifier.weight(1f),
|
||||
angle = lastMeasure.y
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(text = "Ось Z: ${lastMeasure.z}")
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Angle(
|
||||
modifier = Modifier.weight(1f),
|
||||
angle = lastMeasure.z
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
is Ble.Accelerometer.RealtimePoint.Rotation -> {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Скорость:")
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = yProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
Text(text = "Положение: ${lastMeasure.angle}")
|
||||
Text(text = "Обороты:")
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = zProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Angle(
|
||||
angle = lastMeasure.angle,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Text(text = "Скорость:")
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = yProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
Text(text = "Обороты:")
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = zProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
is Ble.Accelerometer.RealtimePoint.Vibration -> {
|
||||
Column {
|
||||
|
||||
Text(text = "Вибрация:")
|
||||
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = xProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
is Ble.Accelerometer.RealtimePoint.Common -> {
|
||||
Column {
|
||||
|
||||
Text(text = "Ось X:")
|
||||
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = xProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
Text(text = "Ось Y:")
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = yProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
Text(text = "Ось Z:")
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = zProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -434,6 +569,70 @@ private fun DisplayState(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayVibrationState(
|
||||
state: AccelerometerAccelContract.State.DisplayVibration
|
||||
) {
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
|
||||
|
||||
val xProducer = remember {
|
||||
ChartEntryModelProducer(listOf<FloatEntry>())
|
||||
}
|
||||
|
||||
xProducer.setEntries(state.measureHistory.mapIndexed { index, measurePoint ->
|
||||
FloatEntry(index.toFloat(), measurePoint.value)
|
||||
})
|
||||
|
||||
val lineChart = lineChart(
|
||||
decorations = listOf(
|
||||
ThresholdLine(
|
||||
labelComponent = textComponent(color = androidx.compose.ui.graphics.Color.Transparent),
|
||||
lineComponent = ShapeComponent(color = Color.TRANSPARENT),
|
||||
thresholdValue = 0f
|
||||
)
|
||||
),
|
||||
persistentMarkers = mapOf(
|
||||
xProducer.getModel().maxX to MarkerComponent(
|
||||
label = textComponent(),
|
||||
indicator = null,
|
||||
guideline = axisGuidelineComponent()
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
val marker = MarkerComponent(
|
||||
label = textComponent(),
|
||||
indicator = null,
|
||||
guideline = axisGuidelineComponent()
|
||||
)
|
||||
|
||||
Chart(
|
||||
marker = marker,
|
||||
chart = lineChart,
|
||||
chartModelProducer = xProducer,
|
||||
startAxis = startAxis(),
|
||||
bottomAxis = bottomAxis(),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
autoScaleUp = AutoScaleUp.None,
|
||||
diffAnimationSpec = tween(0),
|
||||
chartScrollSpec = rememberChartScrollSpec(
|
||||
initialScroll = InitialScroll.End,
|
||||
autoScrollCondition = AutoScrollCondition.OnModelSizeIncreased,
|
||||
autoScrollAnimationSpec = tween(0)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Angle(
|
||||
modifier: Modifier = Modifier,
|
||||
|
|
@ -504,21 +703,21 @@ fun Angle(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun ExceptionState(
|
||||
|
||||
private fun LoadingState(
|
||||
viewModel: AccelerometerAccelViewModel,
|
||||
state: AccelerometerAccelContract.State.Loading
|
||||
) {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(2f),
|
||||
.fillMaxSize(),
|
||||
){
|
||||
|
||||
Text(
|
||||
textAlign = TextAlign.Center,
|
||||
text = "Во время загрузки произошла ошибка",
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
RetryingLoadingTemplate(
|
||||
attempt = state.attempt
|
||||
) {
|
||||
viewModel.setEvent(AccelerometerAccelContract.Event.OnRefresh)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.rt
|
||||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.rt.form
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -9,15 +9,12 @@ import androidx.compose.foundation.layout.wrapContentHeight
|
|||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.input.TextFieldLineLimits
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.Sort
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Surface
|
||||
|
|
@ -36,16 +33,10 @@ import com.ramcosta.composedestinations.annotation.RootGraph
|
|||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerRealtimeDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerSpectreDestination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import com.ramcosta.composedestinations.result.ResultBackNavigator
|
||||
import com.ramcosta.composedestinations.spec.DestinationStyle
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.serialization.Serializable
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.filter.BleFilterContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.RealtimeViewMode
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.model.BleFilter
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
|
|
@ -4,14 +4,10 @@ import androidx.compose.animation.core.FastOutSlowInEasing
|
|||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
|
|
@ -25,7 +21,10 @@ import androidx.compose.material3.MaterialTheme
|
|||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
|
|
@ -50,7 +49,6 @@ import com.ramcosta.composedestinations.annotation.RootGraph
|
|||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.common.ProgressState
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.write
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootGraph
|
||||
import com.ramcosta.composedestinations.result.ResultBackNavigator
|
||||
import com.ramcosta.composedestinations.spec.DestinationStyle
|
||||
import llc.arma.ble.app.ui.common.WriteFlow
|
||||
import llc.arma.ble.app.ui.common.WriteFlowContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.write.ThermometerWriteViewModel
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
|
||||
@Destination<RootGraph>(style = DestinationStyle.Dialog::class)
|
||||
@Composable
|
||||
fun AccelerometerWriteScreen(
|
||||
bleSerial: String,
|
||||
writeRequest: Ble.Accelerometer.WriteRequest,
|
||||
navigator: ResultBackNavigator<Boolean>
|
||||
) {
|
||||
|
||||
val viewModel = hiltViewModel<AccelerometerWriteViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.effect.collect {
|
||||
when(it){
|
||||
WriteFlowContract.Effect.Navigation.Up ->
|
||||
navigator.navigateBack()
|
||||
|
||||
WriteFlowContract.Effect.Navigation.UpSuccess ->
|
||||
navigator.navigateBack(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Surface(
|
||||
shape = RoundedCornerShape(20.dp)
|
||||
) {
|
||||
|
||||
Box(
|
||||
modifier = Modifier.padding(20.dp)
|
||||
) {
|
||||
|
||||
WriteFlow(
|
||||
state = state,
|
||||
onEvent = viewModel::setEvent
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.accelerometer.write
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.ramcosta.composedestinations.generated.destinations.AccelerometerWriteScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.BeaconWriteScreenDestination
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.app.ui.common.WriteFlowContract
|
||||
import llc.arma.ble.app.ui.common.WriteItemData
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInHour
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInMinute
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInSecond
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.main.BleMenuItem
|
||||
import llc.arma.ble.app.ui.screen.locale.localizedName
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.usecase.WriteBle
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AccelerometerWriteViewModel @Inject constructor(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
private val writeBle: WriteBle
|
||||
) : BaseViewModel<WriteFlowContract.State, WriteFlowContract.Event, WriteFlowContract.Effect>() {
|
||||
|
||||
init {
|
||||
|
||||
val params = AccelerometerWriteScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
val items = mutableListOf<WriteItemData>()
|
||||
|
||||
params.writeRequest.tx?.let {
|
||||
items.add(WriteItemData("Мощность", "${it.localizedName} db"))
|
||||
}
|
||||
|
||||
params.writeRequest.saveHistorySettings?.let {
|
||||
|
||||
items.add(
|
||||
WriteItemData(
|
||||
title = "Сохранять историю измерений",
|
||||
subtitle = when(it){
|
||||
Ble.Accelerometer.HistorySettings.Disabled -> "Выключено"
|
||||
is Ble.Accelerometer.HistorySettings.Enabled -> "Включено"
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
params.writeRequest.historyInterval?.let {
|
||||
|
||||
val hours = it / millisInHour
|
||||
val minutes = (it - (hours * millisInHour)) / millisInMinute
|
||||
val seconds = (it - (hours * millisInHour) - (minutes * millisInMinute)) / millisInSecond
|
||||
|
||||
items.add(
|
||||
WriteItemData(
|
||||
title = "Интервал измерений",
|
||||
subtitle = "$hours ч. $minutes мин. $seconds сек."
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
params.writeRequest.readInterval?.let {
|
||||
|
||||
val hours = it / millisInHour
|
||||
val minutes = (it - (hours * millisInHour)) / millisInMinute
|
||||
val seconds = (it - (hours * millisInHour) - (minutes * millisInMinute)) / millisInSecond
|
||||
|
||||
items.add(
|
||||
WriteItemData(
|
||||
title = "Интервал чтения",
|
||||
subtitle = "$hours ч. $minutes мин. $seconds сек."
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
setState {
|
||||
WriteFlowContract.State.Display(
|
||||
items
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun setInitialState() = WriteFlowContract.State.Loading
|
||||
|
||||
override fun handleEvents(event: WriteFlowContract.Event) {
|
||||
when(event){
|
||||
is WriteFlowContract.Event.OnNavigateUp -> reduce(viewState.value, event)
|
||||
is WriteFlowContract.Event.OnWrite -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: WriteFlowContract.State,
|
||||
event: WriteFlowContract.Event.OnNavigateUp
|
||||
){
|
||||
|
||||
setEffect {
|
||||
when(state){
|
||||
is WriteFlowContract.State.Display,
|
||||
WriteFlowContract.State.Error,
|
||||
WriteFlowContract.State.Loading,
|
||||
WriteFlowContract.State.Writing -> WriteFlowContract.Effect.Navigation.Up
|
||||
WriteFlowContract.State.Success -> WriteFlowContract.Effect.Navigation.UpSuccess
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var writeJob: Job? = null
|
||||
|
||||
private fun reduce(
|
||||
state: WriteFlowContract.State,
|
||||
event: WriteFlowContract.Event.OnWrite
|
||||
){
|
||||
|
||||
val params = AccelerometerWriteScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
setState {
|
||||
WriteFlowContract.State.Writing
|
||||
}
|
||||
|
||||
writeJob?.cancel()
|
||||
writeJob = viewModelScope.launch {
|
||||
writeBle(params.bleSerial, params.writeRequest).fold(
|
||||
onSuccess = {
|
||||
setState {
|
||||
WriteFlowContract.State.Success
|
||||
}
|
||||
},
|
||||
onFailure = {
|
||||
setState {
|
||||
WriteFlowContract.State.Error
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package llc.arma.ble.app.ui.screen.inspection.beacon
|
|||
import llc.arma.ble.app.ui.common.ViewEvent
|
||||
import llc.arma.ble.app.ui.common.ViewSideEffect
|
||||
import llc.arma.ble.app.ui.common.ViewState
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.main.ThermometerContract.Effect.Navigation
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
|
||||
|
|
@ -13,11 +12,7 @@ class BeaconContract {
|
|||
|
||||
data object OnNavigateUp : Event()
|
||||
|
||||
object OnWriteBle : Event()
|
||||
|
||||
object OnHideWriteBlePreview : Event()
|
||||
|
||||
object OnShowWriteBlePreview : Event()
|
||||
data object OnShowWriteBlePreview : Event()
|
||||
|
||||
data object OnPowerEdit : Event()
|
||||
|
||||
|
|
@ -25,56 +20,36 @@ class BeaconContract {
|
|||
val ble: Ble.Beacon
|
||||
) : Event()
|
||||
|
||||
data class OnPowerChanged(
|
||||
val tx: BleView.BleState.TX
|
||||
data class OnTxChanged(
|
||||
val tx: Ble.BleState.TX
|
||||
) : Event()
|
||||
|
||||
data class OnTxChanged(val tx: BleView.BleState.TX) : Event()
|
||||
|
||||
object OnNavigateUpClicked : Event()
|
||||
|
||||
object OnChangePassword : Event()
|
||||
data object OnChangePassword : Event()
|
||||
|
||||
}
|
||||
|
||||
sealed class State : ViewState {
|
||||
|
||||
data object Loading : State()
|
||||
data class Loading(
|
||||
val attempt: Int?
|
||||
) : State()
|
||||
|
||||
data class Display(
|
||||
val origin: Ble.Beacon,
|
||||
val beacon: BleView.Beacon,
|
||||
val writeState: WriteState?
|
||||
) : State() {
|
||||
|
||||
sealed class WriteState {
|
||||
|
||||
data class DisplayPreview(
|
||||
val writeRequest: Ble.Beacon.WriteRequest
|
||||
) : WriteState()
|
||||
|
||||
data class Writing(
|
||||
val writeRequest: Ble.Beacon.WriteRequest
|
||||
) : WriteState()
|
||||
|
||||
data object Success : WriteState()
|
||||
|
||||
data object Failure : WriteState()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
val beacon: Ble.Beacon
|
||||
) : State()
|
||||
|
||||
}
|
||||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
data object HideWriteBlePreview : Effect()
|
||||
|
||||
data object ShowWriteBlePreview : Effect()
|
||||
|
||||
sealed class Navigation : Effect() {
|
||||
|
||||
data class Write(
|
||||
val bleSerial: String,
|
||||
val writeRequest: Ble.Beacon.WriteRequest
|
||||
) : Navigation()
|
||||
|
||||
data object Up : Navigation()
|
||||
|
||||
data class PasswordForm(
|
||||
|
|
@ -82,7 +57,7 @@ class BeaconContract {
|
|||
) : Navigation()
|
||||
|
||||
data class TxSelector(
|
||||
val tx: BleView.BleState.TX?
|
||||
val tx: Ble.BleState.TX?
|
||||
) : Navigation()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.beacon
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ContainedLoadingIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
|
|
@ -17,53 +15,39 @@ import androidx.compose.material3.Text
|
|||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootGraph
|
||||
import com.ramcosta.composedestinations.generated.destinations.BeaconWriteScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.ChangePasswordScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.TxPowerSelectorScreenDestination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import com.ramcosta.composedestinations.result.ResultRecipient
|
||||
import com.ramcosta.composedestinations.result.onResult
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.rememberBottomDialogState
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.common.RetryingLoadingTemplate
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.view.DisplayState
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.view.Write
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.main.GateContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.main.GateViewModel
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
|
||||
enum class SheetPage {
|
||||
WRITE
|
||||
}
|
||||
|
||||
@Destination<RootGraph>
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BeaconScreen(
|
||||
bleSerial: String,
|
||||
txSelectResult: ResultRecipient<TxPowerSelectorScreenDestination, BleView.BleState.TX>,
|
||||
txSelectResult: ResultRecipient<TxPowerSelectorScreenDestination, Ble.BleState.TX>,
|
||||
navigator: DestinationsNavigator
|
||||
) {
|
||||
|
||||
val viewModel = hiltViewModel<BeaconViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
var sheetPage by rememberSaveable {
|
||||
mutableStateOf<SheetPage?>(null)
|
||||
}
|
||||
|
||||
val bottomDialog = rememberBottomDialogState()
|
||||
|
||||
txSelectResult.onResult {
|
||||
viewModel.setEvent(BeaconContract.Event.OnTxChanged(it))
|
||||
}
|
||||
|
|
@ -72,15 +56,6 @@ fun BeaconScreen(
|
|||
viewModel.effect.onEach {
|
||||
when(it){
|
||||
|
||||
BeaconContract.Effect.HideWriteBlePreview -> launch {
|
||||
sheetPage = null
|
||||
}
|
||||
BeaconContract.Effect.ShowWriteBlePreview -> launch {
|
||||
sheetPage = null
|
||||
delay(100)
|
||||
sheetPage = SheetPage.WRITE
|
||||
}
|
||||
|
||||
is BeaconContract.Effect.Navigation.PasswordForm ->
|
||||
navigator.navigate(ChangePasswordScreenDestination(it.bleSerial))
|
||||
|
||||
|
|
@ -88,35 +63,14 @@ fun BeaconScreen(
|
|||
navigator.navigate(TxPowerSelectorScreenDestination(it.tx))
|
||||
|
||||
BeaconContract.Effect.Navigation.Up ->
|
||||
navigator.popBackStack()
|
||||
navigator.navigateUp()
|
||||
|
||||
is BeaconContract.Effect.Navigation.Write ->
|
||||
navigator.navigate(BeaconWriteScreenDestination(it.bleSerial, it.writeRequest))
|
||||
}
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
LaunchedEffect(sheetPage){
|
||||
when(sheetPage){
|
||||
SheetPage.WRITE -> bottomDialog.show {
|
||||
|
||||
val currentState = viewModel.viewState.value
|
||||
|
||||
if(currentState is BeaconContract.State.Display && currentState.writeState != null) {
|
||||
|
||||
Write(
|
||||
state = currentState.writeState,
|
||||
onEvent = {
|
||||
viewModel.setEvent(it)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else -> {
|
||||
bottomDialog.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
|
|
@ -144,34 +98,30 @@ fun BeaconScreen(
|
|||
) {
|
||||
|
||||
when(state){
|
||||
is BeaconContract.State.Display -> DisplayState(
|
||||
onEvent = {
|
||||
viewModel.setEvent(it)
|
||||
},
|
||||
ble = state.beacon,
|
||||
origin = state.origin
|
||||
)
|
||||
is BeaconContract.State.Loading -> LoadingState()
|
||||
is BeaconContract.State.Display -> DisplayState(viewModel, state)
|
||||
is BeaconContract.State.Loading -> LoadingState(viewModel, state)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
private fun LoadingState(){
|
||||
private fun LoadingState(
|
||||
viewModel: BeaconViewModel,
|
||||
state: BeaconContract.State.Loading,
|
||||
){
|
||||
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
){
|
||||
|
||||
ContainedLoadingIndicator()
|
||||
RetryingLoadingTemplate(state.attempt){
|
||||
viewModel.setEvent(BeaconContract.Event.OnNavigateUp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,22 +2,14 @@ package llc.arma.ble.app.ui.screen.inspection.beacon
|
|||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.toRoute
|
||||
import com.ramcosta.composedestinations.generated.destinations.BeaconScreenDestination
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.app.ui.mapper.BleMapper
|
||||
import llc.arma.ble.app.ui.mapper.BleViewMapper
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.AccelerometerContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.accelerometer.main.view.RealtimeViewMode
|
||||
import llc.arma.ble.app.ui.common.retryUntilNotNull
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.main.GateContract
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.usecase.AccelScale
|
||||
import llc.arma.ble.domain.usecase.AccelViewMode
|
||||
import llc.arma.ble.domain.usecase.FftAxis
|
||||
import llc.arma.ble.domain.usecase.FftFrequency
|
||||
import llc.arma.ble.domain.usecase.FftViewMode
|
||||
import llc.arma.ble.domain.usecase.GetBleBySerial
|
||||
import llc.arma.ble.domain.usecase.WriteBle
|
||||
import javax.inject.Inject
|
||||
|
|
@ -26,9 +18,6 @@ import javax.inject.Inject
|
|||
class BeaconViewModel @Inject constructor(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
getBleBySerial: GetBleBySerial,
|
||||
private val bleMapper: BleMapper,
|
||||
private val writeBle: WriteBle,
|
||||
private val bleViewMapper: BleViewMapper
|
||||
) : BaseViewModel<BeaconContract.State, BeaconContract.Event, BeaconContract.Effect>() {
|
||||
|
||||
init {
|
||||
|
|
@ -37,12 +26,17 @@ class BeaconViewModel @Inject constructor(
|
|||
|
||||
viewModelScope.launch {
|
||||
|
||||
val ble = getBleBySerial.invoke(params.bleSerial, this).fold(
|
||||
onSuccess = { it },
|
||||
onFailure = { null }
|
||||
)
|
||||
val ble = retryUntilNotNull(
|
||||
onNewAttempt = {
|
||||
setState {
|
||||
BeaconContract.State.Loading(it)
|
||||
}
|
||||
}
|
||||
){
|
||||
getBleBySerial.invoke(params.bleSerial, this).getOrNull()
|
||||
}
|
||||
|
||||
if(ble != null && ble is Ble.Beacon){
|
||||
if(ble is Ble.Beacon){
|
||||
setState {
|
||||
|
||||
when(this){
|
||||
|
|
@ -54,11 +48,10 @@ class BeaconViewModel @Inject constructor(
|
|||
)
|
||||
)
|
||||
}
|
||||
BeaconContract.State.Loading -> {
|
||||
is BeaconContract.State.Loading -> {
|
||||
BeaconContract.State.Display(
|
||||
origin = ble,
|
||||
beacon = bleMapper.map(ble) as BleView.Beacon,
|
||||
writeState = null
|
||||
beacon = ble
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -69,36 +62,19 @@ class BeaconViewModel @Inject constructor(
|
|||
|
||||
}
|
||||
|
||||
override fun setInitialState() = BeaconContract.State.Loading
|
||||
override fun setInitialState() = BeaconContract.State.Loading(null)
|
||||
|
||||
override fun handleEvents(event: BeaconContract.Event) {
|
||||
when(event){
|
||||
is BeaconContract.Event.OnNavigateUpClicked -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnTxChanged -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnBleChanged -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnChangePassword -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnHideWriteBlePreview -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnShowWriteBlePreview -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnWriteBle -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnPowerChanged -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnPowerEdit -> reduce(viewState.value, event)
|
||||
is BeaconContract.Event.OnNavigateUp -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnPowerChanged
|
||||
) {
|
||||
|
||||
if(state is BeaconContract.State.Display) {
|
||||
|
||||
state.beacon.state.tx = event.tx
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnNavigateUp
|
||||
|
|
@ -124,19 +100,21 @@ class BeaconViewModel @Inject constructor(
|
|||
|
||||
}
|
||||
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnNavigateUpClicked
|
||||
) {
|
||||
setEffect { BeaconContract.Effect.Navigation.Up }
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnTxChanged
|
||||
) {
|
||||
|
||||
if(state is BeaconContract.State.Display){
|
||||
setState {
|
||||
state.copy(
|
||||
beacon = state.beacon.copy(
|
||||
state = state.beacon.state.copy(
|
||||
tx = event.tx
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
|
|
@ -159,8 +137,7 @@ class BeaconViewModel @Inject constructor(
|
|||
setState {
|
||||
BeaconContract.State.Display(
|
||||
origin = event.ble,
|
||||
beacon = bleMapper.map(event.ble) as BleView.Beacon,
|
||||
writeState = null
|
||||
beacon = event.ble
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -181,15 +158,6 @@ class BeaconViewModel @Inject constructor(
|
|||
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnHideWriteBlePreview
|
||||
) {
|
||||
setEffect {
|
||||
BeaconContract.Effect.HideWriteBlePreview
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnShowWriteBlePreview
|
||||
|
|
@ -197,83 +165,16 @@ class BeaconViewModel @Inject constructor(
|
|||
|
||||
if(state is BeaconContract.State.Display){
|
||||
|
||||
val newBle = bleViewMapper.map(state.beacon) as Ble.Beacon
|
||||
val params = BeaconScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
val newBle = state.beacon
|
||||
|
||||
val writeRequest = Ble.Beacon.WriteRequest(
|
||||
tx = if(newBle.state.tx == state.origin.state.tx) null else newBle.state.tx
|
||||
)
|
||||
|
||||
setState {
|
||||
state.copy(
|
||||
writeState = BeaconContract.State.Display.WriteState.DisplayPreview(
|
||||
writeRequest
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
setEffect {
|
||||
BeaconContract.Effect.ShowWriteBlePreview
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: BeaconContract.State,
|
||||
event: BeaconContract.Event.OnWriteBle
|
||||
) {
|
||||
|
||||
if(state is BeaconContract.State.Display){
|
||||
|
||||
state.writeState?.let { request ->
|
||||
|
||||
if(request is BeaconContract.State.Display.WriteState.DisplayPreview) {
|
||||
|
||||
viewModelScope.launch {
|
||||
|
||||
setState {
|
||||
state.copy(
|
||||
writeState = BeaconContract.State.Display.WriteState.Writing(request.writeRequest)
|
||||
)
|
||||
}
|
||||
|
||||
val currentState = viewState.value
|
||||
|
||||
if(currentState is BeaconContract.State.Display) {
|
||||
|
||||
val newBleObject = Ble.Beacon(
|
||||
info = currentState.origin.info,
|
||||
state = currentState.origin.state.copy(
|
||||
tx = request.writeRequest.tx ?: state.origin.state.tx
|
||||
)
|
||||
)
|
||||
|
||||
writeBle(state.beacon.info.serial, request.writeRequest).fold(
|
||||
onSuccess = {
|
||||
setState {
|
||||
currentState.copy(
|
||||
origin = newBleObject,
|
||||
beacon = bleMapper.map(newBleObject) as BleView.Beacon,
|
||||
writeState = BeaconContract.State.Display.WriteState.Success
|
||||
)
|
||||
}
|
||||
},
|
||||
onFailure = {
|
||||
setState {
|
||||
state.copy(
|
||||
writeState = BeaconContract.State.Display.WriteState.Failure
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BeaconContract.Effect.Navigation.Write(params.bleSerial, writeRequest)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,95 +1,110 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.beacon.view
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowDown
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowRight
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import llc.arma.ble.app.ui.common.PrimaryButton
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.screen.BleInfoView
|
||||
import llc.arma.ble.app.ui.screen.ShapeType
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconViewModel
|
||||
import llc.arma.ble.app.ui.screen.inspection.thermometer.main.BleMenuItem
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.app.ui.screen.locale.value
|
||||
|
||||
@Composable
|
||||
fun DisplayState(
|
||||
onEvent: (BeaconContract.Event) -> Unit,
|
||||
origin: Ble.Beacon,
|
||||
ble: BleView.Beacon
|
||||
viewModel: BeaconViewModel,
|
||||
state: BeaconContract.State.Display
|
||||
) {
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
|
||||
BleInfoView(
|
||||
bleInfo = origin.info,
|
||||
version = origin.state.version
|
||||
)
|
||||
Column {
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 16.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Start,
|
||||
title = "Мощность",
|
||||
subtitle = "${ble.state.tx.value} db",
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.KeyboardArrowDown,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnPowerEdit)
|
||||
}
|
||||
BleInfoView(
|
||||
bleInfo = state.origin.info,
|
||||
version = state.origin.state.version
|
||||
)
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.End,
|
||||
title = "Изменить пароль",
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.KeyboardArrowRight,
|
||||
contentDescription = null
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.Start,
|
||||
title = "Мощность",
|
||||
subtitle = "${state.beacon.state.tx.value} db",
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.KeyboardArrowDown,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
) {
|
||||
viewModel.setEvent(BeaconContract.Event.OnPowerEdit)
|
||||
}
|
||||
|
||||
BleMenuItem(
|
||||
shapeType = ShapeType.End,
|
||||
title = "Изменить пароль",
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Rounded.KeyboardArrowRight,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
|
||||
) {
|
||||
viewModel.setEvent(BeaconContract.Event.OnChangePassword)
|
||||
}
|
||||
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnChangePassword)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Button (
|
||||
onClick = {
|
||||
onEvent(BeaconContract.Event.OnShowWriteBlePreview)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth().animateContentSize()
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Сохранить"
|
||||
)
|
||||
if(state.origin != state.beacon) {
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
viewModel.setEvent(BeaconContract.Event.OnShowWriteBlePreview)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Сохранить"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,239 +0,0 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.beacon.view
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import llc.arma.ble.R
|
||||
import llc.arma.ble.app.ui.common.PrimaryButton
|
||||
import llc.arma.ble.app.ui.common.SecondaryButton
|
||||
import llc.arma.ble.app.ui.screen.inspection.beacon.BeaconContract
|
||||
import llc.arma.ble.app.ui.screen.locale.localizedName
|
||||
|
||||
@Composable
|
||||
fun Write(
|
||||
state: BeaconContract.State.Display.WriteState,
|
||||
onEvent: (BeaconContract.Event) -> Unit
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.animateContentSize()
|
||||
) {
|
||||
|
||||
Text(
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
text = "Запись изменений",
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
when (state) {
|
||||
is BeaconContract.State.Display.WriteState.DisplayPreview -> {
|
||||
|
||||
if(state.writeRequest.tx != null) {
|
||||
|
||||
state.writeRequest.tx.let {
|
||||
Box(
|
||||
modifier = Modifier.padding(
|
||||
vertical = 0.dp,
|
||||
horizontal = 8.dp
|
||||
)
|
||||
) {
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.padding(8.dp)
|
||||
) {
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "Мощность"
|
||||
)
|
||||
Text(
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
text = "${it.localizedName} db"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Записать"
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnWriteBle)
|
||||
}
|
||||
|
||||
SecondaryButton(
|
||||
label = "Отменить"
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Spacer(modifier = Modifier.height(38.dp))
|
||||
|
||||
Text(
|
||||
text = "Нет изменений",
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(64.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Ок"
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
is BeaconContract.State.Display.WriteState.Writing -> {
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
Spacer(modifier = Modifier.height(28.dp))
|
||||
|
||||
CircularProgressIndicator(
|
||||
strokeCap = StrokeCap.Round,
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(48.dp))
|
||||
|
||||
SecondaryButton(
|
||||
label = "Отменить"
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
BeaconContract.State.Display.WriteState.Success -> {
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Image(
|
||||
modifier = Modifier
|
||||
.size(125.dp)
|
||||
.align(Alignment.Center),
|
||||
painter = painterResource(R.drawable.ic_done),
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Успешно завершено"
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Ок"
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
BeaconContract.State.Display.WriteState.Failure -> {
|
||||
|
||||
Box {
|
||||
|
||||
Column {
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
|
||||
Image(
|
||||
modifier = Modifier
|
||||
.size(125.dp)
|
||||
.align(Alignment.Center),
|
||||
painter = painterResource(R.drawable.ic_error),
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Ошибка записи"
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
PrimaryButton(
|
||||
label = "Ок"
|
||||
) {
|
||||
onEvent(BeaconContract.Event.OnHideWriteBlePreview)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.beacon.write
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootGraph
|
||||
import com.ramcosta.composedestinations.result.ResultBackNavigator
|
||||
import com.ramcosta.composedestinations.spec.DestinationStyle
|
||||
import llc.arma.ble.app.ui.common.WriteFlow
|
||||
import llc.arma.ble.app.ui.common.WriteFlowContract
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.table.write.BleTableWriteViewModel
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
|
||||
@Destination<RootGraph>(style = DestinationStyle.Dialog::class)
|
||||
@Composable
|
||||
fun BeaconWriteScreen(
|
||||
bleSerial: String,
|
||||
writeRequest: Ble.Beacon.WriteRequest,
|
||||
navigator: ResultBackNavigator<Boolean>
|
||||
) {
|
||||
|
||||
val viewModel = hiltViewModel<BeaconWriteViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.effect.collect {
|
||||
when(it){
|
||||
WriteFlowContract.Effect.Navigation.Up ->
|
||||
navigator.navigateBack()
|
||||
|
||||
WriteFlowContract.Effect.Navigation.UpSuccess ->
|
||||
navigator.navigateBack(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Surface(
|
||||
shape = RoundedCornerShape(20.dp)
|
||||
) {
|
||||
|
||||
Box(
|
||||
modifier = Modifier.padding(20.dp)
|
||||
) {
|
||||
|
||||
WriteFlow(
|
||||
state = state,
|
||||
onEvent = viewModel::setEvent
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package llc.arma.ble.app.ui.screen.inspection.beacon.write
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.ramcosta.composedestinations.generated.destinations.BeaconWriteScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.GateWriteScreenDestination
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.BaseViewModel
|
||||
import llc.arma.ble.app.ui.common.WriteFlowContract
|
||||
import llc.arma.ble.app.ui.common.WriteItemData
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInHour
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInMinute
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.millisInSecond
|
||||
import llc.arma.ble.app.ui.screen.locale.localizedName
|
||||
import llc.arma.ble.domain.usecase.WriteBle
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class BeaconWriteViewModel @Inject constructor(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
private val writeBle: WriteBle
|
||||
) : BaseViewModel<WriteFlowContract.State, WriteFlowContract.Event, WriteFlowContract.Effect>() {
|
||||
|
||||
init {
|
||||
|
||||
val params = BeaconWriteScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
val items = mutableListOf<WriteItemData>()
|
||||
|
||||
params.writeRequest.tx?.let {
|
||||
items.add(WriteItemData("Мощность", "${it.localizedName} db"))
|
||||
}
|
||||
|
||||
setState {
|
||||
WriteFlowContract.State.Display(
|
||||
items
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun setInitialState() = WriteFlowContract.State.Loading
|
||||
|
||||
override fun handleEvents(event: WriteFlowContract.Event) {
|
||||
when(event){
|
||||
is WriteFlowContract.Event.OnNavigateUp -> reduce(viewState.value, event)
|
||||
is WriteFlowContract.Event.OnWrite -> reduce(viewState.value, event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reduce(
|
||||
state: WriteFlowContract.State,
|
||||
event: WriteFlowContract.Event.OnNavigateUp
|
||||
){
|
||||
|
||||
setEffect {
|
||||
when(state){
|
||||
is WriteFlowContract.State.Display,
|
||||
WriteFlowContract.State.Error,
|
||||
WriteFlowContract.State.Loading,
|
||||
WriteFlowContract.State.Writing -> WriteFlowContract.Effect.Navigation.Up
|
||||
WriteFlowContract.State.Success -> WriteFlowContract.Effect.Navigation.UpSuccess
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var writeJob: Job? = null
|
||||
|
||||
private fun reduce(
|
||||
state: WriteFlowContract.State,
|
||||
event: WriteFlowContract.Event.OnWrite
|
||||
){
|
||||
|
||||
val params = BeaconWriteScreenDestination.argsFrom(savedStateHandle)
|
||||
|
||||
setState {
|
||||
WriteFlowContract.State.Writing
|
||||
}
|
||||
|
||||
writeJob?.cancel()
|
||||
writeJob = viewModelScope.launch {
|
||||
writeBle(params.bleSerial, params.writeRequest).fold(
|
||||
onSuccess = {
|
||||
setState {
|
||||
WriteFlowContract.State.Success
|
||||
}
|
||||
},
|
||||
onFailure = {
|
||||
setState {
|
||||
WriteFlowContract.State.Error
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -37,8 +37,13 @@ import androidx.compose.material3.Surface
|
|||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.VerticalDivider
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
|
@ -244,7 +249,7 @@ private fun LoadingState(
|
|||
|
||||
if(state.progress == null){
|
||||
ContainedLoadingIndicator()
|
||||
}else{
|
||||
} else {
|
||||
ContainedLoadingIndicator(
|
||||
progress = { state.progress }
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package llc.arma.ble.app.ui.screen.inspection.gate.history
|
|||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.toRoute
|
||||
import com.ramcosta.composedestinations.generated.destinations.GateHistoryScreenDestination
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package llc.arma.ble.app.ui.screen.inspection.gate.main
|
|||
import llc.arma.ble.app.ui.common.ViewEvent
|
||||
import llc.arma.ble.app.ui.common.ViewSideEffect
|
||||
import llc.arma.ble.app.ui.common.ViewState
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
|
||||
|
|
@ -11,16 +10,14 @@ class GateContract {
|
|||
|
||||
sealed class Event : ViewEvent {
|
||||
|
||||
data object OnReload : Event()
|
||||
|
||||
data object OnWriteBle : Event()
|
||||
|
||||
data object OnHideWriteBlePreview : Event()
|
||||
|
||||
data object OnShowWriteBlePreview : Event()
|
||||
|
||||
data object OnTxSelect : Event()
|
||||
|
||||
data class OnPowerChanged(
|
||||
val tx: BleView.BleState.TX
|
||||
val tx: Ble.BleState.TX
|
||||
) : Event()
|
||||
|
||||
data object OnHistoryIntervalSelect : Event()
|
||||
|
|
@ -53,7 +50,7 @@ class GateContract {
|
|||
|
||||
data class Display(
|
||||
val origin: Ble.Gate,
|
||||
val gate: BleView.Gate,
|
||||
val gate: Ble.Gate,
|
||||
val writeState: WriteState?
|
||||
) : State() {
|
||||
|
||||
|
|
@ -79,10 +76,13 @@ class GateContract {
|
|||
|
||||
sealed class Effect : ViewSideEffect {
|
||||
|
||||
data object ShowWriteBlePreview : Effect()
|
||||
|
||||
sealed class Navigation : Effect() {
|
||||
|
||||
data class GateWrite(
|
||||
val serial: String,
|
||||
val request: Ble.Gate.WriteRequest
|
||||
) : Navigation()
|
||||
|
||||
data class ChangePassword(
|
||||
val serial: String,
|
||||
) : Navigation()
|
||||
|
|
@ -98,7 +98,7 @@ class GateContract {
|
|||
) : Navigation()
|
||||
|
||||
data class TxSelector(
|
||||
val tx: BleView.BleState.TX?
|
||||
val tx: Ble.BleState.TX?
|
||||
) : Navigation()
|
||||
|
||||
data class ReadIntervalSelector(
|
||||
|
|
|
|||
|
|
@ -9,24 +9,19 @@ import androidx.compose.foundation.layout.padding
|
|||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.ArrowBack
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material.icons.rounded.Refresh
|
||||
import androidx.compose.material3.ContainedLoadingIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
|
|
@ -38,25 +33,20 @@ import com.ramcosta.composedestinations.generated.destinations.ChangePasswordScr
|
|||
import com.ramcosta.composedestinations.generated.destinations.DurationSelectorScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.GateBleTableScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.GateHistoryScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.GateWriteScreenDestination
|
||||
import com.ramcosta.composedestinations.generated.destinations.TxPowerSelectorScreenDestination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import com.ramcosta.composedestinations.result.ResultRecipient
|
||||
import com.ramcosta.composedestinations.result.onResult
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import llc.arma.ble.app.ui.common.rememberBottomDialogState
|
||||
import llc.arma.ble.app.ui.model.BleView
|
||||
import llc.arma.ble.app.ui.common.RetryingLoadingTemplate
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.main.view.DisplayState
|
||||
import llc.arma.ble.app.ui.screen.inspection.gate.main.view.Write
|
||||
import llc.arma.ble.app.ui.screen.inspection.selector.duration.DurationSelectResult
|
||||
import llc.arma.ble.app.ui.screen.locale.localized
|
||||
import llc.arma.ble.domain.model.Ble
|
||||
import llc.arma.ble.domain.model.BleInfo
|
||||
|
||||
enum class SheetPage {
|
||||
WRITE
|
||||
}
|
||||
|
||||
@Destination<RootGraph>
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
|
|
@ -64,19 +54,18 @@ enum class SheetPage {
|
|||
fun GateScreen(
|
||||
bleSerial: String,
|
||||
readDurationSelectResult: ResultRecipient<DurationSelectorScreenDestination, DurationSelectResult>,
|
||||
txSelectResult: ResultRecipient<TxPowerSelectorScreenDestination, BleView.BleState.TX>,
|
||||
txSelectResult: ResultRecipient<TxPowerSelectorScreenDestination, Ble.BleState.TX>,
|
||||
writeResult: ResultRecipient<GateWriteScreenDestination, Boolean>,
|
||||
navigator: DestinationsNavigator
|
||||
) {
|
||||
|
||||
val viewModel = hiltViewModel<GateViewModel>()
|
||||
val state = viewModel.viewState.value
|
||||
|
||||
var sheetPage by rememberSaveable {
|
||||
mutableStateOf<SheetPage?>(null)
|
||||
writeResult.onResult {
|
||||
if(it) viewModel.setEvent(GateContract.Event.OnReload)
|
||||
}
|
||||
|
||||
val bottomDialog = rememberBottomDialogState()
|
||||
|
||||
txSelectResult.onResult {
|
||||
viewModel.setEvent(GateContract.Event.OnPowerChanged(it))
|
||||
}
|
||||
|
|
@ -96,11 +85,6 @@ fun GateScreen(
|
|||
LaunchedEffect(Unit){
|
||||
viewModel.effect.onEach {
|
||||
when(it){
|
||||
GateContract.Effect.ShowWriteBlePreview -> launch {
|
||||
sheetPage = null
|
||||
delay(100)
|
||||
sheetPage = SheetPage.WRITE
|
||||
}
|
||||
|
||||
is GateContract.Effect.Navigation.BleTable ->
|
||||
navigator.navigate(GateBleTableScreenDestination(it.serial))
|
||||
|
|
@ -131,35 +115,13 @@ fun GateScreen(
|
|||
maximum = 10 * 24 * 60 * 60 * 1000
|
||||
))
|
||||
|
||||
is GateContract.Effect.Navigation.GateWrite ->
|
||||
navigator.navigate(GateWriteScreenDestination(it.serial, it.request))
|
||||
|
||||
}
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
LaunchedEffect(sheetPage){
|
||||
when(sheetPage){
|
||||
SheetPage.WRITE -> bottomDialog.show {
|
||||
|
||||
val currentState = viewModel.viewState.value
|
||||
|
||||
if(currentState is GateContract.State.Display && currentState.writeState != null) {
|
||||
|
||||
Write(
|
||||
state = currentState.writeState,
|
||||
onEvent = {
|
||||
viewModel.setEvent(it)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else -> {
|
||||
bottomDialog.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
|
|
@ -179,6 +141,20 @@ fun GateScreen(
|
|||
Text(
|
||||
text = BleInfo.Type.HOST.localized
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
if(state is GateContract.State.Display){
|
||||
IconButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(GateContract.Event.OnReload)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Refresh,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -199,11 +175,10 @@ fun GateScreen(
|
|||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
private fun LoadingState(
|
||||
viewModel: GateViewModel,
|
||||
state: GateContract.State.Loading
|
||||
state: GateContract.State.Loading,
|
||||
){
|
||||
|
||||
Box(
|
||||
|
|
@ -211,43 +186,8 @@ private fun LoadingState(
|
|||
modifier = Modifier.fillMaxSize()
|
||||
){
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.widthIn(max = 230.dp)
|
||||
) {
|
||||
|
||||
ContainedLoadingIndicator()
|
||||
|
||||
state.attempt?.let {
|
||||
|
||||
Spacer(Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = "Повторная попытка ${it}"
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "Во время загрузки произошла ошибка",
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
TextButton(
|
||||
onClick = {
|
||||
viewModel.setEvent(GateContract.Event.OnNavigateUp)
|
||||
| < | ||||