Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.aboutLibrariesAndroid)
alias(libs.plugins.protobuf)
alias(libs.plugins.kotlin.serialization)
}

Expand Down Expand Up @@ -122,10 +121,8 @@ dependencies {
implementation(libs.androidx.camera.camera2)
implementation(libs.androidx.camera.lifecycle)
implementation(libs.androidx.camera.view)
implementation(libs.androidx.datastore)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.documentfile)
implementation(libs.protobuf.javalite)
implementation(libs.litert)
implementation(libs.litert.support)
implementation(libs.litert.metadata)
Expand Down Expand Up @@ -160,21 +157,6 @@ aboutLibraries {
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:4.32.0"
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
create("java") {
option("lite")
}
}
}
}
}

// See https://developer.android.com/build/configure-apk-splits
androidComponents {
onVariants { variant ->
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/org/fairscan/app/FairScanApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import androidx.lifecycle.viewmodel.CreationExtras
import org.fairscan.app.data.FileLogger
import org.fairscan.app.data.FileManager
import org.fairscan.app.data.LogRepository
import org.fairscan.app.data.recentDocumentsDataStore
import org.fairscan.app.domain.ImageSegmentationService
import org.fairscan.app.platform.AndroidImageLoader
import org.fairscan.app.platform.AndroidPdfWriter
import org.fairscan.app.ui.screens.camera.CameraViewModel
import org.fairscan.app.ui.screens.home.HomeViewModel
import org.fairscan.app.ui.screens.settings.SettingsRepository
import org.fairscan.app.ui.screens.settings.SettingsViewModel
import java.io.File
Expand Down Expand Up @@ -57,7 +55,6 @@ class AppContainer(context: Context) {
val logger = FileLogger(logRepository)
val imageSegmentationService = ImageSegmentationService(context, logger)
val imageLoader = AndroidImageLoader(context.contentResolver)
val recentDocumentsDataStore = context.recentDocumentsDataStore
val settingsRepository = SettingsRepository(context)

@Suppress("UNCHECKED_CAST")
Expand All @@ -69,7 +66,6 @@ class AppContainer(context: Context) {
}
}

val homeViewModelFactory = viewModelFactory { HomeViewModel(it, context) }
val cameraViewModelFactory = viewModelFactory { CameraViewModel(it) }
val settingsViewModelFactory = viewModelFactory { SettingsViewModel(it) }

Expand Down
23 changes: 5 additions & 18 deletions app/src/main/java/org/fairscan/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import org.fairscan.app.data.ImageRepository
import org.fairscan.app.ui.Navigation
import org.fairscan.app.ui.Screen
import org.fairscan.app.ui.components.rememberCameraPermissionState
import org.fairscan.app.ui.screens.document.DocumentScreen
import org.fairscan.app.ui.screens.LibrariesScreen
import org.fairscan.app.ui.screens.about.AboutEvent
import org.fairscan.app.ui.screens.about.AboutScreen
Expand All @@ -63,14 +62,12 @@ import org.fairscan.app.ui.screens.about.createEmailWithImageIntent
import org.fairscan.app.ui.screens.camera.CameraEvent
import org.fairscan.app.ui.screens.camera.CameraScreen
import org.fairscan.app.ui.screens.camera.CameraViewModel
import org.fairscan.app.ui.screens.document.DocumentScreen
import org.fairscan.app.ui.screens.export.ExportActions
import org.fairscan.app.ui.screens.export.ExportEvent
import org.fairscan.app.ui.screens.export.ExportResult
import org.fairscan.app.ui.screens.export.ExportScreenWrapper
import org.fairscan.app.ui.screens.export.ExportViewModel
import org.fairscan.app.ui.screens.home.HomeScreen
import org.fairscan.app.ui.screens.home.HomeViewModel
import org.fairscan.app.ui.screens.settings.ExportFormat
import org.fairscan.app.ui.screens.settings.SettingsScreen
import org.fairscan.app.ui.screens.settings.SettingsViewModel
import org.fairscan.app.ui.theme.FairScanTheme
Expand All @@ -97,7 +94,7 @@ class MainActivity : ComponentActivity() {
val imageRepository = sessionViewModel.imageRepository
val viewModel: MainViewModel by viewModels {
appContainer.viewModelFactory {
MainViewModel(imageRepository, launchMode)
MainViewModel(imageRepository)
}
}
val exportViewModel: ExportViewModel by viewModels {
Expand All @@ -110,7 +107,6 @@ class MainActivity : ComponentActivity() {
AboutViewModel(appContainer, imageRepository)
}
}
val homeViewModel: HomeViewModel by viewModels { appContainer.homeViewModelFactory }
val cameraViewModel: CameraViewModel by viewModels { appContainer.cameraViewModelFactory }

val settingsViewModel: SettingsViewModel
Expand Down Expand Up @@ -157,16 +153,8 @@ class MainActivity : ComponentActivity() {
}

when (currentScreen) {
is Screen.Main.Home -> {
val recentDocs by homeViewModel.recentDocuments.collectAsStateWithLifecycle()
HomeScreen(
cameraPermission = cameraPermission,
currentDocument = document,
navigation = navigation,
onClearScan = { viewModel.startNewDocument() },
recentDocuments = recentDocs,
onOpenPdf = { fileUri -> openUri(fileUri, ExportFormat.PDF.mimeType, logger) }
)
null -> {
// waiting to load pages to get an initial screen
}
is Screen.Main.Camera -> {
val pickMultiple = rememberLauncherForActivityResult(
Expand Down Expand Up @@ -216,7 +204,7 @@ class MainActivity : ComponentActivity() {
onCloseScan = {
exportViewModel.resetFilename()
viewModel.startNewDocument()
viewModel.navigateTo(Screen.Main.Home)
viewModel.navigateTo(Screen.Main.Camera)
}
)
}
Expand Down Expand Up @@ -468,7 +456,6 @@ class MainActivity : ComponentActivity() {
}

private fun navigation(viewModel: MainViewModel, launchMode: LaunchMode): Navigation = Navigation(
toHomeScreen = { viewModel.navigateTo(Screen.Main.Home) },
toCameraScreen = { viewModel.navigateTo(Screen.Main.Camera) },
toDocumentScreen = { viewModel.navigateTo(Screen.Main.Document()) },
toExportScreen = { viewModel.navigateTo(Screen.Main.Export) },
Expand Down
24 changes: 17 additions & 7 deletions app/src/main/java/org/fairscan/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,27 @@ import org.fairscan.imageprocessing.ColorMode
import kotlin.math.min

@OptIn(ExperimentalCoroutinesApi::class)
class MainViewModel(val imageRepository: ImageRepository, launchMode: LaunchMode): ViewModel() {
class MainViewModel(val imageRepository: ImageRepository): ViewModel() {

private val _navigationState = MutableStateFlow(NavigationState.initial(launchMode))
val currentScreen: StateFlow<Screen> = _navigationState.map { it.current }
.stateIn(viewModelScope, SharingStarted.Eagerly, _navigationState.value.current)
private val _navigationState = MutableStateFlow<NavigationState?>(null)
val currentScreen: StateFlow<Screen?> = _navigationState.map { it?.current }
.stateIn(viewModelScope, SharingStarted.Eagerly, null)

private val _pages = MutableStateFlow<List<ScanPage>>(emptyList())


init {
viewModelScope.launch {
_pages.value = imageRepository.pages()
val pages = imageRepository.pages()

_pages.value = pages

_navigationState.value =
if (pages.isEmpty()) {
NavigationState.initial()
} else {
NavigationState.initial().navigateTo(Screen.Main.Export)
}
}
}

Expand Down Expand Up @@ -110,11 +120,11 @@ class MainViewModel(val imageRepository: ImageRepository, launchMode: LaunchMode
}
_currentPageIndex.value = min(_pages.value.size - 1, destination.initialPage)
}
_navigationState.update { it.navigateTo(destination) }
_navigationState.update { it?.navigateTo(destination) }
}

fun navigateBack() {
_navigationState.update { stack -> stack.navigateBack() }
_navigationState.update { stack -> stack?.navigateBack() }
}

fun rotateCurrentPage(clockwise: Boolean) {
Expand Down
47 changes: 0 additions & 47 deletions app/src/main/java/org/fairscan/app/data/RecentDocuments.kt

This file was deleted.

17 changes: 3 additions & 14 deletions app/src/main/java/org/fairscan/app/ui/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
*/
package org.fairscan.app.ui

import org.fairscan.app.LaunchMode

sealed class Screen {
sealed class Main : Screen() {
object Home : Main()
object Camera : Main()
data class Document(val initialPage: Int = 0) : Main()
object Export : Main()
Expand All @@ -31,7 +28,6 @@ sealed class Screen {
}

data class Navigation(
val toHomeScreen: () -> Unit,
val toCameraScreen: () -> Unit,
val toDocumentScreen: () -> Unit,
val toExportScreen: () -> Unit,
Expand All @@ -41,18 +37,12 @@ data class Navigation(
val back: () -> Unit,
)

fun startScreenFor(mode: LaunchMode): Screen.Main =
when (mode) {
LaunchMode.NORMAL -> Screen.Main.Home
LaunchMode.EXTERNAL_SCAN_TO_PDF -> Screen.Main.Camera
}

@ConsistentCopyVisibility
data class NavigationState private constructor(val stack: List<Screen>, val root: Screen.Main) {

companion object {
fun initial(mode: LaunchMode): NavigationState {
val root = startScreenFor(mode)
fun initial(): NavigationState {
val root = Screen.Main.Camera
return NavigationState(listOf(root), root)
}
}
Expand All @@ -70,8 +60,7 @@ data class NavigationState private constructor(val stack: List<Screen>, val root
fun navigateBack(): NavigationState {
return when (current) {
root -> this // Back handled by system
is Screen.Main.Home -> this // Back handled by system
is Screen.Main.Camera -> copy(stack = listOf(Screen.Main.Home))
is Screen.Main.Camera -> this // Back handled by system
is Screen.Main.Document -> copy(stack = listOf(Screen.Main.Camera))
is Screen.Main.Export -> copy(stack = listOf(Screen.Main.Camera))
is Screen.Overlay -> copy(stack = stack.dropLast(1))
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/java/org/fairscan/app/ui/PreviewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package org.fairscan.app.ui

import android.content.Context
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import org.fairscan.app.domain.Jpeg
import org.fairscan.app.domain.PageViewKey
Expand All @@ -26,11 +25,7 @@ import org.fairscan.app.ui.state.PageThumbnail
import org.fairscan.imageprocessing.ColorMode

fun dummyNavigation(): Navigation {
return Navigation({}, {}, {}, {}, {}, {}, {}, {})
}

fun fakeDocument(): DocumentUiModel {
return DocumentUiModel(persistentListOf())
return Navigation({}, {}, {}, {}, {}, {}, {})
}

fun fakeDocument(pageIds: ImmutableList<String>, context: Context): DocumentUiModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ fun CameraScreen(
val isTorchEnabled by cameraViewModel.isTorchEnabled.collectAsStateWithLifecycle()
var torchReapplied by remember { mutableStateOf(false) }

BackHandler { navigation.back() }

val captureController = remember { CameraCaptureController() }
DisposableEffect(Unit) {
onDispose {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fun ExportScreenWrapper(
onOpen = pdfActions.open,
onCloseScan = {
if (!uiState.isSaving) {
if (uiState.hasSavedOrShared)
if (uiState.hasSavedOrShared || uiState.isResumedScan)
onCloseScan()
else
showConfirmationDialog.value = true
Expand All @@ -149,7 +149,7 @@ fun ExportScreenWrapper(
)

if (showConfirmationDialog.value) {
NewDocumentDialog(onCloseScan, showConfirmationDialog, stringResource(R.string.end_scan))
NewDocumentDialog(onCloseScan, showConfirmationDialog, stringResource(R.string.scan_button))
}
}

Expand Down Expand Up @@ -396,7 +396,7 @@ private fun MainActions(
}
ExportButton(
icon = Icons.Default.Done,
text = stringResource(R.string.end_scan),
text = stringResource(R.string.scan_button),
onClick = onCloseScan,
modifier = Modifier.fillMaxWidth(),
isPrimary = uiState.hasSavedOrShared,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class ExportUiState(
val savedBundle: SavedBundle? = null,
val hasShared: Boolean = false,
val error: ExportError? = null,
val isResumedScan: Boolean = false,
) {
val hasSavedOrShared get() = savedBundle != null || hasShared
}
Expand Down
Loading
Loading