Browse Source

Fixed a threading bug in ImageDownloadTask

master
Anthony Restaino 8 years ago
parent
commit
5711421784
  1. 19
      app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java

19
app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java

@ -10,6 +10,8 @@ import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
import com.anthonycr.bonsai.Schedulers;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@ -146,17 +148,12 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
final Bitmap fav = Utils.padFavicon(bitmap); final Bitmap fav = Utils.padFavicon(bitmap);
final ImageView view = mFaviconImage.get(); final ImageView view = mFaviconImage.get();
if (view != null && view.getTag().equals(mWeb.getUrl().hashCode())) { if (view != null && view.getTag().equals(mWeb.getUrl().hashCode())) {
Context context = view.getContext(); Schedulers.main().execute(new Runnable() {
if (context instanceof Activity) { @Override
((Activity) context).runOnUiThread(new Runnable() { public void run() {
@Override view.setImageBitmap(fav);
public void run() { }
view.setImageBitmap(fav); });
}
});
} else {
view.setImageBitmap(fav);
}
} }
mWeb.setBitmap(fav); mWeb.setBitmap(fav);
} }

Loading…
Cancel
Save