Add source
This commit is contained in:
1 parent
6ae4fa1506
commit
a836c6bef6
4 files changed
+94
-14
No files matched your search
@@ -19,6 +19,7 @@ import android.os.AsyncTask;
|
||||
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.network.EhHttpHelper;
|
||||
import com.hippo.network.ResponseCodeException;
|
||||
import com.hippo.util.Utils;
|
||||
|
||||
public class EhClient {
|
||||
@@ -57,39 +58,113 @@ public class EhClient {
|
||||
public Object[] doGetGalleryList(int source, String url) throws Exception {
|
||||
EhHttpHelper ehh = new EhHttpHelper();
|
||||
String body = ehh.get(url);
|
||||
|
||||
final int responseCode = ehh.getResponseCode();
|
||||
if (responseCode >= 400) {
|
||||
throw new ResponseCodeException(responseCode);
|
||||
}
|
||||
|
||||
ListParser parser = new ListParser();
|
||||
parser.parse(body, source);
|
||||
return new Object[]{parser.giArray, parser.pageNum};
|
||||
}
|
||||
|
||||
public static interface EhClientListener {
|
||||
public void onFailure(Exception e);
|
||||
}
|
||||
|
||||
public abstract static class OnGetGalleryListListener implements EhClientListener {
|
||||
public abstract void onSuccess(GalleryInfo[] glArray, int pageNum);
|
||||
}
|
||||
|
||||
private void doBgJob(BgJobHelper bjh) {
|
||||
Utils.execute(false, new AsyncTask<Object, Void, Object[]>() {
|
||||
Utils.execute(false, new AsyncTask<Object, Void, BgJobHelper>() {
|
||||
@Override
|
||||
protected Object[] doInBackground(Object... params) {
|
||||
protected BgJobHelper doInBackground(Object... params) {
|
||||
BgJobHelper bjh = (BgJobHelper) params[0];
|
||||
return new Object[]{bjh.doInBackground(), bjh};
|
||||
bjh.doInBackground();
|
||||
return bjh;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Object[] resultPackage) {
|
||||
Object result = resultPackage[0];
|
||||
BgJobHelper bjh = (BgJobHelper) resultPackage[1];
|
||||
bjh.onPostExecute(result);
|
||||
protected void onPostExecute(BgJobHelper bjh) {
|
||||
bjh.onPostExecute();
|
||||
}
|
||||
}, bjh);
|
||||
}
|
||||
|
||||
private static interface BgJobHelper {
|
||||
public Object doInBackground();
|
||||
private interface BgJobHelper {
|
||||
public void doInBackground();
|
||||
|
||||
public void onPostExecute(Object result);
|
||||
public void onPostExecute();
|
||||
}
|
||||
|
||||
private abstract class SimpleBgJobHelper implements BgJobHelper {
|
||||
|
||||
public interface OnGetGalleryListListener {
|
||||
public void onSuccess(GalleryInfo[] glArray, int pageNum);
|
||||
private EhClientListener mListener;
|
||||
private Exception mException;
|
||||
|
||||
public SimpleBgJobHelper(EhClientListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInBackground() {
|
||||
try {
|
||||
doBgJob();
|
||||
} catch (Exception e) {
|
||||
mException = e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute() {
|
||||
if (mListener != null) {
|
||||
if (mException == null) {
|
||||
doSuccessCallback();
|
||||
} else {
|
||||
mListener.onFailure(mException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void doBgJob() throws Exception;
|
||||
|
||||
public abstract void doSuccessCallback();
|
||||
|
||||
public void onFailure(Exception e);
|
||||
}
|
||||
|
||||
private final class GetGalleryListHelper extends SimpleBgJobHelper {
|
||||
|
||||
private int mSource;
|
||||
private String mUrl;
|
||||
private OnGetGalleryListListener mListener;
|
||||
|
||||
private GalleryInfo[] mGlArray;
|
||||
private int mPageNum;
|
||||
|
||||
public GetGalleryListHelper(int source, String url, OnGetGalleryListListener listener) {
|
||||
super(listener);
|
||||
mSource = source;
|
||||
mUrl = url;
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doBgJob() throws Exception {
|
||||
Object[] objs = doGetGalleryList(mSource, mUrl);
|
||||
mGlArray = (GalleryInfo[]) objs[0];
|
||||
mPageNum = (int) objs[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doSuccessCallback() {
|
||||
mListener.onSuccess(mGlArray, mPageNum);
|
||||
}
|
||||
}
|
||||
|
||||
public void getGalleryList(int source, String url, OnGetGalleryListListener listener) {
|
||||
doBgJob(new GetGalleryListHelper(source, url, listener));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import android.os.Bundle;
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class StartActivity extends AbsActionBarActivity {
|
||||
|
||||
private static final String TAG = StartActivity.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
@@ -17,11 +17,11 @@ package com.hippo.network;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.hippo.util.FastByteArrayOutputStream;
|
||||
import com.hippo.util.Log;
|
||||
import com.hippo.util.Utils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
Reference in new issue
Block a user