From 035a9369f51f356bc16005e93cfb1f1aeb0ab5dd Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Thu, 20 Apr 2017 15:51:16 -0400 Subject: [PATCH] QS + DND interaction again - Fix up attach/detach because those aren't good signals for DND panels, instead use aggregate visibility - Do better initialization on open because filling in that state is now important (previously it was guaranteed to be just turned on) - Fix when forever is selected, if DND is on and doesn't have a condition, it doesn't mean we should turn one on. Test: manual Change-Id: I61dcf3c2b17179b5867f017c767d0c2d6d4940f3 Fixes: 37366004 --- .../android/systemui/volume/ZenModePanel.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index f7dfc0a771db9..fffcc087223f5 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -289,13 +289,20 @@ public class ZenModePanel extends FrameLayout { } } - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (DEBUG) Log.d(mTag, "onAttachedToWindow"); + private void onAttach() { setExpanded(true); mAttached = true; - mAttachedZen = getSelectedZen(-1); + for (int i = 0; i < mZenRadioGroupContent.getChildCount(); i++) { + ConditionTag tag = getConditionTagAt(i); + if (tag != null) tag.rb.setChecked(false); + mZenRadioGroupContent.getChildAt(i).setTag(null); + } + mAttachedZen = mController.getZen(); + ZenRule manualRule = mController.getManualRule(); + mExitCondition = manualRule != null ? manualRule.condition : null; + if (DEBUG) Log.d(mTag, "onAttach " + mAttachedZen + " " + manualRule); + handleUpdateManualRule(manualRule); + mZenButtons.setSelectedValue(mAttachedZen, false); mSessionZen = mAttachedZen; mTransitionHelper.clear(); mController.addCallback(mZenCallback); @@ -304,10 +311,8 @@ public class ZenModePanel extends FrameLayout { setRequestingConditions(!mHidden); } - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - if (DEBUG) Log.d(mTag, "onDetachedFromWindow"); + private void onDetach() { + if (DEBUG) Log.d(mTag, "onDetach"); setExpanded(false); checkForAttachedZenChange(); mAttached = false; @@ -319,6 +324,17 @@ public class ZenModePanel extends FrameLayout { mTransitionHelper.clear(); } + @Override + public void onVisibilityAggregated(boolean isVisible) { + super.onVisibilityAggregated(isVisible); + if (isVisible == mAttached) return; + if (isVisible) { + onAttach(); + } else { + onDetach(); + } + } + private void setSessionExitCondition(Condition condition) { if (Objects.equals(condition, mSessionExitCondition)) return; if (DEBUG) Log.d(mTag, "mSessionExitCondition=" + getConditionId(condition)); @@ -680,7 +696,8 @@ public class ZenModePanel extends FrameLayout { final int favoriteIndex = mPrefs.getMinuteIndex(); if (mExitCondition != null && mExitCondition.equals(mTimeCondition)) { getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.setChecked(true); - } else if (favoriteIndex == -1 || !mCountdownConditionSupported) { + } else if (favoriteIndex == -1 || !mCountdownConditionSupported || + mAttachedZen != Global.ZEN_MODE_OFF) { foreverTag.rb.setChecked(true); } else { mTimeCondition = ZenModeConfig.toTimeCondition(mContext,