[Android] Improve Playlist view behavior depending on cover
Geoffrey Métais
git at videolan.org
Fri Feb 10 18:04:50 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Feb 10 16:53:55 2017 +0100| [fe0377fb318a0af5f15b89bf37017a8019554ee0] | committer: Geoffrey Métais
Improve Playlist view behavior depending on cover
> https://code.videolan.org/videolan/vlc-android/commit/fe0377fb318a0af5f15b89bf37017a8019554ee0
---
vlc-android/res/layout/playlist_activity.xml | 5 +-
.../src/org/videolan/vlc/gui/PlaylistActivity.java | 61 ++++++++++++++++------
2 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/vlc-android/res/layout/playlist_activity.xml b/vlc-android/res/layout/playlist_activity.xml
index 03cfb79..f796c32 100644
--- a/vlc-android/res/layout/playlist_activity.xml
+++ b/vlc-android/res/layout/playlist_activity.xml
@@ -18,7 +18,6 @@
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="200dp"
- vlc:theme="@style/Toolbar.VLC"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
@@ -26,10 +25,11 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true"
vlc:title="@{playlist.title}"
+ vlc:theme="@style/Toolbar.VLC"
vlc:contentScrim="?attr/background_actionbar"
vlc:expandedTitleMarginEnd="64dp"
vlc:expandedTitleMarginStart="48dp"
- vlc:layout_scrollFlags="scroll|enterAlways" >
+ vlc:layout_scrollFlags="scroll|exitUntilCollapsed" >
<ImageView
android:id="@+id/playlist_cover"
android:layout_width="match_parent"
@@ -43,6 +43,7 @@
android:layout_height="?attr/actionBarSize"
vlc:navigationContentDescription="@string/abc_action_bar_up_description"
vlc:popupTheme="?attr/toolbar_popup_style"
+ vlc:theme="@style/Toolbar.VLC"
vlc:navigationIcon="?attr/homeAsUpIndicator"
vlc:titleMarginStart="@dimen/default_margin"
vlc:layout_scrollFlags="scroll|enterAlways"
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index c4845e1..3f9e8e7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -34,11 +34,15 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialogFragment;
+import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.FragmentManager;
+import android.support.v4.view.ViewCompat;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
import android.view.ContextMenu;
+import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -54,7 +58,7 @@ import org.videolan.vlc.gui.audio.AudioBrowserAdapter;
import org.videolan.vlc.gui.audio.AudioBrowserFragment;
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
import org.videolan.vlc.gui.helpers.AudioUtil;
-import org.videolan.vlc.gui.helpers.BitmapCache;
+import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
import org.videolan.vlc.interfaces.IEventsHandler;
@@ -91,29 +95,52 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
getIntent().getParcelableExtra(AudioBrowserFragment.TAG_ITEM));
mBinding.setPlaylist(mPlaylist);
mAdapter = new AudioBrowserAdapter(this, MediaLibraryItem.TYPE_MEDIA, this, false);
- mBinding.setCover(new BitmapDrawable(getResources(), BitmapCache.getFromResource(getResources(), R.drawable.background_cone)));
mBinding.songs.setLayoutManager(new LinearLayoutManager(this));
mBinding.songs.setAdapter(mAdapter);
+ mBinding.appbar.setExpanded(false);
+ ViewCompat.setNestedScrollingEnabled(mBinding.songs, false);
- VLCApplication.runBackground(new Runnable() {
- @Override
- public void run() {
- int width;
- if (AndroidUtil.isHoneycombMr2OrLater()) {
- Point point = new Point();
- getWindowManager().getDefaultDisplay().getSize(point);
- width = point.x;
- } else
- width = getWindowManager().getDefaultDisplay().getWidth();
- final Bitmap cover = AudioUtil.readCoverBitmap(Strings.removeFileProtocole(Uri.decode(mPlaylist.getArtworkMrl())), width);
- if (cover != null)
- mBinding.setCover(new BitmapDrawable(PlaylistActivity.this.getResources(), cover));
- }
- });
+ if (!TextUtils.isEmpty(mPlaylist.getArtworkMrl())) {
+ VLCApplication.runBackground(new Runnable() {
+ @Override
+ public void run() {
+ int width;
+ if (AndroidUtil.isHoneycombMr2OrLater()) {
+ Point point = new Point();
+ getWindowManager().getDefaultDisplay().getSize(point);
+ width = point.x;
+ } else
+ width = getWindowManager().getDefaultDisplay().getWidth();
+ final Bitmap cover = AudioUtil.readCoverBitmap(Strings.removeFileProtocole(Uri.decode(mPlaylist.getArtworkMrl())), width);
+ if (cover != null) {
+ mBinding.setCover(new BitmapDrawable(PlaylistActivity.this.getResources(), cover));
+ VLCApplication.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mBinding.songs.setNestedScrollingEnabled(true);
+ mBinding.appbar.setExpanded(true, true);
+ }
+ });
+ } else
+ fabFallback();
+ }
+ });
+ } else
+ fabFallback();
mBinding.fab.setOnClickListener(this);
}
+ private void fabFallback() {
+ CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) mBinding.fab.getLayoutParams();
+ lp.setAnchorId(mBinding.songs.getId());
+ lp.anchorGravity = Gravity.BOTTOM|Gravity.RIGHT|Gravity.END;
+ lp.bottomMargin = getResources().getDimensionPixelSize(R.dimen.default_margin);
+ lp.setBehavior(new FloatingActionButtonBehavior(PlaylistActivity.this, null));
+ mBinding.fab.setLayoutParams(lp);
+ mBinding.fab.setVisibility(View.VISIBLE);
+ }
+
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
More information about the Android
mailing list