[Android] Visual selection for audio
Geoffrey Métais
git at videolan.org
Thu Nov 17 17:59:56 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 17 17:59:16 2016 +0100| [684cc2f77a16f674f657ebc5224c3551f76b19e1] | committer: Geoffrey Métais
Visual selection for audio
> https://code.videolan.org/videolan/vlc-android/commit/684cc2f77a16f674f657ebc5224c3551f76b19e1
---
vlc-android/res/layout/audio_browser_item.xml | 23 ++++++++++------
.../vlc/gui/audio/AudioBrowserAdapter.java | 32 ++++++++++++++++------
2 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index d472afb..87675aa 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -37,18 +37,20 @@
android:layout_gravity="center"
vlc:media="@{item}"
vlc:binding="@{holder.vdb}"
- android:src="@{cover}" />
+ android:background="@{cover}" />
<LinearLayout
+ android:id="@+id/audio_item_meta"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_alignTop="@+id/media_cover"
+ android:layout_alignBottom="@+id/media_cover"
android:layout_toRightOf="@+id/media_cover"
android:layout_toEndOf="@+id/media_cover"
android:layout_toLeftOf="@+id/item_more"
android:layout_toStartOf="@+id/item_more"
android:paddingLeft="15dp"
android:paddingStart="15dp"
- android:layout_centerVertical="true"
android:orientation="vertical" >
<!-- TextView must be set to singleLine
@@ -56,8 +58,10 @@
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_height="0dp"
+ android:layout_weight="1"
android:singleLine="true"
+ android:gravity="center_vertical"
android:ellipsize="end"
vlc:alignMode="@{alignMode}"
android:text="@{item.title}"
@@ -68,7 +72,8 @@
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_height="0dp"
+ android:layout_weight="1"
android:singleLine="true"
android:ellipsize="middle"
android:text="@{item.description}"
@@ -80,11 +85,13 @@
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
+ android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
- android:background="@drawable/ic_more"
+ android:layout_alignTop="@+id/media_cover"
+ android:layout_alignBottom="@+id/media_cover"
+ android:scaleType="center"
+ android:src="@drawable/ic_more"
android:contentDescription="@string/more_actions"
android:onClick="@{holder::onMoreClick}" />
</RelativeLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index 138adb7..0f1cc33 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -3,6 +3,7 @@ package org.videolan.vlc.gui.audio;
import android.app.Activity;
import android.content.Context;
import android.databinding.ViewDataBinding;
+import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
@@ -10,10 +11,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
+import android.widget.ImageView;
import org.videolan.medialibrary.media.DummyItem;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.vlc.BR;
+import org.videolan.vlc.R;
import org.videolan.vlc.databinding.AudioBrowserItemBinding;
import org.videolan.vlc.databinding.AudioBrowserSeparatorBinding;
import org.videolan.vlc.gui.helpers.AsyncImageLoader;
@@ -71,8 +74,9 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
holder.vdb.setVariable(BR.item, mDataList.get(position));
if (holder.getType() == MediaLibraryItem.TYPE_MEDIA) {
holder.vdb.setVariable(BR.cover, AsyncImageLoader.DEFAULT_COVER_AUDIO_DRAWABLE);
- boolean isSelected = mActionMode && mSelectedItems.contains(position);
- ((MediaItemViewHolder)holder).setViewBackground(((MediaItemViewHolder) holder).itemView.hasFocus() || isSelected);
+ boolean isSelected = mActionMode && mSelectedItems.contains(position);
+ ((MediaItemViewHolder)holder).setCoverlay(isSelected);
+ ((MediaItemViewHolder)holder).setViewBackground(((MediaItemViewHolder) holder).itemView.hasFocus(), isSelected);
}
}
@@ -249,12 +253,17 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
}
public class MediaItemViewHolder extends ViewHolder implements View.OnLongClickListener, View.OnFocusChangeListener {
+ private ImageView coverView;
+ private View contentLayout, ctxButton;
MediaItemViewHolder(AudioBrowserItemBinding binding) {
super(binding);
binding.setHolder(this);
itemView.setOnLongClickListener(this);
itemView.setOnFocusChangeListener(this);
+ coverView = binding.mediaCover;
+ contentLayout = binding.audioItemMeta;
+ ctxButton = binding.itemMore;
}
public void onClick(View v) {
@@ -289,7 +298,12 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
mSelectedItems.add(position);
else
mSelectedItems.remove(position);
- setViewBackground(itemView.hasFocus() || mSelectedItems.contains(position));
+ setCoverlay(mSelectedItems.contains(position));
+ setViewBackground(itemView.hasFocus(), selected);
+ }
+
+ private void setCoverlay(boolean selected) {
+ coverView.setImageResource(selected ? R.drawable.ic_action_mode_select : 0);
}
public int getType() {
@@ -298,14 +312,14 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
@Override
public void onFocusChange(View v, boolean hasFocus) {
- setViewBackground(hasFocus || mSelectedItems.contains(getLayoutPosition()));
+ setViewBackground(hasFocus, mSelectedItems.contains(getLayoutPosition()));
}
- private void setViewBackground(boolean highlight) {
- if (highlight)
- itemView.setBackgroundColor(UiTools.ITEM_FOCUS_ON);
- else
- itemView.setBackgroundColor(UiTools.ITEM_FOCUS_OFF);
+ private void setViewBackground(boolean focused, boolean selected) {
+ itemView.setBackgroundColor(focused ? UiTools.ITEM_FOCUS_ON : UiTools.ITEM_FOCUS_OFF);
+ int selectionColor = selected ? ContextCompat.getColor(itemView.getContext(), R.color.orange200transparent) : 0;
+ contentLayout.setBackgroundColor(selectionColor);
+ ctxButton.setBackgroundColor(selectionColor);
}
}
More information about the Android
mailing list