Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
d47b7344
Verified
Commit
d47b7344
authored
2 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Try to avoid re-composition with empty avatar if already cached
parent
bd84e729
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!278
Introduce LocalAvatarManager and use it to display avatars for thread items
Pipeline
#13336
passed
2 years ago
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/attachment/media/AvatarManager.kt
+18
-2
18 additions, 2 deletions
...arproject/briar/desktop/attachment/media/AvatarManager.kt
with
18 additions
and
2 deletions
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/attachment/media/AvatarManager.kt
+
18
−
2
View file @
d47b7344
...
...
@@ -20,6 +20,7 @@ package org.briarproject.briar.desktop.attachment.media
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.State
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.produceState
import
androidx.compose.ui.graphics.ImageBitmap
import
androidx.compose.ui.res.loadImageBitmap
...
...
@@ -31,6 +32,7 @@ import org.briarproject.briar.api.attachment.AttachmentHeader
import
org.briarproject.briar.api.attachment.AttachmentReader
import
org.briarproject.briar.api.identity.AuthorInfo
import
org.briarproject.briar.desktop.threading.BriarExecutors
import
org.briarproject.briar.desktop.threading.UiExecutor
import
org.briarproject.briar.desktop.ui.LocalAvatarManager
import
javax.inject.Inject
...
...
@@ -39,10 +41,15 @@ class AvatarManager @Inject constructor(
private
val
executors
:
BriarExecutors
,
)
{
// access only on Dispatchers.Swing
@UiExecutor
// access only on Dispatchers.Swing
// TODO we may want to monitor cache size and evict cache entries again
private
val
cache
=
HashMap
<
MessageId
,
ImageBitmap
>()
@UiExecutor
fun
getAvatarFromCache
(
attachmentHeader
:
AttachmentHeader
):
ImageBitmap
?
{
return
cache
[
attachmentHeader
.
messageId
]
}
suspend
fun
loadAvatar
(
attachmentHeader
:
AttachmentHeader
,
):
ImageBitmap
=
withContext
(
Dispatchers
.
Swing
)
{
...
...
@@ -51,8 +58,12 @@ class AvatarManager @Inject constructor(
executors
.
runOnDbThreadWithTransaction
(
true
)
{
txn
->
attachmentReader
.
getAttachment
(
txn
,
attachmentHeader
).
stream
.
use
{
inputStream
->
loadImageBitmap
(
inputStream
)
}.
also
{
txn
.
attach
{
cache
[
attachmentHeader
.
messageId
]
=
it
}
}
}
.
also
{
cache
[
attachmentHeader
.
messageId
]
=
it
}
}
}
}
...
...
@@ -68,6 +79,11 @@ fun AvatarProducer(authorInfo: AuthorInfo): State<ImageBitmap?>? {
null
}
else
{
val
avatarManager
=
checkNotNull
(
LocalAvatarManager
.
current
)
// if avatar is cached, return it directly to avoid recomposition with produceState
avatarManager
.
getAvatarFromCache
(
avatarHeader
)
?.
let
{
return
mutableStateOf
(
it
)
}
// avatar is not cached, so load it
produceState
<
ImageBitmap
?>(
null
,
avatarHeader
.
messageId
)
{
value
=
avatarManager
.
loadAvatar
(
avatarHeader
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment