forked from mirror/monocles_chat
Only get avatar from cache for sidebar
And fetch in background if needed (cherry picked from commit 40acf58dfa08bd392988e62ef41d9517801a1013)
This commit is contained in:
parent
652fac3003
commit
20f89d3de5
3 changed files with 28 additions and 5 deletions
|
@ -95,6 +95,7 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -116,6 +117,7 @@ import eu.siacs.conversations.ui.interfaces.OnConversationRead;
|
|||
import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
|
||||
import eu.siacs.conversations.ui.interfaces.OnConversationsListItemUpdated;
|
||||
import eu.siacs.conversations.ui.util.ActivityResult;
|
||||
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
||||
import eu.siacs.conversations.ui.util.ConversationMenuConfigurator;
|
||||
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
||||
import eu.siacs.conversations.ui.util.PendingItem;
|
||||
|
@ -250,7 +252,13 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
|||
|
||||
long id = 101;
|
||||
for (final var a : accounts) {
|
||||
final var avatar = xmppConnectionService.getAvatarService().get(a, (int) getResources().getDimension(R.dimen.avatar_on_drawer), false);
|
||||
final var size = (int) getResources().getDimension(R.dimen.avatar_on_drawer);
|
||||
final var avatar = xmppConnectionService.getAvatarService().get(a, size, true);
|
||||
if (avatar == null) {
|
||||
final var task = new AvatarWorkerTask(this, R.dimen.avatar_on_drawer);
|
||||
try { task.execute(a); } catch (final RejectedExecutionException ignored) { }
|
||||
refreshAccounts = true;
|
||||
}
|
||||
final var p = new com.mikepenz.materialdrawer.model.ProfileDrawerItem();
|
||||
p.setIdentifier(id++);
|
||||
p.setTag(a);
|
||||
|
|
|
@ -219,7 +219,7 @@ public abstract class XmppActivity extends ActionBarActivity {
|
|||
mToast.show();
|
||||
}
|
||||
|
||||
protected final void refreshUi() {
|
||||
public final void refreshUi() {
|
||||
final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh;
|
||||
if (diff > Config.REFRESH_UI_INTERVAL) {
|
||||
mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
|
||||
|
|
|
@ -22,19 +22,28 @@ import eu.siacs.conversations.ui.XmppActivity;
|
|||
|
||||
public class AvatarWorkerTask extends AsyncTask<AvatarService.Avatarable, Void, Drawable> {
|
||||
private final WeakReference<ImageView> imageViewReference;
|
||||
private final WeakReference<XmppActivity> activityReference;
|
||||
private AvatarService.Avatarable avatarable = null;
|
||||
private @DimenRes
|
||||
final int size;
|
||||
|
||||
public AvatarWorkerTask(ImageView imageView, @DimenRes int size) {
|
||||
imageViewReference = new WeakReference<>(imageView);
|
||||
activityReference = null;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
||||
public AvatarWorkerTask(XmppActivity activity, @DimenRes int size) {
|
||||
activityReference = new WeakReference<>(activity);
|
||||
imageViewReference = new WeakReference<>(null);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Drawable doInBackground(AvatarService.Avatarable... params) {
|
||||
this.avatarable = params[0];
|
||||
final XmppActivity activity = XmppActivity.find(imageViewReference);
|
||||
final XmppActivity activity = activityReference == null ? XmppActivity.find(imageViewReference) : activityReference.get();
|
||||
if (activity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -48,8 +57,14 @@ public class AvatarWorkerTask extends AsyncTask<AvatarService.Avatarable, Void,
|
|||
if (imageView != null) {
|
||||
imageView.setImageDrawable(bitmap);
|
||||
imageView.setBackgroundColor(0x00000000);
|
||||
if (Build.VERSION.SDK_INT >= 28 && bitmap instanceof AnimatedImageDrawable) {
|
||||
((AnimatedImageDrawable) bitmap).start();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 28 && bitmap instanceof AnimatedImageDrawable) {
|
||||
((AnimatedImageDrawable) bitmap).start();
|
||||
}
|
||||
if (activityReference != null) {
|
||||
final var activity = activityReference.get();
|
||||
if (activity != null) {
|
||||
activity.refreshUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue