diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java index e26cdf3b5..5b6eb0242 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java @@ -56,11 +56,11 @@ public class EhClient { public void execute(EhRequest request) { if (!request.isCancelled()) { - Task task = new Task(request.method, request.callback); - task.executeOnExecutor(mRequestThreadPool, request.args); + Task task = new Task(request.getMethod(), request.getCallback(), request.getEhConfig()); + task.executeOnExecutor(mRequestThreadPool, request.getArgs()); request.task = task; } else { - request.callback.onCancel(); + request.getCallback().onCancel(); } } @@ -68,13 +68,15 @@ public class EhClient { private int mMethod; private Callback mCallback; + private EhConfig mEhConfig; private Call mCall; private boolean mStop; - public Task(int method, Callback callback) { + public Task(int method, Callback callback, EhConfig ehConfig) { mMethod = method; mCallback = callback; + mEhConfig = ehConfig; } public void stop() { @@ -106,8 +108,8 @@ public class EhClient { } } - private Object signIn(Object... params) throws Exception { - Call call = EhEngine.prepareSignIn(mOkHttpClient, (String) params[0], (String) params[1]); + private Object signIn(EhConfig ehConfig, Object... params) throws Exception { + Call call = EhEngine.prepareSignIn(mOkHttpClient, ehConfig, (String) params[0], (String) params[1]); if (!mStop) { mCall = call; return EhEngine.doSignIn(call); @@ -116,8 +118,8 @@ public class EhClient { } } - private Object getGalleryList(Object... params) throws Exception { - Call call = EhEngine.prepareGetGalleryList(mOkHttpClient, (String) params[0]); + private Object getGalleryList(EhConfig ehConfig, Object... params) throws Exception { + Call call = EhEngine.prepareGetGalleryList(mOkHttpClient, ehConfig, (String) params[0]); if (!mStop) { mCall = call; return EhEngine.doGetGalleryList(call); @@ -126,8 +128,8 @@ public class EhClient { } } - private Object getGalleryDetail(Object... params) throws Exception { - Call call = EhEngine.prepareGetGalleryDetail(mOkHttpClient, (String) params[0]); + private Object getGalleryDetail(EhConfig ehConfig, Object... params) throws Exception { + Call call = EhEngine.prepareGetGalleryDetail(mOkHttpClient, ehConfig, (String) params[0]); if (!mStop) { mCall = call; return EhEngine.doGetGalleryDetail(call); @@ -141,11 +143,11 @@ public class EhClient { try { switch (mMethod) { case METHOD_SIGN_IN: - return signIn(params); + return signIn(mEhConfig, params); case METHOD_GET_GALLERY_LIST: - return getGalleryList(params); + return getGalleryList(mEhConfig, params); case METHOD_GET_GALLERY_DETAIL: - return getGalleryDetail(params); + return getGalleryDetail(mEhConfig, params); default: return new IllegalStateException("Can't detect method " + mMethod); } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index 16015fa7f..c48649dca 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -63,7 +63,8 @@ public class EhEngine { } } - public static Call prepareSignIn(OkHttpClient okHttpClient, String username, String password) { + public static Call prepareSignIn(OkHttpClient okHttpClient, + EhConfig ehConfig, String username, String password) { FormBody.Builder builder = new FormBody.Builder() .add("UserName", username) .add("PassWord", password) @@ -73,7 +74,7 @@ public class EhEngine { String url = EhUrl.API_SIGN_IN; Log.d(TAG, url); - Request request = new EhRequestBuilder(url) + Request request = new EhRequestBuilder(url, ehConfig) .post(builder.build()) .build(); return okHttpClient.newCall(request); @@ -95,9 +96,10 @@ public class EhEngine { } } - public static Call prepareGetGalleryList(OkHttpClient okHttpClient, String url) { + public static Call prepareGetGalleryList(OkHttpClient okHttpClient, + EhConfig ehConfig, String url) { Log.d(TAG, url); - Request request = new EhRequestBuilder(url).build(); + Request request = new EhRequestBuilder(url, ehConfig).build(); return okHttpClient.newCall(request); } @@ -117,9 +119,10 @@ public class EhEngine { } } - public static Call prepareGetGalleryDetail(OkHttpClient okHttpClient, String url) { + public static Call prepareGetGalleryDetail(OkHttpClient okHttpClient, + EhConfig ehConfig, String url) { Log.d(TAG, url); - Request request = new EhRequestBuilder(url).build(); + Request request = new EhRequestBuilder(url, ehConfig).build(); return okHttpClient.newCall(request); } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhRequest.java b/app/src/main/java/com/hippo/ehviewer/client/EhRequest.java index cb75480cf..b8d7c62e9 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhRequest.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhRequest.java @@ -16,31 +16,55 @@ package com.hippo.ehviewer.client; +import com.hippo.ehviewer.Settings; + public class EhRequest { - int method; - Object[] args; - EhClient.Callback callback; + private int mMethod; + private Object[] mArgs; + private EhClient.Callback mCallback; + private EhConfig mEhConfig; EhClient.Task task; private boolean mCancel = false; public EhRequest setMethod(int method) { - this.method = method; + mMethod = method; return this; } public EhRequest setArgs(Object... args) { - this.args = args; + mArgs = args; return this; } public EhRequest setCallback(EhClient.Callback callback) { - this.callback = callback; + mCallback = callback; return this; } + public EhRequest setEhConfig(EhConfig ehConfig) { + mEhConfig = ehConfig; + return this; + } + + public int getMethod() { + return mMethod; + } + + public Object[] getArgs() { + return mArgs; + } + + public EhClient.Callback getCallback() { + return mCallback; + } + + public EhConfig getEhConfig() { + return mEhConfig != null ? mEhConfig : Settings.getEhConfig(); + } + public void cancel() { if (!mCancel) { mCancel = true;