Request UConfig on login
This commit is contained in:
1 parent
fb970752fd
commit
1382050b5f
3 files changed
+71
-3
No files matched your search
@@ -54,6 +54,7 @@ public class EhClient {
|
||||
public static final int METHOD_ARCHIVE_LIST = 17;
|
||||
public static final int METHOD_DOWNLOAD_ARCHIVE = 18;
|
||||
public static final int METHOD_VOTE_TAG = 19;
|
||||
public static final int METHOD_GET_UCONFIG = 20;
|
||||
|
||||
private final ThreadPoolExecutor mRequestThreadPool;
|
||||
private static final OkHttpClient mOkHttpClient = EhApplication.getOkHttpClient();
|
||||
@@ -170,6 +171,7 @@ public class EhClient {
|
||||
EhEngine.downloadArchive(this, mOkHttpClient, (Long) params[0], (String) params[1], (String) params[2], (String) params[3]);
|
||||
case METHOD_VOTE_TAG ->
|
||||
EhEngine.voteTag(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (String) params[4], (Integer) params[5]);
|
||||
case METHOD_GET_UCONFIG -> EhEngine.getUConfig(this, mOkHttpClient);
|
||||
default -> new IllegalStateException("Can't detect method " + mMethod);
|
||||
};
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -813,6 +813,55 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static Void getUConfig(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Throwable {
|
||||
String url = EhUrl.getUConfigUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
request = response.request();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// TODO Use a better way to handle 302
|
||||
if (!request.url().toString().equals(url)) {
|
||||
Log.d(TAG, "Redirected! Retry " + url);
|
||||
request = new EhRequestBuilder(url, null).build();
|
||||
call = okHttpClient.newCall(request);
|
||||
if (null != task) task.setCall(call);
|
||||
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static VoteCommentParser.Result voteComment(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
|
||||
@@ -113,7 +113,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
outState.putInt(KEY_REQUEST_ID, mRequestId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
@@ -207,6 +207,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
if (REQUEST_CODE_WEBVIEW == requestCode) {
|
||||
if (RESULT_OK == resultCode) {
|
||||
getProfile();
|
||||
getUConfig();
|
||||
}
|
||||
} else {
|
||||
super.onSceneResult(requestCode, resultCode, data);
|
||||
@@ -282,7 +283,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
// Clean up for sign in
|
||||
EhUtils.signOut(context);
|
||||
|
||||
EhCallback callback = new SignInListener(context,
|
||||
EhCallback<SignInScene, String> callback = new SignInListener(context,
|
||||
activity.getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback);
|
||||
EhRequest request = new EhRequest()
|
||||
@@ -304,7 +305,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
hideSoftInput();
|
||||
showProgress(true);
|
||||
|
||||
EhCallback callback = new GetProfileListener(context,
|
||||
EhCallback<SignInScene, ProfileParser.Result> callback = new GetProfileListener(context,
|
||||
activity.getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback);
|
||||
EhRequest request = new EhRequest()
|
||||
@@ -313,6 +314,21 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
EhApplication.getEhClient().execute(request);
|
||||
}
|
||||
|
||||
private void getUConfig() {
|
||||
Context context = getContext();
|
||||
MainActivity activity = getMainActivity();
|
||||
if (null == context || null == activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
hideSoftInput();
|
||||
showProgress(true);
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_UCONFIG);
|
||||
EhApplication.getEhClient().execute(request);
|
||||
}
|
||||
|
||||
private void redirectTo() {
|
||||
Settings.putNeedSignIn(false);
|
||||
MainActivity activity = getMainActivity();
|
||||
@@ -343,6 +359,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
|
||||
if (EhApplication.getEhCookieStore().hasSignedIn()) {
|
||||
getProfile();
|
||||
getUConfig();
|
||||
} else {
|
||||
mSigningIn = false;
|
||||
hideProgress();
|
||||
|
||||
Reference in new issue
Block a user