Rename CameraScreenState to LiveAnalysisState
Remove unused fields
This commit is contained in:
@@ -4,11 +4,8 @@ import android.graphics.Bitmap
|
||||
import androidx.compose.runtime.Immutable
|
||||
|
||||
@Immutable
|
||||
// TODO Rename to LiveAnalysisState
|
||||
data class CameraScreenState(
|
||||
val detectionMessage: String? = null,
|
||||
data class LiveAnalysisState(
|
||||
val inferenceTime: Long = 0L,
|
||||
val binaryMask: Bitmap? = null,
|
||||
val errorMessage: String? = null,
|
||||
val documentQuad: Quad? = null,
|
||||
)
|
||||
@@ -37,7 +37,7 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
val currentScreen by viewModel.currentScreen.collectAsStateWithLifecycle()
|
||||
val cameraScreenState by viewModel.cameraScreenState.collectAsStateWithLifecycle()
|
||||
val liveAnalysisState by viewModel.liveAnalysisState.collectAsStateWithLifecycle()
|
||||
val pages by viewModel.pages.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
MyScanTheme {
|
||||
@@ -45,7 +45,7 @@ class MainActivity : ComponentActivity() {
|
||||
Column (modifier = Modifier.padding(innerPadding)) {
|
||||
when (currentScreen) {
|
||||
is Screen.Camera -> {
|
||||
CameraScreen(viewModel, cameraScreenState,
|
||||
CameraScreen(viewModel, liveAnalysisState,
|
||||
onImageAnalyzed = { image -> viewModel.segment(image) },
|
||||
onFinalizePressed = { viewModel.navigateTo(Screen.FinalizeDocument) }
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Matrix
|
||||
import androidx.camera.core.ImageProxy
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -29,8 +28,8 @@ class MainViewModel(private val imageSegmentationService: ImageSegmentationServi
|
||||
}
|
||||
}
|
||||
|
||||
private var _cameraScreenState = MutableStateFlow(CameraScreenState("just started"))
|
||||
val cameraScreenState: StateFlow<CameraScreenState> = _cameraScreenState.asStateFlow()
|
||||
private var _liveAnalysisState = MutableStateFlow(LiveAnalysisState())
|
||||
val liveAnalysisState: StateFlow<LiveAnalysisState> = _liveAnalysisState.asStateFlow()
|
||||
|
||||
private val _currentScreen = MutableStateFlow<Screen>(Screen.Camera)
|
||||
val currentScreen: StateFlow<Screen> = _currentScreen.asStateFlow()
|
||||
@@ -46,15 +45,14 @@ class MainViewModel(private val imageSegmentationService: ImageSegmentationServi
|
||||
.filterNotNull()
|
||||
.map {
|
||||
val binaryMask = it.segmentation.toBinaryMask()
|
||||
CameraScreenState(
|
||||
detectionMessage = "Inference done",
|
||||
LiveAnalysisState(
|
||||
inferenceTime = it.inferenceTime,
|
||||
binaryMask = binaryMask,
|
||||
documentQuad = detectDocumentQuad(binaryMask)
|
||||
)
|
||||
}
|
||||
.collect {
|
||||
_cameraScreenState.value = it
|
||||
_liveAnalysisState.value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ import androidx.core.graphics.scale
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import org.mydomain.myscan.CameraScreenState
|
||||
import org.mydomain.myscan.LiveAnalysisState
|
||||
import org.mydomain.myscan.MainViewModel
|
||||
import org.mydomain.myscan.Point
|
||||
import org.mydomain.myscan.scaledTo
|
||||
@@ -66,7 +66,7 @@ import java.util.concurrent.Executors
|
||||
@Composable
|
||||
fun CameraScreen(
|
||||
viewModel: MainViewModel,
|
||||
uiState: CameraScreenState,
|
||||
liveAnalysisState: LiveAnalysisState,
|
||||
onImageAnalyzed: (ImageProxy) -> Unit,
|
||||
onFinalizePressed: () -> Unit
|
||||
) {
|
||||
@@ -98,8 +98,8 @@ fun CameraScreen(
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
CameraPreviewWithOverlay(onImageAnalyzed, captureController, uiState)
|
||||
MessageBox(uiState.inferenceTime)
|
||||
CameraPreviewWithOverlay(onImageAnalyzed, captureController, liveAnalysisState)
|
||||
MessageBox(liveAnalysisState.inferenceTime)
|
||||
Button(
|
||||
onClick = {
|
||||
showPageDialog.value = true
|
||||
@@ -148,7 +148,7 @@ fun CameraScreen(
|
||||
private fun CameraPreviewWithOverlay(
|
||||
onImageAnalyzed: (ImageProxy) -> Unit,
|
||||
captureController: CameraCaptureController,
|
||||
uiState: CameraScreenState
|
||||
liveAnalysisState: LiveAnalysisState
|
||||
) {
|
||||
val width = LocalConfiguration.current.screenWidthDp
|
||||
val height = width / 3 * 4
|
||||
@@ -161,7 +161,7 @@ private fun CameraPreviewWithOverlay(
|
||||
onImageAnalyzed = onImageAnalyzed,
|
||||
captureController = captureController
|
||||
)
|
||||
AnalysisOverlay(uiState)
|
||||
AnalysisOverlay(liveAnalysisState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,8 +237,8 @@ fun bindCameraUseCases(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AnalysisOverlay(cameraScreenState: CameraScreenState) {
|
||||
val binaryMask = cameraScreenState.binaryMask
|
||||
private fun AnalysisOverlay(liveAnalysisState: LiveAnalysisState) {
|
||||
val binaryMask = liveAnalysisState.binaryMask
|
||||
if (binaryMask == null) {
|
||||
return
|
||||
}
|
||||
@@ -248,8 +248,8 @@ private fun AnalysisOverlay(cameraScreenState: CameraScreenState) {
|
||||
maskOverlay.scale(size.width.toInt(), size.height.toInt()).asImageBitmap(),
|
||||
colorFilter = ColorFilter.tint(Color(0x8000FF00), BlendMode.SrcIn)
|
||||
)
|
||||
if (cameraScreenState.documentQuad != null) {
|
||||
val scaledQuad = cameraScreenState.documentQuad.scaledTo(
|
||||
if (liveAnalysisState.documentQuad != null) {
|
||||
val scaledQuad = liveAnalysisState.documentQuad.scaledTo(
|
||||
fromWidth = binaryMask.width,
|
||||
fromHeight = binaryMask.height,
|
||||
toWidth = size.width.toInt(),
|
||||
|
||||
Reference in New Issue
Block a user