Reorg: move ImageRepository and PdfFileManager to data

This commit is contained in:
Pierre-Yves Nicolas
2025-11-18 17:29:37 +01:00
parent 8f9d51e65a
commit 90125aa7b8
9 changed files with 21 additions and 15 deletions

View File

@@ -46,6 +46,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import org.fairscan.app.data.GeneratedPdf
import org.fairscan.app.ui.theme.FairScanTheme
import org.fairscan.app.view.AboutScreen
import org.fairscan.app.view.CameraScreen

View File

@@ -39,6 +39,9 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.fairscan.app.data.GeneratedPdf
import org.fairscan.app.data.ImageRepository
import org.fairscan.app.data.PdfFileManager
import org.fairscan.app.data.recentDocumentsDataStore
import org.fairscan.app.domain.ImageSegmentationService
import org.fairscan.app.domain.detectDocumentQuad
@@ -71,7 +74,8 @@ class MainViewModel(
PdfFileManager(
File(context.cacheDir, "pdfs"),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
AndroidPdfWriter()),
AndroidPdfWriter()
),
context.recentDocumentsDataStore,
) as T
}
@@ -385,12 +389,6 @@ class MainViewModel(
}
}
data class GeneratedPdf(
val file: File,
val sizeInBytes: Long,
val pageCount: Int,
)
// TODO Move somewhere else: ViewModel should not depend on that
data class PdfGenerationActions(
val startGeneration: () -> Unit,

View File

@@ -20,6 +20,7 @@ import com.tom_roush.pdfbox.pdmodel.PDPageContentStream
import com.tom_roush.pdfbox.pdmodel.PDPageContentStream.AppendMode
import com.tom_roush.pdfbox.pdmodel.common.PDRectangle
import com.tom_roush.pdfbox.pdmodel.graphics.image.JPEGFactory
import org.fairscan.app.data.PdfWriter
import java.io.OutputStream
class AndroidPdfWriter : PdfWriter {

View File

@@ -12,13 +12,12 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.fairscan.app
package org.fairscan.app.data
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.serialization.json.Json
import org.fairscan.app.data.DocumentMetadata
import org.fairscan.app.data.Page
import org.fairscan.app.ImageTransformations
import java.io.File
const val SCAN_DIR_NAME = "scanned_pages"

View File

@@ -12,12 +12,18 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.fairscan.app
package org.fairscan.app.data
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
data class GeneratedPdf(
val file: File,
val sizeInBytes: Long,
val pageCount: Int,
)
fun interface PdfWriter {
fun writePdfFromJpegs(jpegs: Sequence<ByteArray>, outputStream: OutputStream): Int
}

View File

@@ -15,7 +15,7 @@
package org.fairscan.app.ui
import android.net.Uri
import org.fairscan.app.GeneratedPdf
import org.fairscan.app.data.GeneratedPdf
import java.io.File
data class PdfGenerationUiState(

View File

@@ -66,7 +66,7 @@ import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.net.toUri
import org.fairscan.app.GeneratedPdf
import org.fairscan.app.data.GeneratedPdf
import org.fairscan.app.Navigation
import org.fairscan.app.PdfGenerationActions
import org.fairscan.app.R

View File

@@ -12,9 +12,10 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.fairscan.app
package org.fairscan.app.data
import org.assertj.core.api.Assertions.assertThat
import org.fairscan.app.ImageTransformations
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.fairscan.app
package org.fairscan.app.data
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test