bugfix
This commit is contained in:
@@ -108,10 +108,17 @@ class InternalPhotoStorage(private val context: Context) : PhotoStorage {
|
|||||||
val resolver = context.contentResolver
|
val resolver = context.contentResolver
|
||||||
|
|
||||||
// 1) Nur die Abmessungen ermitteln (inJustDecodeBounds), ohne Pixel zu laden.
|
// 1) Nur die Abmessungen ermitteln (inJustDecodeBounds), ohne Pixel zu laden.
|
||||||
|
//
|
||||||
|
// WICHTIG: BitmapFactory.decodeStream(...) liefert bei inJustDecodeBounds = true
|
||||||
|
// IMMER null zurück (es befüllt nur boundsOptions, gibt aber nie ein Bitmap zurück).
|
||||||
|
// Die Null-Prüfung muss sich deshalb auf den STREAM selbst beziehen, nicht auf das
|
||||||
|
// (stets null-wertige) Ergebnis von decodeStream() - sonst würde jeder Import-
|
||||||
|
// Versuch fälschlich als "Bild konnte nicht geöffnet werden" fehlschlagen, komplett
|
||||||
|
// unabhängig vom tatsächlichen Bild.
|
||||||
val boundsOptions = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
val boundsOptions = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||||
resolver.openInputStream(sourceUri)?.use { input ->
|
val boundsStream = resolver.openInputStream(sourceUri)
|
||||||
BitmapFactory.decodeStream(input, null, boundsOptions)
|
?: error("Bild konnte nicht geöffnet werden (Uri nicht mehr gültig?).")
|
||||||
} ?: error("Bild konnte nicht geöffnet werden (Uri nicht mehr gültig?).")
|
boundsStream.use { input -> BitmapFactory.decodeStream(input, null, boundsOptions) }
|
||||||
|
|
||||||
if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) {
|
if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) {
|
||||||
error("Bildabmessungen konnten nicht ermittelt werden - vermutlich kein unterstütztes Bildformat.")
|
error("Bildabmessungen konnten nicht ermittelt werden - vermutlich kein unterstütztes Bildformat.")
|
||||||
|
|||||||
+6
@@ -170,6 +170,12 @@ class DocumentationEditViewModel(
|
|||||||
repository.addPhoto(documentationId, uri)
|
repository.addPhoto(documentationId, uri)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
failureCount++
|
failureCount++
|
||||||
|
// Bewusst OHNE Uri/Dateipfad geloggt (Datenschutz-Vorgabe: keine Bild-Uris/
|
||||||
|
// Dateipfade in Logs) - die Exception-Nachricht selbst genügt zur Diagnose.
|
||||||
|
android.util.Log.w(
|
||||||
|
"DocumentationEdit",
|
||||||
|
"Fotoimport fehlgeschlagen: ${e::class.simpleName}: ${e.message}",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val refreshed = repository.getFullDocumentation(documentationId)
|
val refreshed = repository.getFullDocumentation(documentationId)
|
||||||
|
|||||||
Reference in New Issue
Block a user