1414 */
1515package org.fairscan.app.view
1616
17- import androidx.compose.foundation.Image
1817import androidx.compose.foundation.clickable
1918import androidx.compose.foundation.layout.Column
20- import androidx.compose.foundation.layout.Row
2119import androidx.compose.foundation.layout.Spacer
2220import androidx.compose.foundation.layout.fillMaxSize
2321import androidx.compose.foundation.layout.fillMaxWidth
2422import androidx.compose.foundation.layout.height
2523import androidx.compose.foundation.layout.padding
26- import androidx.compose.foundation.layout.width
2724import androidx.compose.foundation.rememberScrollState
2825import androidx.compose.foundation.verticalScroll
2926import androidx.compose.material.icons.Icons
@@ -41,11 +38,7 @@ import androidx.compose.material3.Scaffold
4138import androidx.compose.material3.Text
4239import androidx.compose.material3.TopAppBar
4340import androidx.compose.runtime.Composable
44- import androidx.compose.runtime.mutableStateOf
45- import androidx.compose.runtime.saveable.rememberSaveable
46- import androidx.compose.ui.Alignment
4741import androidx.compose.ui.Modifier
48- import androidx.compose.ui.graphics.asImageBitmap
4942import androidx.compose.ui.platform.LocalContext
5043import androidx.compose.ui.res.stringResource
5144import androidx.compose.ui.tooling.preview.Preview
@@ -63,13 +56,10 @@ import kotlin.math.min
6356@Composable
6457fun HomeScreen (
6558 cameraPermission : CameraPermissionState ,
66- currentDocument : DocumentUiModel ,
6759 navigation : Navigation ,
68- onStartNewScan : () -> Unit ,
6960 recentDocuments : List <RecentDocumentUiState >,
7061 onOpenPdf : (File ) -> Unit ,
7162) {
72- val showCloseDocDialog = rememberSaveable { mutableStateOf(false ) }
7363 Scaffold (
7464 topBar = {
7565 TopAppBar (
@@ -83,15 +73,9 @@ fun HomeScreen(
8373 BottomAppBar {
8474 Spacer (Modifier .weight(1f ))
8575 MainActionButton (
86- onClick = {
87- if (currentDocument.isEmpty()) {
88- onStartNewScan()
89- } else {
90- showCloseDocDialog.value = true
91- }
92- },
76+ onClick = navigation.toCameraScreen,
9377 icon = Icons .Default .PhotoCamera ,
94- text = stringResource(R .string.start_a_new_scan ),
78+ text = stringResource(R .string.scan_button ),
9579 modifier = Modifier
9680 .padding(12 .dp)
9781 .height(48 .dp),
@@ -109,22 +93,10 @@ fun HomeScreen(
10993 CameraPermissionRationale (cameraPermission)
11094 }
11195
112- if (! currentDocument.isEmpty()) {
113- SectionTitle (stringResource(R .string.current_document))
114- CurrentDocumentCard (currentDocument, navigation)
115- }
116-
11796 if (recentDocuments.isNotEmpty()) {
11897 SectionTitle (stringResource(R .string.last_saved_documents))
11998 RecentDocumentList (recentDocuments, onOpenPdf)
12099 }
121-
122- if (showCloseDocDialog.value) {
123- NewDocumentDialog (
124- onConfirm = onStartNewScan,
125- showCloseDocDialog,
126- stringResource(R .string.new_document))
127- }
128100 }
129101 }
130102}
@@ -149,38 +121,6 @@ private fun CameraPermissionRationale(cameraPermission: CameraPermissionState) {
149121 }
150122}
151123
152- @Composable
153- private fun CurrentDocumentCard (
154- currentDocument : DocumentUiModel ,
155- navigation : Navigation ,
156- ) {
157- Card (
158- modifier = Modifier
159- .fillMaxWidth()
160- .padding(horizontal = 12 .dp, vertical = 6 .dp)
161- ) {
162- Row (
163- verticalAlignment = Alignment .CenterVertically ,
164- modifier = Modifier .padding(12 .dp)
165- ) {
166- currentDocument.load(0 )?.let {
167- Image (
168- bitmap = it.asImageBitmap(),
169- contentDescription = null ,
170- modifier = Modifier
171- .height(100 .dp)
172- .padding(4 .dp)
173- )
174- }
175- Spacer (Modifier .width(12 .dp))
176- Column (Modifier .weight(1f )) {
177- Text (pageCountText(currentDocument.pageCount()))
178- }
179- MainActionButton (navigation.toDocumentScreen, stringResource(R .string.open))
180- }
181- }
182- }
183-
184124@Composable
185125private fun RecentDocumentList (
186126 recentDocuments : List <RecentDocumentUiState >,
@@ -222,9 +162,7 @@ fun HomeScreenPreviewOnFirstLaunch() {
222162 MyScanTheme {
223163 HomeScreen (
224164 cameraPermission = rememberCameraPermissionState(),
225- currentDocument = DocumentUiModel (listOf ()) { _ -> null },
226165 navigation = dummyNavigation(),
227- onStartNewScan = {},
228166 recentDocuments = listOf (),
229167 onOpenPdf = {},
230168 )
@@ -233,15 +171,11 @@ fun HomeScreenPreviewOnFirstLaunch() {
233171
234172@Preview
235173@Composable
236- fun HomeScreenPreviewWithCurrentDocument () {
174+ fun HomeScreenPreviewWithLastSavedFiles () {
237175 MyScanTheme {
238176 HomeScreen (
239177 cameraPermission = rememberCameraPermissionState(),
240- currentDocument = fakeDocument(
241- listOf (" gallica.bnf.fr-bpt6k5530456s-1.jpg" ),
242- LocalContext .current),
243178 navigation = dummyNavigation(),
244- onStartNewScan = {},
245179 recentDocuments = listOf (
246180 RecentDocumentUiState (File (" /path/my_file.pdf" ), 1755971180000 , 3 ),
247181 RecentDocumentUiState (File (" /path/scan2.pdf" ), 1755000500000 , 1 )
0 commit comments