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
This commit is contained in:
Ibrahim Yilmaz
2023-08-09 14:32:42 +00:00
parent d7ab422d1b
commit 8a9733fc8d
2 changed files with 38 additions and 22 deletions

View File

@@ -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<MessagingMessage> newMessagingMessages =
createMessages(newMessages, false /* isHistoric */);
final List<MessagingMessage> 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<Notification.MessagingStyle.Message> newMessages,
List<Notification.MessagingStyle.Message> newHistoricMessages,
boolean showSpinner) {
// convert MessagingStyle.Message to MessagingMessage, re-using ones from a previous binding
// if they exist
List<MessagingMessage> historicMessages = createMessages(newHistoricMessages,
true /* isHistoric */);
List<MessagingMessage> messages = createMessages(newMessages, false /* isHistoric */);
private void bindViews(Person user,
boolean showSpinner, int unreadCount, List<MessagingMessage> newMessagingMessages,
List<MessagingMessage> newHistoricMessagingMessages) {
setUser(user);
setUnreadCount(unreadCount);
bind(showSpinner, newMessagingMessages, newHistoricMessagingMessages);
}
private void bind(boolean showSpinner, List<MessagingMessage> messages,
List<MessagingMessage> historicMessages) {
// Copy our groups, before they get clobbered
ArrayList<MessagingGroup> oldGroups = new ArrayList<>(mGroups);

View File

@@ -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<MessagingMessage> historicMessagingMessages = createMessages(newHistoricMessages,
true /* isHistoric */);
final List<MessagingMessage> newMessagingMessages =
createMessages(newMessages, false /* isHistoric */);
bindViews(user, showSpinner, historicMessagingMessages, newMessagingMessages);
}
/**
@@ -211,14 +218,15 @@ public class MessagingLayout extends FrameLayout
}
}
private void bind(List<Notification.MessagingStyle.Message> newMessages,
List<Notification.MessagingStyle.Message> newHistoricMessages,
boolean showSpinner) {
List<MessagingMessage> historicMessages = createMessages(newHistoricMessages,
true /* isHistoric */);
List<MessagingMessage> messages = createMessages(newMessages, false /* isHistoric */);
private void bindViews(Person user, boolean showSpinner,
List<MessagingMessage> historicMessagingMessages,
List<MessagingMessage> newMessagingMessages) {
setUser(user);
bind(showSpinner, historicMessagingMessages, newMessagingMessages);
}
private void bind(boolean showSpinner, List<MessagingMessage> historicMessages,
List<MessagingMessage> messages) {
ArrayList<MessagingGroup> oldGroups = new ArrayList<>(mGroups);
addMessagesToGroups(historicMessages, messages, showSpinner);