From 8a9733fc8d5b28b548363dde908eb342a2e62939 Mon Sep 17 00:00:00 2001 From: Ibrahim Yilmaz Date: Wed, 9 Aug 2023 14:32:42 +0000 Subject: [PATCH] Decouple MessagingMessage View creation from view binding in Messaging Layouts MessagingLayout and ConversationLayout bindings create MessagingMessage for historic and normal messages. This CL decouples these logics to create Precomputed Text version of MessagingMessage. Bug: 289250881 Test: Manual. Post Messaging and Conversation notifications with and without this. No change is expected. Change-Id: Id09362b9a2263653ea3e145f20369ba017a63924 --- .../internal/widget/ConversationLayout.java | 36 +++++++++++-------- .../internal/widget/MessagingLayout.java | 24 ++++++++----- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/core/java/com/android/internal/widget/ConversationLayout.java b/core/java/com/android/internal/widget/ConversationLayout.java index 117c670a21979..7dda91d7b25e2 100644 --- a/core/java/com/android/internal/widget/ConversationLayout.java +++ b/core/java/com/android/internal/widget/ConversationLayout.java @@ -397,8 +397,7 @@ public class ConversationLayout extends FrameLayout = Notification.MessagingStyle.Message.getMessagesFromBundleArray(histMessages); // mUser now set (would be nice to avoid the side effect but WHATEVER) - setUser(extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON, android.app.Person.class)); - + final Person user = extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON, Person.class); // Append remote input history to newMessages (again, side effect is lame but WHATEVS) RemoteInputHistoryItem[] history = (RemoteInputHistoryItem[]) extras.getParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS, android.app.RemoteInputHistoryItem.class); @@ -406,11 +405,18 @@ public class ConversationLayout extends FrameLayout boolean showSpinner = extras.getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false); - // bind it, baby - bind(newMessages, newHistoricMessages, showSpinner); - int unreadCount = extras.getInt(Notification.EXTRA_CONVERSATION_UNREAD_MESSAGE_COUNT); - setUnreadCount(unreadCount); + + // convert MessagingStyle.Message to MessagingMessage, re-using ones from a previous binding + // if they exist + final List newMessagingMessages = + createMessages(newMessages, false /* isHistoric */); + final List newHistoricMessagingMessages = + createMessages(newHistoricMessages, true /* isHistoric */); + // bind it, baby + bindViews(user, showSpinner, unreadCount, + newMessagingMessages, + newHistoricMessagingMessages); } /** @@ -452,15 +458,17 @@ public class ConversationLayout extends FrameLayout } } - private void bind(List newMessages, - List newHistoricMessages, - boolean showSpinner) { - // convert MessagingStyle.Message to MessagingMessage, re-using ones from a previous binding - // if they exist - List historicMessages = createMessages(newHistoricMessages, - true /* isHistoric */); - List messages = createMessages(newMessages, false /* isHistoric */); + private void bindViews(Person user, + boolean showSpinner, int unreadCount, List newMessagingMessages, + List newHistoricMessagingMessages) { + setUser(user); + setUnreadCount(unreadCount); + bind(showSpinner, newMessagingMessages, newHistoricMessagingMessages); + } + + private void bind(boolean showSpinner, List messages, + List historicMessages) { // Copy our groups, before they get clobbered ArrayList oldGroups = new ArrayList<>(mGroups); diff --git a/core/java/com/android/internal/widget/MessagingLayout.java b/core/java/com/android/internal/widget/MessagingLayout.java index f187d5c8625c9..8345c5cc9ef9d 100644 --- a/core/java/com/android/internal/widget/MessagingLayout.java +++ b/core/java/com/android/internal/widget/MessagingLayout.java @@ -172,9 +172,16 @@ public class MessagingLayout extends FrameLayout RemoteInputHistoryItem[] history = (RemoteInputHistoryItem[]) extras.getParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS, android.app.RemoteInputHistoryItem.class); addRemoteInputHistoryToMessages(newMessages, history); + + final Person user = extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON, Person.class); boolean showSpinner = extras.getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false); - bind(newMessages, newHistoricMessages, showSpinner); + + final List historicMessagingMessages = createMessages(newHistoricMessages, + true /* isHistoric */); + final List newMessagingMessages = + createMessages(newMessages, false /* isHistoric */); + bindViews(user, showSpinner, historicMessagingMessages, newMessagingMessages); } /** @@ -211,14 +218,15 @@ public class MessagingLayout extends FrameLayout } } - private void bind(List newMessages, - List newHistoricMessages, - boolean showSpinner) { - - List historicMessages = createMessages(newHistoricMessages, - true /* isHistoric */); - List messages = createMessages(newMessages, false /* isHistoric */); + private void bindViews(Person user, boolean showSpinner, + List historicMessagingMessages, + List newMessagingMessages) { + setUser(user); + bind(showSpinner, historicMessagingMessages, newMessagingMessages); + } + private void bind(boolean showSpinner, List historicMessages, + List messages) { ArrayList oldGroups = new ArrayList<>(mGroups); addMessagesToGroups(historicMessages, messages, showSpinner);