Show/hide the seek bar properly

1. Don't change the visibility of seek bar when the queue is shown
2. Add a wrapper around seek bar and change the visibility of the
wrapper when the visibility of control bar scrim or queue is changed.

Fixes: 142910039
Test: on Hawk and Volvo car
Change-Id: I5710c73eadb8e22671b5fd2e341b4faa60cfb77a
diff --git a/res/layout/fragment_playback.xml b/res/layout/fragment_playback.xml
index da935d3..511574e 100644
--- a/res/layout/fragment_playback.xml
+++ b/res/layout/fragment_playback.xml
@@ -111,27 +111,36 @@
         app:layout_constraintTop_toBottomOf="@id/app_bar_guideline"
         app:layout_constraintBottom_toTopOf="@+id/control_bar_first_row_guideline"/>
 
-    <SeekBar
+    <!-- @id/seek_bar should be hidden when @id/control_bar_scrim is expanded, and shown when the
+    scrim is collapsed. Since its visibility is also controlled by MetadataController, it could
+    become visible again even if the scrim is still expanded. To solve that we add a wrapper around
+    it and hide/show the wrapper when the scrim is expanded/collapsed.-->
+    <FrameLayout
         style="@style/SeekBarStyle"
-        android:id="@+id/seek_bar"
+        android:id="@+id/seek_bar_container"
         android:layout_gravity="center"
-        android:clickable="false"
-        android:focusable="false"
         android:layout_marginStart="@dimen/playback_seekbar_margin_x"
         android:layout_marginEnd="@dimen/playback_seekbar_margin_x"
-        android:paddingEnd="@dimen/playback_seekbar_padding_x"
-        android:paddingStart="@dimen/playback_seekbar_padding_x"
-        android:progressDrawable="@drawable/seekbar_background"
-        android:thumb="@drawable/seekbar_thumb"
-        android:thumbOffset="@dimen/playback_seekbar_thumb_offset"
-        android:splitTrack="false"
-        android:progressTint="@color/progress_bar_highlight"
-        android:progressBackgroundTint="@color/progress_bar_background"
-        android:background="@null"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/metadata_container"
-        app:layout_constraintBottom_toTopOf="@+id/control_bar_first_row_guideline"/>
+        app:layout_constraintBottom_toTopOf="@+id/control_bar_first_row_guideline">
+        <SeekBar
+            android:id="@+id/seek_bar"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:clickable="false"
+            android:focusable="false"
+            android:paddingEnd="@dimen/playback_seekbar_padding_x"
+            android:paddingStart="@dimen/playback_seekbar_padding_x"
+            android:progressDrawable="@drawable/seekbar_background"
+            android:thumb="@drawable/seekbar_thumb"
+            android:thumbOffset="@dimen/playback_seekbar_thumb_offset"
+            android:splitTrack="false"
+            android:progressTint="@color/progress_bar_highlight"
+            android:progressBackgroundTint="@color/progress_bar_background"
+            android:background="@null"/>
+    </FrameLayout>
 
     <Space
         android:id="@+id/queue_list_top_constraint"
diff --git a/res/values/id.xml b/res/values/id.xml
index ae86f45..8f60cc7 100644
--- a/res/values/id.xml
+++ b/res/values/id.xml
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
   <item type="id" name="imageDownloadTask"/>
+  <item type="id" name="seek_bar_container"/>
 </resources>
diff --git a/res/values/integers.xml b/res/values/integers.xml
index cd87eea..79f53ab 100644
--- a/res/values/integers.xml
+++ b/res/values/integers.xml
@@ -41,13 +41,13 @@
 
     <!-- Views to hide when opening the custom actions when the queue isn't visible. -->
     <integer-array name="playback_views_to_hide_when_showing_custom_actions">
-        <item>@id/seek_bar</item>
+        <item>@id/seek_bar_container</item>
     </integer-array>
 
     <!-- Views to hide when the queue is visible (to show when the queue becomes invisible). -->
     <integer-array name="playback_views_to_hide_when_queue_is_visible">
         <item>@id/metadata_container</item>
-        <item>@id/seek_bar</item>
+        <item>@id/seek_bar_container</item>
     </integer-array>
 
     <!-- Views to show when the queue is visible (to hide when the queue becomes invisible). -->
diff --git a/src/com/android/car/media/PlaybackFragment.java b/src/com/android/car/media/PlaybackFragment.java
index 445daa4..35f023d 100644
--- a/src/com/android/car/media/PlaybackFragment.java
+++ b/src/com/android/car/media/PlaybackFragment.java
@@ -71,6 +71,7 @@
     private PlaybackControlsActionBar mPlaybackControls;
     private QueueItemsAdapter mQueueAdapter;
     private RecyclerView mQueue;
+    private ViewGroup mSeekBarContainer;
     private SeekBar mSeekBar;
     private View mQueueButton;
     private ViewGroup mNavIconContainer;
@@ -286,6 +287,7 @@
         View view = inflater.inflate(R.layout.fragment_playback, container, false);
         mAlbumBackground = view.findViewById(R.id.playback_background);
         mQueue = view.findViewById(R.id.queue_list);
+        mSeekBarContainer = view.findViewById(R.id.seek_bar_container);
         mSeekBar = view.findViewById(R.id.seek_bar);
         mQueueButton = view.findViewById(R.id.queue_button);
         mQueueButton.setOnClickListener(button -> toggleQueueVisibility());
@@ -346,7 +348,7 @@
 
         // Don't update the visibility of seekBar if show_linear_progress_bar is false.
         ViewUtils.Filter ignoreSeekBarFilter =
-            (viewToFilter) -> mShowLinearProgressBar || viewToFilter != mSeekBar;
+            (viewToFilter) -> mShowLinearProgressBar || viewToFilter != mSeekBarContainer;
 
         mViewsToHideForCustomActions = ViewUtils.getViewsById(view, res,
             R.array.playback_views_to_hide_when_showing_custom_actions, ignoreSeekBarFilter);
@@ -394,16 +396,10 @@
             }
 
             if (expanding) {
-                if (mShowLinearProgressBar) {
-                    ViewUtils.hideViewAnimated(mSeekBar, millis);
-                }
                 if (mControlBarScrim != null) {
                     ViewUtils.showViewAnimated(mControlBarScrim, millis);
                 }
             } else {
-                if (mShowLinearProgressBar) {
-                    ViewUtils.showViewAnimated(mSeekBar, millis);
-                }
                 if (mControlBarScrim != null) {
                     ViewUtils.hideViewAnimated(mControlBarScrim, millis);
                 }
@@ -499,7 +495,6 @@
         mQueueButton.setActivated(mQueueIsVisible);
         mQueueButton.setSelected(mQueueIsVisible);
         if (mQueueIsVisible) {
-
             ViewUtils.showViewsAnimated(mViewsToShowWhenQueueIsVisible, mFadeDuration);
             ViewUtils.hideViewsAnimated(mViewsToHideWhenQueueIsVisible, mFadeDuration);
             ViewUtils.setVisible(mViewsToShowImmediatelyWhenQueueIsVisible, true);