Keep image markers after retention trimming
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user