Reorg: move view to subpackages in ui

This commit is contained in:
Pierre-Yves Nicolas
2025-11-18 18:37:43 +01:00
parent 90125aa7b8
commit 0c2854e31c
20 changed files with 96 additions and 58 deletions

View File

@@ -47,13 +47,15 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.fairscan.app.data.GeneratedPdf import org.fairscan.app.data.GeneratedPdf
import org.fairscan.app.ui.Navigation
import org.fairscan.app.ui.Screen
import org.fairscan.app.ui.theme.FairScanTheme import org.fairscan.app.ui.theme.FairScanTheme
import org.fairscan.app.view.AboutScreen import org.fairscan.app.ui.screens.AboutScreen
import org.fairscan.app.view.CameraScreen import org.fairscan.app.ui.screens.camera.CameraScreen
import org.fairscan.app.view.DocumentScreen import org.fairscan.app.ui.screens.DocumentScreen
import org.fairscan.app.view.ExportScreenWrapper import org.fairscan.app.ui.screens.ExportScreenWrapper
import org.fairscan.app.view.HomeScreen import org.fairscan.app.ui.screens.HomeScreen
import org.fairscan.app.view.LibrariesScreen import org.fairscan.app.ui.screens.LibrariesScreen
import org.opencv.android.OpenCVLoader import org.opencv.android.OpenCVLoader
private const val PDF_MIME_TYPE = "application/pdf" private const val PDF_MIME_TYPE = "application/pdf"

View File

@@ -47,9 +47,12 @@ import org.fairscan.app.domain.ImageSegmentationService
import org.fairscan.app.domain.detectDocumentQuad import org.fairscan.app.domain.detectDocumentQuad
import org.fairscan.app.domain.extractDocument import org.fairscan.app.domain.extractDocument
import org.fairscan.app.domain.scaledTo import org.fairscan.app.domain.scaledTo
import org.fairscan.app.ui.PdfGenerationUiState import org.fairscan.app.ui.NavigationState
import org.fairscan.app.ui.RecentDocumentUiState import org.fairscan.app.ui.state.PdfGenerationUiState
import org.fairscan.app.view.DocumentUiModel import org.fairscan.app.ui.state.RecentDocumentUiState
import org.fairscan.app.ui.Screen
import org.fairscan.app.ui.state.DocumentUiModel
import org.fairscan.app.ui.state.LiveAnalysisState
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.File import java.io.File

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.ui
sealed class Screen { sealed class Screen {
sealed class Main : Screen() { sealed class Main : Screen() {

View File

@@ -12,13 +12,13 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui
import android.content.Context import android.content.Context
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import org.fairscan.app.Navigation import org.fairscan.app.ui.state.DocumentUiModel
fun dummyNavigation(): Navigation { fun dummyNavigation(): Navigation {
return Navigation({}, {}, {}, {}, {}, {}, {}) return Navigation({}, {}, {}, {}, {}, {}, {})

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.components
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.components
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text import androidx.compose.material3.Text

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.components
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
@@ -49,6 +49,7 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import org.fairscan.app.THUMBNAIL_SIZE_DP import org.fairscan.app.THUMBNAIL_SIZE_DP
import org.fairscan.app.ui.state.DocumentUiModel
import sh.calvin.reorderable.ReorderableItem import sh.calvin.reorderable.ReorderableItem
import sh.calvin.reorderable.rememberReorderableLazyListState import sh.calvin.reorderable.rememberReorderableLazyListState

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.components
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.background import androidx.compose.foundation.background
@@ -80,7 +80,7 @@ fun MyScaffold(
@Composable @Composable
fun DocumentBar( fun DocumentBar(
pageListState: CommonPageListState, pageListState: CommonPageListState,
buttonBar: @Composable () -> Unit, buttonBar: @Composable () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
pageListButton: (@Composable () -> Unit)? = null, pageListButton: (@Composable () -> Unit)? = null,

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.components
import android.content.Context import android.content.Context
import android.text.format.DateFormat import android.text.format.DateFormat

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens
import android.content.Intent import android.content.Intent
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
@@ -64,6 +64,7 @@ import androidx.compose.ui.unit.dp
import androidx.core.net.toUri import androidx.core.net.toUri
import org.fairscan.app.BuildConfig import org.fairscan.app.BuildConfig
import org.fairscan.app.R import org.fairscan.app.R
import org.fairscan.app.ui.components.BackButton
import org.fairscan.app.ui.theme.FairScanTheme import org.fairscan.app.ui.theme.FairScanTheme
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
@@ -55,8 +55,16 @@ import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import net.engawapg.lib.zoomable.ZoomState import net.engawapg.lib.zoomable.ZoomState
import net.engawapg.lib.zoomable.zoomable import net.engawapg.lib.zoomable.zoomable
import org.fairscan.app.Navigation import org.fairscan.app.ui.Navigation
import org.fairscan.app.R import org.fairscan.app.R
import org.fairscan.app.ui.components.CommonPageListState
import org.fairscan.app.ui.components.ConfirmationDialog
import org.fairscan.app.ui.components.MainActionButton
import org.fairscan.app.ui.components.MyScaffold
import org.fairscan.app.ui.components.SecondaryActionButton
import org.fairscan.app.ui.dummyNavigation
import org.fairscan.app.ui.fakeDocument
import org.fairscan.app.ui.state.DocumentUiModel
import org.fairscan.app.ui.theme.FairScanTheme import org.fairscan.app.ui.theme.FairScanTheme
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@@ -112,7 +120,8 @@ fun DocumentScreen(
currentPageIndex, currentPageIndex,
{ showDeletePageDialog.value = true }, { showDeletePageDialog.value = true },
onRotateImage, onRotateImage,
modifier) modifier
)
if (showDeletePageDialog.value) { if (showDeletePageDialog.value) {
ConfirmationDialog( ConfirmationDialog(
title = stringResource(R.string.delete_page), title = stringResource(R.string.delete_page),
@@ -230,7 +239,8 @@ fun DocumentScreenPreview() {
DocumentScreen( DocumentScreen(
fakeDocument( fakeDocument(
listOf(1, 2).map { "gallica.bnf.fr-bpt6k5530456s-$it.jpg" }.toImmutableList(), listOf(1, 2).map { "gallica.bnf.fr-bpt6k5530456s-$it.jpg" }.toImmutableList(),
LocalContext.current), LocalContext.current
),
initialPage = 1, initialPage = 1,
navigation = dummyNavigation(), navigation = dummyNavigation(),
onDeleteImage = { _ -> }, onDeleteImage = { _ -> },

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens
import android.content.Context import android.content.Context
import android.text.format.Formatter import android.text.format.Formatter
@@ -67,10 +67,17 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.net.toUri import androidx.core.net.toUri
import org.fairscan.app.data.GeneratedPdf import org.fairscan.app.data.GeneratedPdf
import org.fairscan.app.Navigation import org.fairscan.app.ui.Navigation
import org.fairscan.app.PdfGenerationActions import org.fairscan.app.PdfGenerationActions
import org.fairscan.app.R import org.fairscan.app.R
import org.fairscan.app.ui.PdfGenerationUiState import org.fairscan.app.ui.state.PdfGenerationUiState
import org.fairscan.app.ui.components.AboutScreenNavButton
import org.fairscan.app.ui.components.BackButton
import org.fairscan.app.ui.components.MainActionButton
import org.fairscan.app.ui.components.NewDocumentDialog
import org.fairscan.app.ui.components.isLandscape
import org.fairscan.app.ui.components.pageCountText
import org.fairscan.app.ui.dummyNavigation
import org.fairscan.app.ui.theme.FairScanTheme import org.fairscan.app.ui.theme.FairScanTheme
import java.io.File import java.io.File
import java.text.SimpleDateFormat import java.text.SimpleDateFormat

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@@ -56,10 +56,16 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import org.fairscan.app.CameraPermissionState import org.fairscan.app.CameraPermissionState
import org.fairscan.app.Navigation import org.fairscan.app.ui.Navigation
import org.fairscan.app.R import org.fairscan.app.R
import org.fairscan.app.rememberCameraPermissionState import org.fairscan.app.rememberCameraPermissionState
import org.fairscan.app.ui.RecentDocumentUiState import org.fairscan.app.ui.state.RecentDocumentUiState
import org.fairscan.app.ui.components.AboutScreenNavButton
import org.fairscan.app.ui.components.formatDate
import org.fairscan.app.ui.components.pageCountText
import org.fairscan.app.ui.dummyNavigation
import org.fairscan.app.ui.fakeDocument
import org.fairscan.app.ui.state.DocumentUiModel
import org.fairscan.app.ui.theme.FairScanTheme import org.fairscan.app.ui.theme.FairScanTheme
import java.io.File import java.io.File
@@ -286,7 +292,8 @@ fun HomeScreenPreviewWithCurrentDocument() {
cameraPermission = rememberCameraPermissionState(), cameraPermission = rememberCameraPermissionState(),
currentDocument = fakeDocument( currentDocument = fakeDocument(
persistentListOf("gallica.bnf.fr-bpt6k5530456s-1.jpg"), persistentListOf("gallica.bnf.fr-bpt6k5530456s-1.jpg"),
LocalContext.current), LocalContext.current
),
navigation = dummyNavigation(), navigation = dummyNavigation(),
onClearScan = {}, onClearScan = {},
recentDocuments = listOf(), recentDocuments = listOf(),

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -31,6 +31,7 @@ import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults
import com.mikepenz.aboutlibraries.ui.compose.android.rememberLibraries import com.mikepenz.aboutlibraries.ui.compose.android.rememberLibraries
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import org.fairscan.app.R import org.fairscan.app.R
import org.fairscan.app.ui.components.BackButton
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens.camera
import android.graphics.Bitmap import android.graphics.Bitmap
import android.util.Log import android.util.Log
@@ -54,7 +54,7 @@ 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.fairscan.app.CameraPermissionState import org.fairscan.app.CameraPermissionState
import org.fairscan.app.LiveAnalysisState import org.fairscan.app.ui.state.LiveAnalysisState
import org.fairscan.app.domain.Point import org.fairscan.app.domain.Point
import org.fairscan.app.domain.scaledTo import org.fairscan.app.domain.scaledTo
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.screens.camera
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
@@ -83,12 +83,18 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import org.fairscan.app.CameraPermissionState import org.fairscan.app.CameraPermissionState
import org.fairscan.app.LiveAnalysisState import org.fairscan.app.ui.state.LiveAnalysisState
import org.fairscan.app.MainViewModel import org.fairscan.app.MainViewModel
import org.fairscan.app.MainViewModel.CaptureState import org.fairscan.app.MainViewModel.CaptureState
import org.fairscan.app.Navigation import org.fairscan.app.ui.Navigation
import org.fairscan.app.R import org.fairscan.app.R
import org.fairscan.app.Screen import org.fairscan.app.ui.Screen
import org.fairscan.app.ui.components.CommonPageListState
import org.fairscan.app.ui.components.MainActionButton
import org.fairscan.app.ui.components.MyScaffold
import org.fairscan.app.ui.components.pageCountText
import org.fairscan.app.ui.dummyNavigation
import org.fairscan.app.ui.fakeDocument
import org.fairscan.app.ui.theme.FairScanTheme import org.fairscan.app.ui.theme.FairScanTheme
data class CameraUiState( data class CameraUiState(
@@ -230,14 +236,14 @@ private fun CameraScreenScaffold(
pageListState = pageListState, pageListState = pageListState,
onBack = navigation.back, onBack = navigation.back,
bottomBar = { Bar(cameraUiState.pageCount, onFinalizePressed) } bottomBar = { Bar(cameraUiState.pageCount, onFinalizePressed) }
) { ) { modifier ->
modifier -> CameraPreviewBox(
CameraPreviewBox( cameraPreview,
cameraPreview, cameraUiState,
cameraUiState, onCapture,
onCapture, onTorchSwitched,
onTorchSwitched, modifier.clickable(onClick = onPageCountClick)
modifier.clickable(onClick = onPageCountClick)) )
} }
if (cameraUiState.captureState is CaptureState.CapturePreview) { if (cameraUiState.captureState is CaptureState.CapturePreview) {
CapturedImage(cameraUiState.captureState.processed.asImageBitmap(), thumbnailCoords) CapturedImage(cameraUiState.captureState.processed.asImageBitmap(), thumbnailCoords)
@@ -502,7 +508,7 @@ private fun ScreenPreview(captureState: CaptureState, rotationDegrees: Float = 0
.toImmutableList(), .toImmutableList(),
LocalContext.current), LocalContext.current),
onPageClick = {}, onPageClick = {},
onPageReorder = { _,_ -> }, onPageReorder = { _, _ -> },
listState = LazyListState(), listState = LazyListState(),
), ),
cameraUiState = CameraUiState(pageCount = 4, LiveAnalysisState(), captureState, cameraUiState = CameraUiState(pageCount = 4, LiveAnalysisState(), captureState,

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.view package org.fairscan.app.ui.state
import android.graphics.Bitmap import android.graphics.Bitmap
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.ui.state
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.ui package org.fairscan.app.ui.state
import android.net.Uri import android.net.Uri
import org.fairscan.app.data.GeneratedPdf import org.fairscan.app.data.GeneratedPdf

View File

@@ -12,15 +12,15 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.ui
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.fairscan.app.Screen.Main.Camera import org.fairscan.app.ui.Screen.Main.Camera
import org.fairscan.app.Screen.Main.Document import org.fairscan.app.ui.Screen.Main.Document
import org.fairscan.app.Screen.Main.Export import org.fairscan.app.ui.Screen.Main.Export
import org.fairscan.app.Screen.Main.Home import org.fairscan.app.ui.Screen.Main.Home
import org.fairscan.app.Screen.Overlay.About import org.fairscan.app.ui.Screen.Overlay.About
import org.fairscan.app.Screen.Overlay.Libraries import org.fairscan.app.ui.Screen.Overlay.Libraries
import org.junit.Test import org.junit.Test
class NavigationTest { class NavigationTest {