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) {
|
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 imageId = row.entry.imageId
|
||||||
val appContext = requireContext().applicationContext
|
val appContext = requireContext().applicationContext
|
||||||
|
val contentsContainer = this
|
||||||
Thread {
|
Thread {
|
||||||
EncryptedImageStore(appContext).read(imageId)?.let { bytes ->
|
EncryptedImageStore(appContext).read(imageId)?.let { bytes ->
|
||||||
BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
||||||
}?.let { bitmap ->
|
}?.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()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,20 +147,16 @@ class EncryptedNotificationLogStore(context: Context) {
|
|||||||
if (imageBytes <= limit) return
|
if (imageBytes <= limit) return
|
||||||
chunkFiles().forEach { chunk ->
|
chunkFiles().forEach { chunk ->
|
||||||
if (imageBytes <= limit) return@forEach
|
if (imageBytes <= limit) return@forEach
|
||||||
val entries = readChunk(chunk)
|
readChunk(chunk).forEach { entry ->
|
||||||
var changed = false
|
|
||||||
val retained = entries.map { entry ->
|
|
||||||
if (imageBytes > limit && entry.imageId != null) {
|
if (imageBytes > limit && entry.imageId != null) {
|
||||||
val image = File(imageDirectory, "${entry.imageId}.bin")
|
val image = File(imageDirectory, "${entry.imageId}.bin")
|
||||||
imageBytes -= image.length()
|
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()
|
image.delete()
|
||||||
changed = true
|
|
||||||
entry.copy(imageId = null)
|
|
||||||
} else {
|
|
||||||
entry
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed) writeChunk(chunk, retained)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user