Add ImageWrite to write images, move to images namespace
This commit is contained in:
@@ -38,6 +38,8 @@ import app.klottr.create.QueueOutboxOutcome
|
||||
import app.klottr.create.createNoteFlow
|
||||
import app.klottr.create.queueNoteDocOutbox
|
||||
import app.klottr.events.FoundEvents
|
||||
import app.klottr.images.ImageWriter
|
||||
import app.klottr.images.ImageReader
|
||||
import app.klottr.location.LastLocationStore
|
||||
import app.klottr.location.LocationServiceProvider
|
||||
import app.klottr.nearby.FoundOpenAction
|
||||
@@ -55,8 +57,6 @@ import app.klottr.net.DigitaltMuseum
|
||||
import app.klottr.net.DigitaltMuseumItem
|
||||
import app.klottr.net.FornsokShared
|
||||
import app.klottr.net.Geocache
|
||||
import app.klottr.net.ImageHandle
|
||||
import app.klottr.net.ImageReader
|
||||
import app.klottr.net.Wikipedia
|
||||
import app.klottr.net.createNoteDoc
|
||||
import app.klottr.net.fetchImageStreamPost
|
||||
@@ -695,7 +695,7 @@ fun KlottrAppShell(
|
||||
hasImage = draft.image != null,
|
||||
uploadImage = {
|
||||
// Plattformoberoende läsning via shared ImageReader
|
||||
val read = ImageReader.read(draft.image!!)
|
||||
val read = app.klottr.images.ImageReader.read(draft.image!!)
|
||||
?: run {
|
||||
Api.lastUploadError = "Kunde inte läsa bilddata."
|
||||
return@createNoteFlow null
|
||||
@@ -793,21 +793,13 @@ fun KlottrAppShell(
|
||||
hasImage = (img != null), // Använd snapshotten
|
||||
persistImageIfAny = {
|
||||
val handle = img ?: return@queueNoteDocOutbox null
|
||||
val read = ImageReader.read(handle) ?: return@queueNoteDocOutbox null
|
||||
val mime = read.mime
|
||||
val ext = when {
|
||||
mime.equals("image/jpeg", true) || mime.equals("image/jpg", true) -> ".jpg"
|
||||
mime.equals("image/png", true) -> ".png"
|
||||
mime.equals("image/webp", true) -> ".webp"
|
||||
mime.equals("image/gif", true) -> ".gif"
|
||||
else -> ".img"
|
||||
}
|
||||
val outDir = File(context.filesDir, "outbox").apply { mkdirs() }
|
||||
val outFile = File(outDir, "img_${created}$ext")
|
||||
try {
|
||||
outFile.outputStream().use { outs -> outs.write(read.bytes) }
|
||||
outFile.absolutePath to mime
|
||||
} catch (_: Exception) { null }
|
||||
val read = app.klottr.images.ImageReader.read(handle) ?: return@queueNoteDocOutbox null
|
||||
val saved = ImageWriter.save(
|
||||
read = read,
|
||||
subdir = "outbox",
|
||||
baseName = "img_${created}"
|
||||
) ?: return@queueNoteDocOutbox null
|
||||
saved.absolutePath to saved.mime
|
||||
},
|
||||
addOutboxDoc = { la, lo, t, b, ts, rad, imagePath, imageMime ->
|
||||
OutboxStore.addDoc(
|
||||
@@ -866,20 +858,12 @@ fun KlottrAppShell(
|
||||
persistImageIfAny = {
|
||||
val handle = img ?: return@queueNoteDocOutbox null
|
||||
val read = ImageReader.read(handle) ?: return@queueNoteDocOutbox null
|
||||
val mime = read.mime
|
||||
val ext = when {
|
||||
mime.equals("image/jpeg", true) || mime.equals("image/jpg", true) -> ".jpg"
|
||||
mime.equals("image/png", true) -> ".png"
|
||||
mime.equals("image/webp", true) -> ".webp"
|
||||
mime.equals("image/gif", true) -> ".gif"
|
||||
else -> ".img"
|
||||
}
|
||||
val outDir = File(context.filesDir, "outbox").apply { mkdirs() }
|
||||
val outFile = File(outDir, "img_${created}$ext")
|
||||
try {
|
||||
outFile.outputStream().use { outs -> outs.write(read.bytes) }
|
||||
outFile.absolutePath to mime
|
||||
} catch (_: Exception) { null }
|
||||
val saved = ImageWriter.save(
|
||||
read = read,
|
||||
subdir = "outbox",
|
||||
baseName = "img_${created}"
|
||||
) ?: return@queueNoteDocOutbox null
|
||||
saved.absolutePath to saved.mime
|
||||
},
|
||||
addOutboxDoc = { la, lo, t, b, ts, rad, imagePath, imageMime ->
|
||||
OutboxStore.addDoc(
|
||||
|
||||
@@ -19,10 +19,11 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import app.klottr.db.DatabaseFactory
|
||||
import app.klottr.db.KlottrDatabase
|
||||
import app.klottr.net.ImageReader
|
||||
import app.klottr.shared.SharedPing
|
||||
import app.klottr.theme.KlottrTheme
|
||||
import app.klottr.auth.AuthPlatform
|
||||
import app.klottr.images.ImageReader
|
||||
import app.klottr.images.ImageWriter
|
||||
import app.klottr.util.AuthShared
|
||||
import app.klottr.util.PlatformAuthStorage
|
||||
import app.klottr.util.AuthStorageDelegate
|
||||
@@ -120,7 +121,7 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
// Säkerställ att delad ImageReader har appContext på Android
|
||||
ImageReader.init(applicationContext)
|
||||
|
||||
ImageWriter.init(applicationContext)
|
||||
|
||||
KlottrTheme(darkTheme = night) {
|
||||
KlottrAppShell(
|
||||
|
||||
Reference in New Issue
Block a user