Skip to content

Commit

Permalink
Store updated avatar in the bitmap cache
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGrzybkowski committed Nov 13, 2024
1 parent a2a35ed commit c704bda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,10 @@ class MeFragment : Fragment(R.layout.me_fragment), OnScrollToTopListener {

private fun MeFragmentBinding.loadAvatar(injectFilePath: String?, forceRefresh: Boolean = false) {
val newAvatarUploaded = !injectFilePath.isNullOrEmpty()
val avatarUrl = meGravatarLoader.constructGravatarUrl(accountStore.account.avatarUrl, forceRefresh)
val avatarUrl = meGravatarLoader.constructGravatarUrl(accountStore.account.avatarUrl)
val newAvatarSelected = newAvatarUploaded || forceRefresh
meGravatarLoader.load(
newAvatarUploaded,
newAvatarSelected,
avatarUrl,
injectFilePath,
meAvatar,
Expand Down Expand Up @@ -531,7 +532,7 @@ class MeFragment : Fragment(R.layout.me_fragment), OnScrollToTopListener {
resource: Drawable,
model: Any?
) {
if (newAvatarUploaded && resource is BitmapDrawable) {
if (newAvatarSelected && resource is BitmapDrawable) {
var bitmap = resource.bitmap
// create a copy since the original bitmap may by automatically recycled
bitmap = bitmap.copy(bitmap.config, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class MeGravatarLoader @Inject constructor(
private val resourseProvider: ResourceProvider
) {
fun load(
newAvatarUploaded: Boolean,
newAvatarSelected: Boolean,
avatarUrl: String,
injectFilePath: String?,
imageView: ImageView,
imageType: ImageType,
listener: RequestListener<Drawable>? = null
) {
if (newAvatarUploaded) {
if (newAvatarSelected) {
// invalidate the specific gravatar entry from the bitmap cache. It will be updated via the injected
// request cache.
WordPress.getBitmapCache().removeSimilar(avatarUrl)
Expand All @@ -45,10 +45,12 @@ class MeGravatarLoader @Inject constructor(
imageManager.loadIntoCircle(
imageView,
imageType,
if (newAvatarUploaded && injectFilePath != null) {
if (newAvatarSelected && injectFilePath != null) {
injectFilePath
} else {
avatarUrl
// If new avatar selected we force refresh the avatar
val constructGravatarUrl = constructGravatarUrl(avatarUrl, newAvatarSelected)
constructGravatarUrl
},
listener,
appPrefsWrapper.avatarVersion
Expand Down

0 comments on commit c704bda

Please sign in to comment.