summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorSteve Elliott <steell@google.com>2022-02-16 17:26:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-02-16 17:26:15 +0000
commitba790ec0e9079761f411a822d937dcf13ead4f32 (patch)
treef599c9ef6aedf0db27ee0b61f6c00264fd763661 /core/java
parenta44a2100e1d90ff3d529ae774f2c702853b251b9 (diff)
parent2a68270c76def0b635bd1583e9c1817d09dff969 (diff)
Merge "Defer MessagingGroup#recycle until bind completes"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/com/android/internal/widget/ConversationLayout.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/core/java/com/android/internal/widget/ConversationLayout.java b/core/java/com/android/internal/widget/ConversationLayout.java
index 78bb53d33539..5fa4a652e176 100644
--- a/core/java/com/android/internal/widget/ConversationLayout.java
+++ b/core/java/com/android/internal/widget/ConversationLayout.java
@@ -150,6 +150,7 @@ public class ConversationLayout extends FrameLayout
private Icon mShortcutIcon;
private View mAppNameDivider;
private TouchDelegateComposite mTouchDelegate = new TouchDelegateComposite(this);
+ private ArrayList<MessagingGroup> mToRecycle = new ArrayList<>();
public ConversationLayout(@NonNull Context context) {
super(context);
@@ -472,6 +473,12 @@ public class ConversationLayout extends FrameLayout
updateTitleAndNamesDisplay();
updateConversationLayout();
+
+ // Recycle everything at the end of the update, now that we know it's no longer needed.
+ for (MessagingGroup group : mToRecycle) {
+ group.recycle();
+ }
+ mToRecycle.clear();
}
/**
@@ -745,18 +752,18 @@ public class ConversationLayout extends FrameLayout
MessagingGroup group = oldGroups.get(i);
if (!mGroups.contains(group)) {
List<MessagingMessage> messages = group.getMessages();
- Runnable endRunnable = () -> {
- mMessagingLinearLayout.removeTransientView(group);
- group.recycle();
- };
-
boolean wasShown = group.isShown();
mMessagingLinearLayout.removeView(group);
if (wasShown && !MessagingLinearLayout.isGone(group)) {
mMessagingLinearLayout.addTransientView(group, 0);
- group.removeGroupAnimated(endRunnable);
+ group.removeGroupAnimated(() -> {
+ mMessagingLinearLayout.removeTransientView(group);
+ group.recycle();
+ });
} else {
- endRunnable.run();
+ // Defer recycling until after the update is done, since we may still need the
+ // old group around to perform other updates.
+ mToRecycle.add(group);
}
mMessages.removeAll(messages);
mHistoricMessages.removeAll(messages);