[Android] TV: Fix image loading

Geoffrey Métais git at videolan.org
Fri Mar 4 15:18:26 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar  4 15:17:46 2016 +0100| [40452acea8312d10a477049d7d4ae4746a181035] | committer: Geoffrey Métais

TV: Fix image loading

> https://code.videolan.org/videolan/vlc-android/commit/40452acea8312d10a477049d7d4ae4746a181035
---

 vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java | 13 +++++++++----
 vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java |  5 ++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java b/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java
index 45f8c56..444bdd2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.java
@@ -81,8 +81,13 @@ public class CardPresenter extends Presenter {
         }
 
         protected void updateCardViewImage(MediaWrapper mediaWrapper) {
-            mCardView.getMainImageView().setScaleType(ImageView.ScaleType.CENTER);
-            AsyncImageLoader.LoadImage(new CoverFetcher(mContext, mediaWrapper), mCardView);
+            if (!TextUtils.isEmpty(mediaWrapper.getArtworkURL()) && mediaWrapper.getArtworkURL().startsWith("http")) {
+                mCardView.getMainImageView().setScaleType(ImageView.ScaleType.FIT_CENTER);
+                AsyncImageLoader.LoadImage(new HttpImageLoader(mediaWrapper.getArtworkURL()), mCardView);
+            } else {
+                mCardView.getMainImageView().setScaleType(mediaWrapper.getType() == MediaWrapper.TYPE_DIR ? ImageView.ScaleType.CENTER : ImageView.ScaleType.CENTER_CROP);
+                AsyncImageLoader.LoadImage(new CoverFetcher(mContext, mediaWrapper), mCardView);
+            }
         }
 
         protected void updateCardViewImage(Drawable image) {
@@ -124,9 +129,11 @@ public class CardPresenter extends Presenter {
             SimpleCard card = (SimpleCard) item;
             Bitmap image = card.getImage();
             holder.mCardView.setTitleText(card.getName());
+            holder.mCardView.setContentText("");
             holder.updateCardViewImage(image != null ? new BitmapDrawable(image) : mRes.getDrawable(card.getImageId()));
         }else if (item instanceof String){
             holder.mCardView.setTitleText((String) item);
+            holder.mCardView.setContentText("");
             holder.updateCardViewImage(sDefaultCardImage);
         }
     }
@@ -238,8 +245,6 @@ public class CardPresenter extends Presenter {
 
         @Override
         public void updateImage(final Bitmap picture, final View target) {
-            if (!TextUtils.isEmpty(mediaWrapper.getArtworkURL()) && mediaWrapper.getArtworkURL().startsWith("http"))
-                AsyncImageLoader.LoadImage(new HttpImageLoader(mediaWrapper.getArtworkURL()), target);
             sHandler.post(
                     new Runnable() {
                         @Override
diff --git a/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java b/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java
index 8ad8185..9a664ca 100644
--- a/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java
@@ -29,6 +29,8 @@ import android.databinding.ViewDataBinding;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
+import android.os.Handler;
+import android.os.Looper;
 import android.support.v17.leanback.widget.ImageCardView;
 import android.support.v4.util.SimpleArrayMap;
 import android.view.View;
@@ -54,6 +56,7 @@ public class HttpImageLoader implements Callbacks {
     private ViewDataBinding mBinding;
     private boolean bindChanged = false;
     final OnRebindCallback<ViewDataBinding> rebindCallbacks;
+    private static final Handler sHandler = new Handler(Looper.getMainLooper());
 
     public HttpImageLoader(String imageLink) {
         mImageLink = imageLink;
@@ -127,7 +130,7 @@ public class HttpImageLoader implements Callbacks {
                 }
             }
         } else if (bitmap != null && (bitmap.getWidth() != 1 && bitmap.getHeight() != 1)) {
-            target.post(new Runnable() {
+            sHandler.post(new Runnable() {
                 @Override
                 public void run() {
                     if (target instanceof ImageCardView)



More information about the Android mailing list