diff --git a/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt b/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt index 3a6b8bf..0425de0 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt @@ -183,20 +183,24 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { }) } if (expanded && row.entry.imageId != null) { - val image = ImageView(context).apply { - adjustViewBounds = true - maxHeight = dp(240) - contentDescription = "Notification image" - setPadding(0, dp(4), 0, 0) - } - addView(image) val imageId = row.entry.imageId val appContext = requireContext().applicationContext + val contentsContainer = this Thread { EncryptedImageStore(appContext).read(imageId)?.let { bytes -> BitmapFactory.decodeByteArray(bytes, 0, bytes.size) }?.let { bitmap -> - activity?.runOnUiThread { if (image.isAttachedToWindow) image.setImageBitmap(bitmap) } + activity?.runOnUiThread { + if (contentsContainer.isAttachedToWindow) { + contentsContainer.addView(ImageView(contentsContainer.context).apply { + setImageBitmap(bitmap) + adjustViewBounds = true + maxHeight = dp(240) + contentDescription = "Notification image" + setPadding(0, dp(4), 0, 0) + }) + } + } } }.start() } diff --git a/app/src/main/java/se/ajpanton/notificationlog/data/EncryptedNotificationLogStore.kt b/app/src/main/java/se/ajpanton/notificationlog/data/EncryptedNotificationLogStore.kt index 63508f6..948fe07 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/data/EncryptedNotificationLogStore.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/data/EncryptedNotificationLogStore.kt @@ -147,20 +147,16 @@ class EncryptedNotificationLogStore(context: Context) { if (imageBytes <= limit) return chunkFiles().forEach { chunk -> if (imageBytes <= limit) return@forEach - val entries = readChunk(chunk) - var changed = false - val retained = entries.map { entry -> + readChunk(chunk).forEach { entry -> if (imageBytes > limit && entry.imageId != null) { val image = File(imageDirectory, "${entry.imageId}.bin") imageBytes -= image.length() + // Keep imageId and the original `[image]` text marker in the + // log. The viewer and HTML exporter use the marker whenever + // this retained file is no longer available. image.delete() - changed = true - entry.copy(imageId = null) - } else { - entry } } - if (changed) writeChunk(chunk, retained) } }