package de.eightbitboy.hijacr.data;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.orhanobut.logger.Logger;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

public class ComicFetcher extends AsyncTask<Void, Void, Void> {
	private FragmentActivity activity;
	private ImageView imageView;
	private int comicNumber;
	private ComicData comicData;

	//TODO remove the view from this class
	public ComicFetcher(FragmentActivity activity, ImageView imageView, int comicNumber, ComicData comicData) {
		this.activity = activity;
		this.imageView = imageView;
		this.comicNumber = comicNumber;
		this.comicData = comicData;
	}

	@Override
	protected Void doInBackground(Void... params) {
		try {
			Document page = Jsoup.connect(comicData.getBaseUrl() + comicNumber).get();
			Elements img = page.select(comicData.getImageQuery());
			String imgSrc = img.attr("src");
			imgSrc = "http:" + imgSrc;

			Logger.d("Image url: " + imgSrc.toString());

			final String source = imgSrc;
			activity.runOnUiThread(new Runnable() {
				@Override
				public void run() {
					fetchImage(source, imageView);
				}
			});
		} catch (IOException e) {
			Logger.e("Fetching the image failed!");
			e.printStackTrace();
		}

		return null;
	}

	private void fetchImage(String imageUrl, ImageView imageView) {
		ImageLoader.getInstance().displayImage(imageUrl, imageView);

		/*
		ImageLoader.getInstance().loadImage(imageUrl, new SimpleImageLoadingListener() {
			@Override
			public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
				// Do whatever you want with Bitmap
			}
		});
		*/
	}
}

@@ -912,16 +912,235 @@
 rams) %7B%0A
+%09%09final String imageUrl = getImageUrl();%0A%09%09activity.runOnUiThread(new Runnable() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09fetchImage(imageUrl, imageView);%0A%09%09%09%7D%0A%09%09%7D);%0A%0A%09%09return null;%0A%09%7D%0A%0A%09private String getImageUrl() %7B%0A
 %09%09try %7B%0A
@@ -1398,166 +1398,21 @@
 %0A%09%09%09
-final String source = imgSrc;%0A%09%09%09activity.runOnUiThread(new Runnable() %7B%0A%09%09%09%09@Override%0A%09%09%09%09public void run() %7B%0A%09%09%09%09%09fetchImage(source, imageView);%0A%09%09%09%09%7D%0A%09%09%09%7D)
+return imgSrc
 ;%0A%09%09

Improve code structure