Merge "Fixed an issue where the unread count would disappear too fast" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-04-07 18:42:06 +00:00
committed by Android (Google) Code Review
5 changed files with 75 additions and 11 deletions

View File

@@ -386,14 +386,17 @@ public class ConversationLayout extends FrameLayout
/** @hide */
public void setUnreadCount(int unreadCount) {
mUnreadBadge.setVisibility(mIsCollapsed && unreadCount > 1 ? VISIBLE : GONE);
CharSequence text = unreadCount >= 100
? getResources().getString(R.string.unread_convo_overflow, 99)
: String.format(Locale.getDefault(), "%d", unreadCount);
mUnreadBadge.setText(text);
mUnreadBadge.setBackgroundTintList(ColorStateList.valueOf(mLayoutColor));
boolean needDarkText = ColorUtils.calculateLuminance(mLayoutColor) > 0.5f;
mUnreadBadge.setTextColor(needDarkText ? Color.BLACK : Color.WHITE);
boolean visible = mIsCollapsed && unreadCount > 1;
mUnreadBadge.setVisibility(visible ? VISIBLE : GONE);
if (visible) {
CharSequence text = unreadCount >= 100
? getResources().getString(R.string.unread_convo_overflow, 99)
: String.format(Locale.getDefault(), "%d", unreadCount);
mUnreadBadge.setText(text);
mUnreadBadge.setBackgroundTintList(ColorStateList.valueOf(mLayoutColor));
boolean needDarkText = ColorUtils.calculateLuminance(mLayoutColor) > 0.5f;
mUnreadBadge.setTextColor(needDarkText ? Color.BLACK : Color.WHITE);
}
}
private void addRemoteInputHistoryToMessages(

View File

@@ -103,12 +103,20 @@ class ConversationNotificationManager @Inject constructor(
override fun onEntryInflated(entry: NotificationEntry) {
if (!entry.ranking.isConversation) return
fun updateCount(isExpanded: Boolean) {
if (isExpanded && !notifPanelCollapsed) {
if (isExpanded && (!notifPanelCollapsed || entry.isPinnedAndExpanded())) {
resetCount(entry.key)
entry.row?.let(::resetBadgeUi)
}
}
entry.row?.setOnExpansionChangedListener(::updateCount)
entry.row?.setOnExpansionChangedListener { isExpanded ->
if (entry.row?.isShown == true && isExpanded) {
entry.row.performOnIntrinsicHeightReached {
updateCount(isExpanded)
}
} else {
updateCount(isExpanded)
}
}
updateCount(entry.row?.isExpanded == true)
}
@@ -169,7 +177,8 @@ class ConversationNotificationManager @Inject constructor(
private fun resetBadgeUi(row: ExpandableNotificationRow): Unit =
(row.layouts?.asSequence() ?: emptySequence())
.mapNotNull { layout -> layout.contractedChild as? ConversationLayout }
.flatMap { layout -> layout.allViews.asSequence()}
.mapNotNull { view -> view as? ConversationLayout }
.forEach { convoLayout -> convoLayout.setUnreadCount(0) }
private data class ConversationState(val unreadCount: Int, val notification: Notification)

View File

@@ -601,6 +601,13 @@ public final class NotificationEntry extends ListEntry {
return row != null && row.isPinned();
}
/**
* Is this entry pinned and was expanded while doing so
*/
public boolean isPinnedAndExpanded() {
return row != null && row.isPinnedAndExpanded();
}
public void setRowPinned(boolean pinned) {
if (row != null) row.setPinned(pinned);
}

View File

@@ -284,6 +284,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
if (isPinned()) {
nowExpanded = !mExpandedWhenPinned;
mExpandedWhenPinned = nowExpanded;
// Also notify any expansion changed listeners. This is necessary since the
// expansion doesn't actually change (it's already system expanded) but it
// changes visually
if (mExpansionChangedListener != null) {
mExpansionChangedListener.onExpansionChanged(nowExpanded);
}
} else {
nowExpanded = !isExpanded();
setUserExpanded(nowExpanded);
@@ -326,6 +332,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
private NotificationInlineImageResolver mImageResolver;
private NotificationMediaManager mMediaManager;
@Nullable private OnExpansionChangedListener mExpansionChangedListener;
@Nullable private Runnable mOnIntrinsicHeightReachedRunnable;
private SystemNotificationAsyncTask mSystemNotificationAsyncTask =
new SystemNotificationAsyncTask();
@@ -358,6 +365,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
return Arrays.copyOf(mLayouts, mLayouts.length);
}
/**
* Is this entry pinned and was expanded while doing so
*/
public boolean isPinnedAndExpanded() {
if (!isPinned()) {
return false;
}
return mExpandedWhenPinned;
}
@Override
public boolean isGroupExpansionChanging() {
if (isChildInGroup()) {
@@ -2690,6 +2707,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
if (mMenuRow != null && mMenuRow.getMenuView() != null) {
mMenuRow.onParentHeightUpdate();
}
handleIntrinsicHeightReached();
}
@Override
@@ -2907,6 +2925,24 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
mExpansionChangedListener = listener;
}
/**
* Perform an action when the notification height has reached its intrinsic height.
*
* @param runnable the runnable to run
*/
public void performOnIntrinsicHeightReached(@Nullable Runnable runnable) {
mOnIntrinsicHeightReachedRunnable = runnable;
handleIntrinsicHeightReached();
}
private void handleIntrinsicHeightReached() {
if (mOnIntrinsicHeightReachedRunnable != null
&& getActualHeight() == getIntrinsicHeight()) {
mOnIntrinsicHeightReachedRunnable.run();
mOnIntrinsicHeightReachedRunnable = null;
}
}
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfoInternal(info);

View File

@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.notification.row;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Notification;
import android.app.PendingIntent;
@@ -988,6 +989,14 @@ public class NotificationContentView extends FrameLayout {
}
}
public @NonNull View[] getAllViews() {
return new View[] {
mContractedChild,
mHeadsUpChild,
mExpandedChild,
mSingleLineView };
}
public NotificationViewWrapper getVisibleWrapper(int visibleType) {
switch (visibleType) {
case VISIBLE_TYPE_EXPANDED: