diff options
author | Roberto Perez <robertoalexis@google.com> | 2018-05-15 17:25:46 -0700 |
---|---|---|
committer | Roberto Perez <robertoalexis@google.com> | 2018-05-18 14:28:20 -0700 |
commit | 1d3e7e02676ed495b9f99701fa4647aa524d3f1b (patch) | |
tree | 978f40544280f2e2be23f64ded330a4f7f259d79 | |
parent | fc30bbfdb4221ecd18adf59501d5ca82ca631310 (diff) | |
download | Media-1d3e7e02676ed495b9f99701fa4647aa524d3f1b.tar.gz |
Fixing navigation when content forward browsing is disabled.
Bug: 78908883
Test: Launched in Mojave
Change-Id: I453d306665ca6f446c12b38b381d352a91d311b9
Merged-In: I453d306665ca6f446c12b38b381d352a91d311b9
17 files changed, 221 insertions, 73 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 47da7be..76e2464 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,6 +16,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" + android:sharedUserId="com.android.car.media" package="com.android.car.media" > <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/> diff --git a/res/layout-h1200dp/fragment_metadata.xml b/res/layout-h1200dp/fragment_metadata.xml new file mode 100644 index 0000000..63412aa --- /dev/null +++ b/res/layout-h1200dp/fragment_metadata.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2018, The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<merge + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + tools:showIn="@layout/fragment_playback"> + + <ImageView + android:id="@+id/album_art" + android:layout_width="@dimen/playback_album_art_size_large" + android:layout_height="@dimen/playback_album_art_size_large" + android:layout_marginEnd="@dimen/car_keyline_2" + android:layout_marginStart="@dimen/car_keyline_2" + android:contentDescription="@string/album_art" + android:background="@color/car_body1_light" + android:scaleType="centerCrop" + android:transitionName="@string/album_art" + app:layout_constraintBottom_toTopOf="@id/metadata_subcontainer" + app:layout_constraintEnd_toEndOf="@+id/margin_end" + app:layout_constraintStart_toStartOf="@+id/margin_start" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_chainStyle="packed" + tools:src="@drawable/ic_person"/> + + <include + android:id="@+id/metadata_subcontainer" + layout="@layout/metadata_normal" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/car_padding_5" + android:layout_marginBottom="@dimen/playback_controls_margin" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/album_art" + app:layout_constraintStart_toStartOf="@+id/album_art" + app:layout_constraintTop_toBottomOf="@+id/album_art"/> + + <androidx.car.widget.PagedListView + android:id="@+id/queue_list" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_marginTop="@dimen/playback_album_art_size_normal" + android:layout_marginBottom="@dimen/playback_controls_margin" + android:visibility="gone" + app:dividerEndMargin="@dimen/car_keyline_1" + app:dividerStartMargin="@dimen/car_keyline_1" + app:layout_behavior="@string/appbar_scrolling_view_behavior" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@+id/margin_top" + app:listDividerColor="@color/car_list_divider_light"/> +</merge> diff --git a/res/layout/fragment_metadata_with_queue.xml b/res/layout-h1200dp/fragment_metadata_with_queue.xml index f3474f0..26bfb26 100644 --- a/res/layout/fragment_metadata_with_queue.xml +++ b/res/layout-h1200dp/fragment_metadata_with_queue.xml @@ -28,6 +28,7 @@ android:layout_marginTop="@dimen/car_padding_4" android:layout_marginStart="@dimen/car_keyline_1" android:contentDescription="@string/album_art" + android:background="@color/car_body1_light" android:scaleType="centerCrop" android:transitionName="@string/album_art" app:layout_constraintTop_toTopOf="parent" diff --git a/res/layout/fragment_playback_with_queue.xml b/res/layout-h1200dp/fragment_playback_with_queue.xml index 113de90..113de90 100644 --- a/res/layout/fragment_playback_with_queue.xml +++ b/res/layout-h1200dp/fragment_playback_with_queue.xml diff --git a/res/layout/fragment_metadata.xml b/res/layout/fragment_metadata.xml index ffeaf95..4324681 100644 --- a/res/layout/fragment_metadata.xml +++ b/res/layout/fragment_metadata.xml @@ -18,22 +18,21 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - tools:showIn="@layout/fragment_playback"> + tools:showIn="@layout/fragment_playback_with_queue"> + <ImageView android:id="@+id/album_art" - android:layout_width="@dimen/playback_album_art_size_large" - android:layout_height="@dimen/playback_album_art_size_large" - android:layout_marginEnd="@dimen/car_keyline_2" - android:layout_marginStart="@dimen/car_keyline_2" + android:layout_width="@dimen/playback_album_art_size_normal" + android:layout_height="@dimen/playback_album_art_size_normal" + android:layout_marginStart="@dimen/car_keyline_1" android:contentDescription="@string/album_art" + android:background="@color/car_body1_light" android:scaleType="centerCrop" android:transitionName="@string/album_art" - app:layout_constraintBottom_toTopOf="@id/metadata_subcontainer" - app:layout_constraintEnd_toEndOf="@+id/margin_end" - app:layout_constraintStart_toStartOf="@+id/margin_start" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_chainStyle="packed" + app:layout_constraintBottom_toTopOf="@+id/playback_controls" + app:layout_constraintStart_toStartOf="@+id/margin_start" tools:src="@drawable/ic_person"/> <include @@ -41,24 +40,25 @@ layout="@layout/metadata_normal" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/car_padding_5" - android:layout_marginBottom="@dimen/playback_controls_margin" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="@+id/album_art" - app:layout_constraintStart_toStartOf="@+id/album_art" - app:layout_constraintTop_toBottomOf="@+id/album_art"/> + android:layout_marginStart="@dimen/car_padding_4" + android:layout_marginEnd="@dimen/car_keyline_1" + app:layout_constraintBottom_toBottomOf="@+id/album_art" + app:layout_constraintEnd_toEndOf="@+id/margin_end" + app:layout_constraintStart_toEndOf="@+id/album_art" + app:layout_constraintTop_toTopOf="@+id/album_art"/> <androidx.car.widget.PagedListView android:id="@+id/queue_list" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_marginTop="@dimen/playback_album_art_size_normal" + android:layout_marginTop="@dimen/car_padding_4" android:layout_marginBottom="@dimen/playback_controls_margin" android:visibility="gone" app:dividerEndMargin="@dimen/car_keyline_1" app:dividerStartMargin="@dimen/car_keyline_1" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintTop_toBottomOf="@+id/margin_top" + app:layout_constraintTop_toBottomOf="@+id/album_art" app:listDividerColor="@color/car_list_divider_light"/> + </merge> diff --git a/res/layout/media_activity.xml b/res/layout/media_activity.xml index c719337..050a9c8 100644 --- a/res/layout/media_activity.xml +++ b/res/layout/media_activity.xml @@ -39,7 +39,6 @@ android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_marginTop="@dimen/car_padding_4" android:visibility="visible" app:layout_constraintTop_toBottomOf="@+id/app_bar" app:layout_constraintBottom_toTopOf="@+id/browse_controls_container"/> @@ -48,7 +47,6 @@ android:id="@+id/playback_container" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_marginTop="@dimen/car_padding_4" android:visibility="gone" app:layout_constraintTop_toBottomOf="@+id/app_bar" app:layout_constraintBottom_toBottomOf="parent"/> @@ -86,7 +84,7 @@ <com.android.car.media.widgets.AppBarView android:id="@+id/app_bar" - android:layout_height="@dimen/appbar_height" + android:layout_height="@dimen/car_app_bar_height" android:layout_width="match_parent" app:layout_constraintTop_toTopOf="parent"/> diff --git a/res/values-h1200dp/bools.xml b/res/values-h1200dp/bools.xml index 34eae64..b1476c8 100644 --- a/res/values-h1200dp/bools.xml +++ b/res/values-h1200dp/bools.xml @@ -15,6 +15,6 @@ limitations under the License. --> <resources> + <!-- On screens tall enough we enable content forward browsing --> <bool name="forward_content_browse_enabled">true</bool> - <bool name="force_browse_tabs">true</bool> </resources>
\ No newline at end of file diff --git a/res/values-h600dp/dimens.xml b/res/values-h1200dp/dimens.xml index 25639cf..6032220 100644 --- a/res/values-h600dp/dimens.xml +++ b/res/values-h1200dp/dimens.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2016 The Android Open Source Project +<!-- Copyright (C) 2018 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,5 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. --> <resources> - <dimen name="now_playing_metadata_top_margin">32dp</dimen> + <!-- Application Bar --> + <dimen name="car_app_bar_height">116dp</dimen> </resources> diff --git a/res/values/bools.xml b/res/values/bools.xml index b9bd29e..3247ad9 100644 --- a/res/values/bools.xml +++ b/res/values/bools.xml @@ -17,8 +17,4 @@ <resources> <!-- Whether forward content browse is enabled --> <bool name="forward_content_browse_enabled">false</bool> - - <!-- Force the presentation of tabs even if the number of browsable items exceeds the - maximum number of allowed tabs (this is mainly for demo purposes) --> - <bool name="force_browse_tabs">false</bool> </resources>
\ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index bc9b767..f4a7439 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -23,7 +23,6 @@ <!-- Music now playing screen --> <dimen name="music_action_icon_inset">0dp</dimen> <dimen name="music_action_ripple_inset">32dp</dimen> - <dimen name="now_playing_metadata_top_margin">0dp</dimen> <dimen name="missing_permission_icon_size">128dp</dimen> diff --git a/src/com/android/car/media/BrowseFragment.java b/src/com/android/car/media/BrowseFragment.java index 9286632..ecb3f6c 100644 --- a/src/com/android/car/media/BrowseFragment.java +++ b/src/com/android/car/media/BrowseFragment.java @@ -90,14 +90,19 @@ public class BrowseFragment extends Fragment { mBrowseAdapter.update(); if (mBrowseAdapter.getItemCount() > 0) { ViewUtils.showViewAnimated(mBrowseList, mFadeDuration); + ViewUtils.hideViewAnimated(mErrorIcon, mFadeDuration); + ViewUtils.hideViewAnimated(mErrorMessage, mFadeDuration); } else { mErrorMessage.setText(R.string.nothing_to_play); + ViewUtils.hideViewAnimated(mBrowseList, mFadeDuration); + ViewUtils.hideViewAnimated(mErrorIcon, mFadeDuration); ViewUtils.showViewAnimated(mErrorMessage, mFadeDuration); } break; case ERROR: stopLoadingIndicator(); mErrorMessage.setText(R.string.unknown_error); + ViewUtils.hideViewAnimated(mBrowseList, mFadeDuration); ViewUtils.showViewAnimated(mErrorMessage, mFadeDuration); ViewUtils.showViewAnimated(mErrorIcon, mFadeDuration); break; @@ -245,9 +250,6 @@ public class BrowseFragment extends Fragment { if (mMediaSource != null) { mMediaSource.subscribe(mBrowseObserver); } - if (mBrowseAdapter != null) { - mBrowseAdapter.start(); - } } private Runnable mProgressIndicatorRunnable = new Runnable() { @@ -277,6 +279,7 @@ public class BrowseFragment extends Fragment { } if (mBrowseAdapter != null) { mBrowseAdapter.stop(); + mBrowseAdapter = null; } } diff --git a/src/com/android/car/media/MediaActivity.java b/src/com/android/car/media/MediaActivity.java index d6c3f8f..d7b809b 100644 --- a/src/com/android/car/media/MediaActivity.java +++ b/src/com/android/car/media/MediaActivity.java @@ -23,9 +23,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.os.Bundle; -import android.support.design.widget.AppBarLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.widget.DrawerLayout; import android.transition.Fade; import android.util.Log; import android.util.TypedValue; @@ -56,7 +56,7 @@ import androidx.car.drawer.CarDrawerAdapter; * by broadcast. Drawer menu is controlled by {@link MediaDrawerController}. */ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.Callbacks, - AppSelectionFragment.Callbacks { + AppSelectionFragment.Callbacks, PlaybackFragment.Callbacks { private static final String TAG = "MediaActivity"; /** Intent extra specifying the package with the MediaBrowser */ @@ -84,7 +84,6 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C private CrossfadeImageView mAlbumBackground; private PlaybackFragment mPlaybackFragment; private AppSelectionFragment mAppSelectionFragment; - private AppBarLayout mDrawerBarLayout; private PlaybackControls mPlaybackControls; private MetadataView mMetadataView; private ViewGroup mBrowseControlsContainer; @@ -157,6 +156,7 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C @Override public void onAppSelection() { + Log.d(TAG, "onAppSelection clicked"); if (mIsAppSelectorOpen) { closeAppSelector(); } else { @@ -168,6 +168,24 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C mAppBarView.setAppSelection(!mMediaSourcesManager.getMediaSources().isEmpty()); mAppSelectionFragment.refresh(); }; + private DrawerLayout.DrawerListener mDrawerListener = new DrawerLayout.DrawerListener() { + @Override + public void onDrawerSlide(@android.support.annotation.NonNull View view, float v) { + } + + @Override + public void onDrawerOpened(@android.support.annotation.NonNull View view) { + closeAppSelector(); + } + + @Override + public void onDrawerClosed(@android.support.annotation.NonNull View view) { + } + + @Override + public void onDrawerStateChanged(int i) { + } + }; /** * Possible modes of the application UI @@ -198,17 +216,20 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C super.onCreate(savedInstanceState); setMainContent(R.layout.media_activity); - setToolbarElevation(0f); + setToolbarClickThrough(true); mContentForwardBrowseEnabled = getResources() .getBoolean(R.bool.forward_content_browse_enabled); mDrawerController = new MediaDrawerController(this, getDrawerController()); getDrawerController().setRootAdapter(getRootAdapter()); + getDrawerController().addDrawerListener(mDrawerListener); + if (mContentForwardBrowseEnabled) { + getSupportActionBar().hide(); + } mAppBarView = findViewById(R.id.app_bar); mAppBarView.setListener(mAppBarListener); - boolean forceBrowseTabs = getResources().getBoolean(R.bool.force_browse_tabs); - mAppBarView.setVisibility(forceBrowseTabs ? View.VISIBLE : View.GONE); + mAppBarView.setContentForwardEnabled(mContentForwardBrowseEnabled); mPlaybackFragment = new PlaybackFragment(); mAppSelectionFragment = new AppSelectionFragment(); int fadeDuration = getResources().getInteger(R.integer.app_selector_fade_duration); @@ -216,8 +237,6 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C mAppSelectionFragment.setExitTransition(new Fade().setDuration(fadeDuration)); mPlaybackModel = new PlaybackModel(this); mMediaSourcesManager = new MediaSourcesManager(this); - mDrawerBarLayout = findViewById(androidx.car.R.id.appbar); - mDrawerBarLayout.setVisibility(forceBrowseTabs ? View.GONE : View.VISIBLE); mAlbumBackground = findViewById(R.id.media_background); mPlaybackControls = findViewById(R.id.browse_controls); mPlaybackControls.setModel(mPlaybackModel); @@ -361,7 +380,6 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C } mMediaSource = mediaSource; setLastMediaSource(mMediaSource); - mAppBarView.setState(AppBarView.State.BROWSING); if (mMediaSource != null) { if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Browsing: " + mediaSource.getName()); @@ -370,10 +388,10 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C MediaManager.getInstance(this).setMediaClientComponent(component); // If content forward browsing is disabled, then no need to subscribe to this media // source. - updateBrowseFragment(BrowseState.LOADING, null); if (mContentForwardBrowseEnabled) { Log.i(TAG, "Content forward is enabled: subscribing to " + mMediaSource.getPackageName()); + updateBrowseFragment(BrowseState.LOADING, null); mMediaSource.subscribe(mMediaSourceObserver); } mAppBarView.setAppIcon(mMediaSource.getRoundPackageIcon()); @@ -435,9 +453,11 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C } private void switchToMode(Mode mode) { - mMode = mode; + // If content forward is not enable, then we always show the playback UI (browse will be + // done in the drawer) + mMode = mContentForwardBrowseEnabled ? mode : Mode.PLAYBACK; updateMetadata(); - switch (mode) { + switch (mMode) { case PLAYBACK: ViewUtils.showViewAnimated(mPlaybackContainer, mFadeDuration); ViewUtils.hideViewAnimated(mBrowseContainer, mFadeDuration); @@ -624,4 +644,14 @@ public class MediaActivity extends CarDrawerActivity implements BrowseFragment.C .putString(LAST_MEDIA_SOURCE_SHARED_PREF_KEY, mediaSource.getPackageName()) .apply(); } + + + @Override + public void onQueueButtonClicked() { + if (mContentForwardBrowseEnabled) { + mPlaybackFragment.toggleQueueVisibility(); + } else { + mDrawerController.showPlayQueue(); + } + } } diff --git a/src/com/android/car/media/MetadataController.java b/src/com/android/car/media/MetadataController.java index 5f74891..e7261f5 100644 --- a/src/com/android/car/media/MetadataController.java +++ b/src/com/android/car/media/MetadataController.java @@ -14,7 +14,6 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import java.util.Objects; /** * Common controller for displaying current track's metadata. @@ -116,9 +115,13 @@ public class MetadataController { MediaItemMetadata metadata = mModel != null ? mModel.getMetadata() : null; mTitle.setText(metadata != null ? metadata.getTitle() : null); mSubtitle.setText(metadata != null ? metadata.getSubtitle() : null); - if (mAlbumArt != null && metadata != null) { + if (mAlbumArt != null && metadata != null && (metadata.getAlbumArtUri() != null + || metadata.getAlbumArtBitmap() != null)) { + mAlbumArt.setVisibility(View.VISIBLE); metadata.getAlbumArt(mAlbumArt.getContext(), mAlbumArtSize, mAlbumArtSize, true) .thenAccept(mAlbumArt::setImageBitmap); + } else if (mAlbumArt != null) { + mAlbumArt.setVisibility(View.GONE); } } diff --git a/src/com/android/car/media/PlaybackFragment.java b/src/com/android/car/media/PlaybackFragment.java index da42832..d88a348 100644 --- a/src/com/android/car/media/PlaybackFragment.java +++ b/src/com/android/car/media/PlaybackFragment.java @@ -61,6 +61,7 @@ public class PlaybackFragment extends Fragment { private PlaybackControls mPlaybackControls; private QueueItemsAdapter mQueueAdapter; private PagedListView mQueue; + private Callbacks mCallbacks; private MetadataController mMetadataController; private ConstraintLayout mRootView; @@ -123,12 +124,22 @@ public class PlaybackFragment extends Fragment { } } + /** + * Callbacks this fragment can trigger + */ + public interface Callbacks { + /** + * Indicates that the "show queue" button has been clicked + */ + void onQueueButtonClicked(); + } + private PlaybackControls.Listener mPlaybackControlsListener = new PlaybackControls.Listener() { @Override public void onToggleQueue() { - mQueueIsVisible = !mQueueIsVisible; - mPlaybackControls.setQueueVisible(mQueueIsVisible); - setQueueVisible(mQueueIsVisible); + if (mCallbacks != null) { + mCallbacks.onQueueButtonClicked(); + } } }; @@ -146,6 +157,18 @@ public class PlaybackFragment extends Fragment { return view; } + @Override + public void onAttach(Context context) { + super.onAttach(context); + mCallbacks = (Callbacks) context; + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + private void initPlaybackControls(PlaybackControls playbackControls) { mPlaybackControls = playbackControls; mPlaybackControls.setModel(mModel); @@ -193,9 +216,15 @@ public class PlaybackFragment extends Fragment { mModel.unregisterObserver(mPlaybackObserver); } - public void setQueueVisible(boolean visible) { + /** + * Hides or shows the playback queue + */ + public void toggleQueueVisibility() { + mQueueIsVisible = !mQueueIsVisible; + mPlaybackControls.setQueueVisible(mQueueIsVisible); + Transition transition = TransitionInflater.from(getContext()).inflateTransition( - visible ? R.transition.queue_in : R.transition.queue_out); + mQueueIsVisible ? R.transition.queue_in : R.transition.queue_out); transition.addListener(new TransitionListenerAdapter() { @Override @@ -218,9 +247,8 @@ public class PlaybackFragment extends Fragment { TransitionManager.beginDelayedTransition(mRootView, transition); ConstraintSet constraintSet = new ConstraintSet(); constraintSet.clone(mRootView.getContext(), - visible ? R.layout.fragment_playback_with_queue : R.layout.fragment_playback); + mQueueIsVisible ? R.layout.fragment_playback_with_queue : R.layout.fragment_playback); constraintSet.applyTo(mRootView); - } private void updateState() { diff --git a/src/com/android/car/media/browse/BrowseAdapter.java b/src/com/android/car/media/browse/BrowseAdapter.java index dcb8d4a..dd5d2ee 100644 --- a/src/com/android/car/media/browse/BrowseAdapter.java +++ b/src/com/android/car/media/browse/BrowseAdapter.java @@ -358,6 +358,7 @@ public class BrowseAdapter extends RecyclerView.Adapter<BrowseViewHolder> implem if (parentId.equals(mParentMediaItemId)) { // Direct children from the requested media item id. Update subscription list. LinkedHashMap<String, MediaItemState> newItemStates = new LinkedHashMap<>(); + List<MediaItemState> itemsToSubscribe = new ArrayList<>(); for (MediaItemMetadata item : children) { MediaItemState itemState = mItemStates.get(item.getId()); if (itemState != null) { @@ -368,7 +369,7 @@ public class BrowseAdapter extends RecyclerView.Adapter<BrowseViewHolder> implem // New section, subscribe to it. itemState = new MediaItemState(item); newItemStates.put(item.getId(), itemState); - subscribe(itemState); + itemsToSubscribe.add(itemState); } } // Remove unused sections @@ -376,6 +377,11 @@ public class BrowseAdapter extends RecyclerView.Adapter<BrowseViewHolder> implem unsubscribe(itemState); } mItemStates = newItemStates; + // Subscribe items once we have updated the map (updates might happen synchronously + // if data is already available). + for (MediaItemState itemState : itemsToSubscribe) { + subscribe(itemState); + } } else { MediaItemState itemState = mItemStates.get(parentId); if (itemState == null) { diff --git a/src/com/android/car/media/drawer/MediaItemsFetcher.java b/src/com/android/car/media/drawer/MediaItemsFetcher.java index 3cef566..36c01c0 100644 --- a/src/com/android/car/media/drawer/MediaItemsFetcher.java +++ b/src/com/android/car/media/drawer/MediaItemsFetcher.java @@ -19,6 +19,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.media.MediaDescription; import android.text.TextUtils; +import android.view.View; import com.android.car.apps.common.BitmapDownloader; import com.android.car.apps.common.BitmapWorkerOptions; @@ -114,22 +115,27 @@ interface MediaItemsFetcher { } Bitmap iconBitmap = description.getIconBitmap(); holder.getIcon().setImageBitmap(iconBitmap); // Ok to set null here for clearing. - if (iconBitmap == null && description.getIconUri() != null) { - int bitmapSize = - context.getResources().getDimensionPixelSize(R.dimen.car_primary_icon_size); - // We don't want to cache android resources as they are needed to be refreshed after - // configuration changes. - int cacheFlag = UriUtils.isAndroidResourceUri(description.getIconUri()) - ? (BitmapWorkerOptions.CACHE_FLAG_DISK_DISABLED - | BitmapWorkerOptions.CACHE_FLAG_MEM_DISABLED) - : 0; - BitmapWorkerOptions options = new BitmapWorkerOptions.Builder(context) - .resource(description.getIconUri()) - .height(bitmapSize) - .width(bitmapSize) - .cacheFlag(cacheFlag) - .build(); - BitmapDownloader.getInstance(context).loadBitmap(options, holder.getIcon()); + if (iconBitmap == null) { + if (description.getIconUri() != null) { + holder.getIcon().setVisibility(View.VISIBLE); + int bitmapSize = + context.getResources().getDimensionPixelSize(R.dimen.car_primary_icon_size); + // We don't want to cache android resources as they are needed to be refreshed after + // configuration changes. + int cacheFlag = UriUtils.isAndroidResourceUri(description.getIconUri()) + ? (BitmapWorkerOptions.CACHE_FLAG_DISK_DISABLED + | BitmapWorkerOptions.CACHE_FLAG_MEM_DISABLED) + : 0; + BitmapWorkerOptions options = new BitmapWorkerOptions.Builder(context) + .resource(description.getIconUri()) + .height(bitmapSize) + .width(bitmapSize) + .cacheFlag(cacheFlag) + .build(); + BitmapDownloader.getInstance(context).loadBitmap(options, holder.getIcon()); + } else { + holder.getIcon().setVisibility(View.GONE); + } } } } diff --git a/src/com/android/car/media/widgets/AppBarView.java b/src/com/android/car/media/widgets/AppBarView.java index bad0641..741e07f 100644 --- a/src/com/android/car/media/widgets/AppBarView.java +++ b/src/com/android/car/media/widgets/AppBarView.java @@ -56,6 +56,7 @@ public class AppBarView extends RelativeLayout { private MediaItemMetadata mSelectedItem; private String mMediaAppTitle; private Drawable mDefaultIcon; + private boolean mContentForwardEnabled; /** * Application bar listener @@ -238,6 +239,13 @@ public class AppBarView extends RelativeLayout { } /** + * Whether content forward browsing is enabled or not + */ + public void setContentForwardEnabled(boolean enabled) { + mContentForwardEnabled = enabled; + } + + /** * Updates the application icon to show next to the application switcher. */ public void setAppIcon(Bitmap icon) { @@ -304,15 +312,18 @@ public class AppBarView extends RelativeLayout { break; case PLAYING: mNavIcon.setImageDrawable(mCollapse); - mNavIconContainer.setVisibility(hasItems ? View.GONE : View.VISIBLE); - mTabsContainer.setVisibility(hasItems ? View.VISIBLE : View.GONE); - mTitle.setVisibility(hasItems ? View.GONE : View.VISIBLE); + mNavIconContainer.setVisibility(hasItems || !mContentForwardEnabled ? View.GONE + : View.VISIBLE); + mTabsContainer.setVisibility(hasItems && mContentForwardEnabled ? View.VISIBLE + : View.GONE); + mTitle.setVisibility(hasItems || !mContentForwardEnabled ? View.GONE + : View.VISIBLE); mAppSwitchIcon.setImageDrawable(mArrowDropDown); break; case APP_SELECTION: mNavIconContainer.setVisibility(View.GONE); mTabsContainer.setVisibility(View.GONE); - mTitle.setVisibility(View.VISIBLE); + mTitle.setVisibility(mContentForwardEnabled ? View.VISIBLE : View.GONE); mAppSwitchIcon.setImageDrawable(mArrowDropUp); break; } |