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