Commit 8defda73 authored by Geoffrey Métais's avatar Geoffrey Métais

Get drawables with UI context

parent 7d40ed44
......@@ -97,7 +97,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
getIntent().getParcelableExtra(AudioBrowserFragment.TAG_ITEM));
mIsPlaylist = mPlaylist.getItemType() == MediaLibraryItem.TYPE_PLAYLIST;
mBinding.setPlaylist(mPlaylist);
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, false);
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, false, getResources());
mBinding.songs.setLayoutManager(new LinearLayoutManager(this));
mBinding.songs.setAdapter(mAdapter);
......
......@@ -30,7 +30,7 @@ public class SearchResultAdapter extends RecyclerView.Adapter<SearchResultAdapte
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
if (TextUtils.isEmpty(mDataList[position].getArtworkMrl()))
holder.binding.setCover(UiTools.getDefaultCover(mDataList[position]));
holder.binding.setCover(UiTools.getDefaultCover(holder.itemView.getResources(), mDataList[position]));
holder.binding.setItem(mDataList[position]);
}
......
......@@ -120,8 +120,8 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
mLists = new ContextMenuRecyclerView[]{albumsList, songsList};
String[] titles = new String[] {getString(R.string.albums), getString(R.string.songs)};
mAlbumsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_ALBUM, this, true);
mSongsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, true);
mAlbumsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_ALBUM, this, true, getResources());
mSongsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, true, getResources());
mAlbumsAdapter.setParentAdapterType(mItem.getItemType());
mSongsAdapter.setParentAdapterType(mItem.getItemType());
mAdapters = new AudioBrowserAdapter[]{mAlbumsAdapter, mSongsAdapter};
......
......@@ -24,6 +24,7 @@
package org.videolan.vlc.gui.audio;
import android.content.Context;
import android.content.res.Resources;
import android.databinding.ViewDataBinding;
import android.graphics.drawable.BitmapDrawable;
import android.support.annotation.MainThread;
......@@ -47,6 +48,7 @@ import org.videolan.vlc.databinding.AudioBrowserItemBinding;
import org.videolan.vlc.databinding.AudioBrowserSeparatorBinding;
import org.videolan.vlc.gui.helpers.AsyncImageLoader;
import org.videolan.vlc.gui.helpers.SelectorViewHolder;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.FastScroller;
import org.videolan.vlc.interfaces.IEventsHandler;
import org.videolan.vlc.util.MediaItemFilter;
......@@ -75,11 +77,11 @@ public class AudioBrowserAdapter extends SortableAdapter<MediaLibraryItem, Audio
private int mParentType = 0;
private BitmapDrawable mDefaultCover;
public AudioBrowserAdapter(int type, IEventsHandler eventsHandler, boolean sections) {
public AudioBrowserAdapter(int type, IEventsHandler eventsHandler, boolean sections, Resources res) {
mIEventsHandler = eventsHandler;
mMakeSections = sections;
mType = type;
mDefaultCover = getIconDrawable();
mDefaultCover = getIconDrawable(res);
}
public int getAdapterType() {
......@@ -393,14 +395,14 @@ public class AudioBrowserAdapter extends SortableAdapter<MediaLibraryItem, Audio
mSelectionCount += selected ? 1 : -1;
}
private BitmapDrawable getIconDrawable() {
private BitmapDrawable getIconDrawable(Resources res) {
switch (mType) {
case MediaLibraryItem.TYPE_ALBUM:
return AsyncImageLoader.DEFAULT_COVER_ALBUM_DRAWABLE;
return UiTools.Resources.getAlbum(res);
case MediaLibraryItem.TYPE_ARTIST:
return AsyncImageLoader.DEFAULT_COVER_ARTIST_DRAWABLE;
return UiTools.Resources.getArtist(res);
case MediaLibraryItem.TYPE_MEDIA:
return AsyncImageLoader.DEFAULT_COVER_AUDIO_DRAWABLE;
return UiTools.Resources.getAudio(res);
default:
return null;
}
......
......@@ -23,6 +23,7 @@ package org.videolan.vlc.gui.audio;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
......@@ -103,11 +104,12 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSongsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, true);
mArtistsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_ARTIST, this, true);
mAlbumsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_ALBUM, this, true);
mGenresAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_GENRE, this, true);
mPlaylistAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, true);
final Resources res = getResources();
mSongsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, true, res);
mArtistsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_ARTIST, this, true, res);
mAlbumsAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_ALBUM, this, true, res);
mGenresAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_GENRE, this, true, res);
mPlaylistAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, true, res);
mAdapters = new AudioBrowserAdapter[]{mArtistsAdapter, mAlbumsAdapter, mSongsAdapter, mGenresAdapter, mPlaylistAdapter};
}
......
......@@ -504,7 +504,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (v instanceof TextView) ((TextView) v).setTextColor(v.hasFocus() ? UiTools.Resources.ITEM_FOCUS_ON : mTextColor);
if (v instanceof TextView) ((TextView) v).setTextColor(v.hasFocus() ? UiTools.Resources.getFocusOnColor(v.getContext()) : mTextColor);
mToast.setText(mAdapter.getSelectedAdvOptionHelp());
mToast.show();
}
......
......@@ -80,7 +80,7 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMedialibrary = VLCApplication.getMLInstance();
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, false);
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, false, getResources());
mTracks = (MediaWrapper[]) getArguments().getParcelableArray(KEY_TRACKS);
mNewTrack = (MediaWrapper[]) getArguments().getParcelableArray(KEY_NEW_TRACKS);
}
......
......@@ -42,7 +42,6 @@ import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BR;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.media.MediaGroup;
import org.videolan.vlc.util.HttpImageLoader;
......@@ -57,13 +56,6 @@ public class AsyncImageLoader {
public final static String TAG = "VLC/AsyncImageLoader";
public static final Bitmap DEFAULT_COVER_VIDEO = BitmapCache.getFromResource(VLCApplication.getAppResources(), R.drawable.ic_no_thumbnail_1610);
public static final BitmapDrawable DEFAULT_COVER_VIDEO_DRAWABLE = new BitmapDrawable(VLCApplication.getAppResources(), DEFAULT_COVER_VIDEO);
public static final Bitmap DEFAULT_COVER_AUDIO = BitmapCache.getFromResource(VLCApplication.getAppResources(), R.drawable.ic_no_song);
public static final BitmapDrawable DEFAULT_COVER_AUDIO_DRAWABLE = new BitmapDrawable(VLCApplication.getAppResources(), DEFAULT_COVER_AUDIO);
public static final BitmapDrawable DEFAULT_COVER_ARTIST_DRAWABLE = new BitmapDrawable(VLCApplication.getAppResources(), BitmapCache.getFromResource(VLCApplication.getAppResources(), R.drawable.ic_no_artist));
public static final BitmapDrawable DEFAULT_COVER_ALBUM_DRAWABLE = new BitmapDrawable(VLCApplication.getAppResources(), BitmapCache.getFromResource(VLCApplication.getAppResources(), R.drawable.ic_no_album));
private static final BitmapCache sBitmapCache = BitmapCache.getInstance();
private static final Medialibrary sMedialibrary = VLCApplication.getMLInstance();
......
......@@ -43,8 +43,7 @@ public class SelectorViewHolder<T extends ViewDataBinding> extends RecyclerView.
}
private void setViewBackground(boolean focus, boolean selected) {
final int color = focus ? UiTools.Resources.ITEM_FOCUS_ON : selected ? UiTools.Resources.ITEM_SELECTION_ON : UiTools.Resources.ITEM_FOCUS_OFF;
binding.setVariable(BR.bgColor, color);
binding.setVariable(BR.bgColor, UiTools.Resources.getItemBgColor(itemView.getContext(), focus, selected));
}
@Override
......
......@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.databinding.BindingAdapter;
import android.graphics.Bitmap;
......@@ -44,6 +45,7 @@ import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
......@@ -88,9 +90,64 @@ public class UiTools {
private static final String TAG = "VLC/UiTools";
public static class Resources {
public static final int ITEM_FOCUS_OFF = ContextCompat.getColor(VLCApplication.getAppContext(), R.color.transparent);
public static final int ITEM_FOCUS_ON = ContextCompat.getColor(VLCApplication.getAppContext(), R.color.orange500transparent);
public static final int ITEM_SELECTION_ON = ContextCompat.getColor(VLCApplication.getAppContext(), R.color.orange200transparent);
private static int ITEM_FOCUS_OFF = 0;
private static int ITEM_FOCUS_ON = 0;
private static int ITEM_SELECTION_ON = 0;
private static BitmapDrawable DEFAULT_COVER_VIDEO_DRAWABLE;
private static BitmapDrawable DEFAULT_COVER_AUDIO_DRAWABLE;
private static BitmapDrawable DEFAULT_COVER_ARTIST_DRAWABLE;
private static BitmapDrawable DEFAULT_COVER_ALBUM_DRAWABLE;
public static int getFocusOnColor(Context ctx) {
if (ITEM_FOCUS_ON == 0) ITEM_FOCUS_ON = ContextCompat.getColor(ctx, R.color.orange500transparent);
return ITEM_FOCUS_ON;
}
@MainThread
public static int getItemBgColor(Context ctx, boolean focus, boolean selected) {
if (focus) {
return getFocusOnColor(ctx);
} else if (selected) {
if (ITEM_SELECTION_ON == 0) ITEM_SELECTION_ON = ContextCompat.getColor(ctx, R.color.orange200transparent);
return ITEM_SELECTION_ON;
} else {
if (ITEM_FOCUS_OFF == 0) ITEM_FOCUS_OFF = ContextCompat.getColor(ctx, R.color.transparent);
return ITEM_FOCUS_OFF;
}
}
@MainThread
public static BitmapDrawable getVideo(android.content.res.Resources res) {
if (DEFAULT_COVER_VIDEO_DRAWABLE == null) {
DEFAULT_COVER_VIDEO_DRAWABLE = new BitmapDrawable(res, BitmapCache.getFromResource(res, R.drawable.ic_no_thumbnail_1610));
}
return DEFAULT_COVER_VIDEO_DRAWABLE;
}
@MainThread
public static BitmapDrawable getAudio(android.content.res.Resources res) {
if (DEFAULT_COVER_AUDIO_DRAWABLE == null) {
DEFAULT_COVER_AUDIO_DRAWABLE = new BitmapDrawable(res, BitmapCache.getFromResource(res, R.drawable.ic_no_song));
}
return DEFAULT_COVER_AUDIO_DRAWABLE;
}
@MainThread
public static BitmapDrawable getArtist(android.content.res.Resources res) {
if (DEFAULT_COVER_ARTIST_DRAWABLE == null) {
DEFAULT_COVER_ARTIST_DRAWABLE = new BitmapDrawable(res, BitmapCache.getFromResource(res, R.drawable.ic_no_artist));
}
return DEFAULT_COVER_ARTIST_DRAWABLE;
}
@MainThread
public static BitmapDrawable getAlbum(android.content.res.Resources res) {
if (DEFAULT_COVER_ALBUM_DRAWABLE == null) {
DEFAULT_COVER_ALBUM_DRAWABLE = new BitmapDrawable(res, BitmapCache.getFromResource(res, R.drawable.ic_no_album));
}
return DEFAULT_COVER_ALBUM_DRAWABLE;
}
}
private static final Handler sHandler = new Handler(Looper.getMainLooper());
......@@ -259,17 +316,17 @@ public class UiTools {
throw new IllegalThreadStateException();
}
public static BitmapDrawable getDefaultCover(MediaLibraryItem item) {
public static BitmapDrawable getDefaultCover(android.content.res.Resources res, MediaLibraryItem item) {
switch (item.getItemType()) {
case MediaLibraryItem.TYPE_ARTIST:
return AsyncImageLoader.DEFAULT_COVER_ARTIST_DRAWABLE;
return Resources.getArtist(res);
case MediaLibraryItem.TYPE_ALBUM:
return AsyncImageLoader.DEFAULT_COVER_ALBUM_DRAWABLE;
return Resources.getAlbum(res);
case MediaLibraryItem.TYPE_MEDIA:
if (((MediaWrapper)item).getType() == MediaWrapper.TYPE_VIDEO)
return AsyncImageLoader.DEFAULT_COVER_VIDEO_DRAWABLE;
return Resources.getVideo(res);
default:
return AsyncImageLoader.DEFAULT_COVER_AUDIO_DRAWABLE;
return Resources.getAudio(res);
}
}
......
......@@ -20,11 +20,13 @@
package org.videolan.vlc.gui.video;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Build;
import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
......@@ -46,6 +48,7 @@ import org.videolan.vlc.SortableAdapter;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.AsyncImageLoader;
import org.videolan.vlc.gui.helpers.SelectorViewHolder;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.interfaces.IEventsHandler;
import org.videolan.vlc.media.MediaGroup;
import org.videolan.vlc.util.MediaItemDiffCallback;
......@@ -130,7 +133,7 @@ public class VideoListAdapter extends SortableAdapter<MediaWrapper, VideoListAda
@Override
public void onViewRecycled(ViewHolder holder) {
holder.binding.setVariable(BR.cover, AsyncImageLoader.DEFAULT_COVER_VIDEO_DRAWABLE);
holder.binding.setVariable(BR.cover, UiTools.Resources.getVideo(holder.itemView.getResources()));
}
public boolean isEmpty() {
......@@ -289,11 +292,12 @@ public class VideoListAdapter extends SortableAdapter<MediaWrapper, VideoListAda
public class ViewHolder extends SelectorViewHolder<ViewDataBinding> implements View.OnFocusChangeListener {
private ImageView thumbView;
@TargetApi(Build.VERSION_CODES.M)
public ViewHolder(ViewDataBinding binding) {
super(binding);
thumbView = itemView.findViewById(R.id.ml_item_thumbnail);
binding.setVariable(BR.holder, this);
binding.setVariable(BR.cover, AsyncImageLoader.DEFAULT_COVER_VIDEO_DRAWABLE);
binding.setVariable(BR.cover, UiTools.Resources.getVideo(binding.getRoot().getResources()));
if (AndroidUtil.isMarshMallowOrLater) itemView.setOnContextClickListener(new View.OnContextClickListener() {
@Override
public boolean onContextClick(View v) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment