Commit 1f1a1411 authored by Geoffrey Métais's avatar Geoffrey Métais

Adapt async loading to data binding

parent 2895e770
......@@ -24,8 +24,12 @@
package org.videolan.vlc.gui;
import android.app.Activity;
import android.databinding.ViewDataBinding;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.graphics.drawable.BitmapDrawable;
import org.videolan.vlc.BR;
import org.videolan.vlc.VLCApplication;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
......@@ -38,30 +42,27 @@ public class AsyncImageLoader {
static ExecutorService executor = Executors.newSingleThreadExecutor();
public static void LoadImage(Callable<Bitmap> loader, final ImageView view, Activity activity){
public static void LoadImage(Callable<Bitmap> loader, final ViewDataBinding binding, Activity activity){
Future<Bitmap> future = executor.submit(loader);
handleImage(view, activity, future);
handleImage(binding, activity, future);
}
private static void handleImage(final ImageView view, final Activity activity, final Future<Bitmap> future) {
private static void handleImage(final ViewDataBinding binding, final Activity activity, final Future<Bitmap> future) {
new Thread(new Runnable() {
@Override
public void run() {
try {
final Bitmap bitmap = future.get();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
view.post(new Runnable() {
@Override
public void run() {
view.setImageBitmap(bitmap);
}
});
}
});
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
binding.setVariable(BR.cover, new BitmapDrawable(VLCApplication.getAppResources(), bitmap));
binding.executePendingBindings();
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
......
......@@ -26,18 +26,12 @@ import android.content.SharedPreferences;
import android.database.DataSetObserver;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v4.util.ArrayMap;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.SectionIndexer;
......@@ -46,9 +40,8 @@ import android.widget.TextView;
import org.videolan.vlc.BR;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.interfaces.IAudioClickHandler;
import org.videolan.vlc.gui.AsyncImageLoader;
import org.videolan.vlc.util.BitmapCache;
import org.videolan.vlc.interfaces.IAudioClickHandler;
import org.videolan.vlc.util.Util;
import java.util.ArrayList;
......@@ -58,7 +51,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Callable;
public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndexer, IAudioClickHandler {
public final static String TAG = "VLC/AudioBrowserListAdapter";
......@@ -337,9 +329,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
if (mItemType == ITEM_WITH_COVER) {
AudioUtil.AudioCoverFetcher fetcher = new AudioUtil.AudioCoverFetcher(mContext, mItems.get(position).mMediaList);
AsyncImageLoader.LoadImage(fetcher, holder.cover, mContext);
//TODO
//holder.binding.setVariable(BR.cover, new BitmapDrawable(mContext.getResources(), cover));
AsyncImageLoader.LoadImage(fetcher, holder.binding, mContext);
}
holder.binding.setVariable(BR.footer, !isMediaItemAboveASeparator(position));
......
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