From 8362a52c4c795f2daad4756ff11cf0745a36da18 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Sun, 18 Apr 2021 22:59:25 -0400 Subject: [PATCH] Make smart reply insertion logic more robust Specifically, this removes the assumptions that the smart reply view container should only container one child, and that the smart replies will be the first view. Bug: 174575121 Test: manual, atest Change-Id: If2b98f6faac3e7cc4ac63bd114f25df1f604aa5e --- .../row/NotificationContentView.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java index a0b0b3dc57bd6..5cc23c0f00286 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java @@ -1481,18 +1481,26 @@ public class NotificationContentView extends FrameLayout { return null; } - SmartReplyView smartReplyView = null; - if (smartReplyContainer.getChildCount() == 1 - && smartReplyContainer.getChildAt(0) instanceof SmartReplyView) { + // Search for an existing SmartReplyView + int index = 0; + final int childCount = smartReplyContainer.getChildCount(); + for (; index < childCount; index++) { + View child = smartReplyContainer.getChildAt(index); + if (child.getId() == R.id.smart_reply_view && child instanceof SmartReplyView) { + break; + } + } + + if (index < childCount) { // If we already have a SmartReplyView - replace it with the newly inflated one. The // newly inflated one is connected to the new inflated smart reply/action buttons. - smartReplyContainer.removeAllViews(); + smartReplyContainer.removeViewAt(index); } - if (smartReplyContainer.getChildCount() == 0 - && inflatedSmartReplyViewHolder != null + SmartReplyView smartReplyView = null; + if (inflatedSmartReplyViewHolder != null && inflatedSmartReplyViewHolder.getSmartReplyView() != null) { smartReplyView = inflatedSmartReplyViewHolder.getSmartReplyView(); - smartReplyContainer.addView(smartReplyView); + smartReplyContainer.addView(smartReplyView, index); } if (smartReplyView != null) { smartReplyView.resetSmartSuggestions(smartReplyContainer);