Commit b0cc218a authored by Geoffrey Métais's avatar Geoffrey Métais

Update Extensions display

parent 29e7bab3
package org.videolan.vlc.gui.browser; package org.videolan.vlc.gui.browser;
import android.content.res.Resources;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri; import android.net.Uri;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.databinding.ExtensionItemViewBinding; import org.videolan.vlc.databinding.ExtensionItemViewBinding;
import org.videolan.vlc.extensions.api.VLCExtensionItem; import org.videolan.vlc.extensions.api.VLCExtensionItem;
import org.videolan.vlc.gui.helpers.AsyncImageLoader;
import org.videolan.vlc.media.MediaUtils; import org.videolan.vlc.media.MediaUtils;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.util.HttpImageLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.ViewHolder> { public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.ViewHolder> {
private static final String TAG = "VLC/ExtensionAdapter";
ExtensionBrowser mFragment; ExtensionBrowser mFragment;
List<VLCExtensionItem> mItemsList = new ArrayList<>(); List<VLCExtensionItem> mItemsList = new ArrayList<>();
...@@ -34,7 +29,6 @@ public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.View ...@@ -34,7 +29,6 @@ public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.View
public ViewHolder(ExtensionItemViewBinding binding) { public ViewHolder(ExtensionItemViewBinding binding) {
super(binding.getRoot()); super(binding.getRoot());
this.binding = binding; this.binding = binding;
itemView.setOnLongClickListener(this);
binding.setHolder(this); binding.setHolder(this);
} }
...@@ -79,14 +73,9 @@ public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.View ...@@ -79,14 +73,9 @@ public class ExtensionAdapter extends RecyclerView.Adapter<ExtensionAdapter.View
@Override @Override
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
final ViewHolder vh = holder;
final VLCExtensionItem item = getItem(position); final VLCExtensionItem item = getItem(position);
vh.binding.setItem(item); holder.binding.setItem(item);
vh.binding.executePendingBindings(); holder.binding.executePendingBindings();
Resources res = holder.itemView.getContext().getResources();
vh.binding.setImage(new BitmapDrawable(res, BitmapFactory.decodeResource(res, getIconResId(item))));
if (item.imageUri != null && (TextUtils.equals("http", item.imageUri.getScheme())))
AsyncImageLoader.LoadImage(new HttpImageLoader(item.getImageUri().toString(), holder.binding), null);
} }
private int getIconResId(VLCExtensionItem item) { private int getIconResId(VLCExtensionItem item) {
......
...@@ -7,7 +7,6 @@ import android.os.Message; ...@@ -7,7 +7,6 @@ import android.os.Message;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -18,7 +17,6 @@ import android.widget.TextView; ...@@ -18,7 +17,6 @@ import android.widget.TextView;
import org.videolan.medialibrary.media.MediaWrapper; import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.extensions.ExtensionListing; import org.videolan.vlc.extensions.ExtensionListing;
import org.videolan.vlc.extensions.ExtensionManagerService; import org.videolan.vlc.extensions.ExtensionManagerService;
import org.videolan.vlc.extensions.Utils; import org.videolan.vlc.extensions.Utils;
...@@ -49,7 +47,6 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener, ...@@ -49,7 +47,6 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener,
private FloatingActionButton mAddDirectoryFAB; private FloatingActionButton mAddDirectoryFAB;
private ExtensionAdapter mAdapter; private ExtensionAdapter mAdapter;
protected ContextMenuRecyclerView mRecyclerView; protected ContextMenuRecyclerView mRecyclerView;
protected LinearLayoutManager mLayoutManager;
protected TextView mEmptyView; protected TextView mEmptyView;
protected SwipeRefreshLayout mSwipeRefreshLayout; protected SwipeRefreshLayout mSwipeRefreshLayout;
...@@ -85,9 +82,7 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener, ...@@ -85,9 +82,7 @@ public class ExtensionBrowser extends Fragment implements View.OnClickListener,
mRecyclerView = v.findViewById(R.id.network_list); mRecyclerView = v.findViewById(R.id.network_list);
mEmptyView = v.findViewById(android.R.id.empty); mEmptyView = v.findViewById(android.R.id.empty);
mEmptyView.setText(R.string.extension_empty); mEmptyView.setText(R.string.extension_empty);
mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new DividerItemDecoration(VLCApplication.getAppContext(), DividerItemDecoration.VERTICAL));
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
registerForContextMenu(mRecyclerView); registerForContextMenu(mRecyclerView);
......
...@@ -67,6 +67,8 @@ public class AsyncImageLoader { ...@@ -67,6 +67,8 @@ public class AsyncImageLoader {
@BindingAdapter({"imageUri"}) @BindingAdapter({"imageUri"})
public static void downloadIcon(final View v, final Uri imageUri) { public static void downloadIcon(final View v, final Uri imageUri) {
if (imageUri == null || !imageUri.getScheme().equals("http"))
return;
AsyncImageLoader.LoadImage(new CoverFetcher(null) { AsyncImageLoader.LoadImage(new CoverFetcher(null) {
@Override @Override
public Bitmap getImage() { public Bitmap getImage() {
......
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