Fixed an issue where media could become invisible

Fixes: 192939241
Test: follow steps on bug, observe media visible
Change-Id: I41fee551e97418640a054f6ee0152ec337172c56
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
index 8c2c373..a318073 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
@@ -140,9 +140,11 @@
         updateAnimators();
     }
 
-
-    public void onQsScrollingChanged() {
-        // Lazily update animators whenever the scrolling changes
+    /**
+     * Request an update to the animators. This will update them lazily next time the position
+     * is changed.
+     */
+    public void requestAnimatorUpdate() {
         mNeedsAnimatorUpdate = true;
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
index 0d91f29..36b4ee9 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
@@ -173,7 +173,7 @@
         mQSPanelScrollView.setOnScrollChangeListener(
                 (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
                     // Lazily update animators whenever the scrolling changes
-                    mQSAnimator.onQsScrollingChanged();
+                    mQSAnimator.requestAnimatorUpdate();
                     mHeader.setExpandedScrollAmount(scrollY);
                     if (mScrollListener != null) {
                         mScrollListener.onQsPanelScrollChanged(scrollY);
@@ -215,6 +215,14 @@
                         setQsExpansion(mLastQSExpansion, mLastHeaderTranslation);
                     }
                 });
+        mQSPanelController.setUsingHorizontalLayoutChangeListener(
+                () -> {
+                    // The hostview may be faded out in the horizontal layout. Let's make sure to
+                    // reset the alpha when switching layouts. This is fine since the animator will
+                    // update the alpha if it's not supposed to be 1.0f
+                    mQSPanelController.getMediaHost().getHostView().setAlpha(1.0f);
+                    mQSAnimator.requestAnimatorUpdate();
+                });
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java
index 7a09826..4739a3f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java
@@ -103,6 +103,9 @@
 
     private boolean mUsingHorizontalLayout;
 
+    @Nullable
+    private Runnable mUsingHorizontalLayoutChangedListener;
+
     protected QSPanelControllerBase(
             T view,
             QSTileHost host,
@@ -135,6 +138,13 @@
         mQSLogger.logAllTilesChangeListening(mView.isListening(), mView.getDumpableTag(), "");
     }
 
+    /**
+     * @return the media host for this panel
+     */
+    public MediaHost getMediaHost() {
+        return mMediaHost;
+    }
+
     @Override
     protected void onViewAttached() {
         mQsTileRevealController = createTileRevealController();
@@ -303,6 +313,9 @@
             mUsingHorizontalLayout = horizontal;
             mView.setUsingHorizontalLayout(mUsingHorizontalLayout, mMediaHost.getHostView(), force);
             updateMediaDisappearParameters();
+            if (mUsingHorizontalLayoutChangedListener != null) {
+                mUsingHorizontalLayoutChangedListener.run();
+            }
             return true;
         }
         return false;
@@ -386,6 +399,13 @@
         mMediaVisibilityChangedListener = listener;
     }
 
+    /**
+     * Add a listener when the horizontal layout changes
+     */
+    public void setUsingHorizontalLayoutChangeListener(Runnable listener) {
+        mUsingHorizontalLayoutChangedListener = listener;
+    }
+
     /** */
     public static final class TileRecord extends QSPanel.Record {
         public QSTile tile;