diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.java b/app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.java index 8e79ebfd2..64d0f4c45 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.java @@ -32,8 +32,7 @@ public class EhCookieStore extends CookieDBStore { private static final String KEY_IPD_PASS_HASH = "ipb_pass_hash"; public void cleanUpForSignIn() { - remove(EhUrl.DOMAIN_E); - remove(EhUrl.DOMAIN_EX); + removeAll(); } public boolean hasSignedIn() { @@ -99,14 +98,22 @@ public class EhCookieStore extends CookieDBStore { List result = new ArrayList<>(cookies.size() + 2); for (Cookie cookie: cookies) { - result.add(cookie); + if (EhUrl.DOMAIN_E.equals(cookie.domain())) { + // Don't save igneous: mystery. It is for sad panda + if (EhUrl.DOMAIN_E.equals(cookie.domain()) && + "igneous".equals(cookie.name()) && + "mystery".equals(cookie.value())) { + continue; + } - // Save id and hash for exhentai - if (EhUrl.DOMAIN_E.equals(cookie.domain()) && - (KEY_IPD_MEMBER_ID.equals(cookie.name()) || - KEY_IPD_PASS_HASH.equals(cookie.name()))) { - result.add(newCookie(cookie, EhUrl.DOMAIN_EX)); + // Save id and hash for exhentai + if (KEY_IPD_MEMBER_ID.equals(cookie.name()) || + KEY_IPD_PASS_HASH.equals(cookie.name())) { + result.add(newCookie(cookie, EhUrl.DOMAIN_EX)); + } } + + result.add(cookie); } super.saveFromResponse(url, Collections.unmodifiableList(result)); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java index 7d1013804..b803cd484 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java @@ -49,7 +49,7 @@ import com.hippo.ehviewer.ui.scene.GalleryDetailScene; import com.hippo.ehviewer.ui.scene.GalleryInfoScene; import com.hippo.ehviewer.ui.scene.GalleryListScene; import com.hippo.ehviewer.ui.scene.GalleryPreviewsScene; -import com.hippo.ehviewer.ui.scene.LoginScene; +import com.hippo.ehviewer.ui.scene.SignInScene; import com.hippo.ehviewer.ui.scene.ProgressScene; import com.hippo.ehviewer.ui.scene.QuickSearchScene; import com.hippo.ehviewer.ui.scene.WarningScene; @@ -90,7 +90,7 @@ public final class MainActivity extends StageActivity static { registerLaunchMode(WarningScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK); registerLaunchMode(AnalyticsScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK); - registerLaunchMode(LoginScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK); + registerLaunchMode(SignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK); registerLaunchMode(GalleryListScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TOP); registerLaunchMode(QuickSearchScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK); registerLaunchMode(GalleryDetailScene.class, SceneFragment.LAUNCH_MODE_STANDARD); @@ -112,7 +112,7 @@ public final class MainActivity extends StageActivity } case CHECK_STEP_ANALYTICS: if (!EhUtils.hasSignedIn(this)) { - startScene(new Announcer(LoginScene.class).setArgs(args)); + startScene(new Announcer(SignInScene.class).setArgs(args)); break; } case CHECK_STEP_SIGN_IN: @@ -156,7 +156,7 @@ public final class MainActivity extends StageActivity } else if (Settings.getAskAnalytics()) { return new Announcer(AnalyticsScene.class); } else if (!EhUtils.hasSignedIn(this)) { - return new Announcer(LoginScene.class); + return new Announcer(SignInScene.class); } else { Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); @@ -181,7 +181,7 @@ public final class MainActivity extends StageActivity Bundle newArgs = new Bundle(); newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName()); newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs()); - return new Announcer(LoginScene.class).setArgs(newArgs); + return new Announcer(SignInScene.class).setArgs(newArgs); } } return announcer; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java similarity index 80% rename from app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java rename to app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java index 60ee12972..d0d3b3378 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java @@ -17,7 +17,6 @@ package com.hippo.ehviewer.ui.scene; import android.content.Context; -import android.content.DialogInterface; import android.graphics.Paint; import android.os.Bundle; import android.support.annotation.Nullable; @@ -45,23 +44,36 @@ import com.hippo.scene.SceneFragment; import com.hippo.scene.StageActivity; import com.hippo.util.ActivityHelper; import com.hippo.util.ExceptionUtils; +import com.hippo.yorozuya.AssertUtils; +import com.hippo.yorozuya.ViewUtils; -public final class LoginScene extends BaseScene implements EditText.OnEditorActionListener, +public final class SignInScene extends BaseScene implements EditText.OnEditorActionListener, View.OnClickListener { - private static final String TAG = LoginScene.class.getSimpleName(); - private static final String KEY_REQUEST_ID = "request_id"; + /*--------------- + View life cycle + ---------------*/ + @Nullable private View mProgress; + @Nullable private TextInputLayout mUsernameLayout; + @Nullable private TextInputLayout mPasswordLayout; + @Nullable private EditText mUsername; + @Nullable private EditText mPassword; + @Nullable private View mRegister; + @Nullable private View mSignIn; - private TextView mSignInViaWebview; + @Nullable + private TextView mSignInViaWebView; + @Nullable private TextView mSignInViaCookies; + @Nullable private TextView mSkipSigningIn; private int mRequestId; @@ -102,19 +114,21 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.scene_login, container, false); - View loginForm = view.findViewById(R.id.login_form); - mProgress = view.findViewById(R.id.progress); - mUsernameLayout = (TextInputLayout) loginForm.findViewById(R.id.username_layout); + View loginForm = ViewUtils.$$(view, R.id.login_form); + mProgress = ViewUtils.$$(view, R.id.progress); + mUsernameLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.username_layout); mUsername = mUsernameLayout.getEditText(); - mPasswordLayout = (TextInputLayout) loginForm.findViewById(R.id.password_layout); + AssertUtils.assertNotNull(mUsername); + mPasswordLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.password_layout); mPassword = mPasswordLayout.getEditText(); - mRegister = loginForm.findViewById(R.id.register); - mSignIn = loginForm.findViewById(R.id.sign_in); - mSignInViaWebview = (TextView) loginForm.findViewById(R.id.sign_in_via_webview); - mSignInViaCookies = (TextView) loginForm.findViewById(R.id.sign_in_via_cookies); - mSkipSigningIn = (TextView) loginForm.findViewById(R.id.skip_signing_in); + AssertUtils.assertNotNull(mPassword); + mRegister = ViewUtils.$$(loginForm, R.id.register); + mSignIn = ViewUtils.$$(loginForm, R.id.sign_in); + mSignInViaWebView = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_webview); + mSignInViaCookies = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_cookies); + mSkipSigningIn = (TextView) ViewUtils.$$(loginForm, R.id.skip_signing_in); - mSignInViaWebview.setPaintFlags(mSignInViaWebview.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + mSignInViaWebView.setPaintFlags(mSignInViaWebView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); mSignInViaCookies.setPaintFlags(mSignInViaCookies.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); mSkipSigningIn.setPaintFlags(mSignInViaCookies.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); @@ -122,7 +136,7 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi mRegister.setOnClickListener(this); mSignIn.setOnClickListener(this); - mSignInViaWebview.setOnClickListener(this); + mSignInViaWebView.setOnClickListener(this); mSignInViaCookies.setOnClickListener(this); mSkipSigningIn.setOnClickListener(this); @@ -153,7 +167,7 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi UrlOpener.openUrl(getActivity(), EhUrl.API_REGISTER, false, true); } else if (mSignIn == v) { signIn(); - } else if (mSignInViaWebview == v) { + } else if (mSignInViaWebView == v) { } else if (mSignInViaCookies == v) { @@ -175,6 +189,11 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi } private void signIn() { + if (null == mUsername || null == mPassword || null == mUsernameLayout || + null == mPasswordLayout || null == mProgress) { + return; + } + String username = mUsername.getText().toString(); String password = mPassword.getText().toString(); @@ -222,35 +241,32 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi .setTitle(R.string.skip_signing_in) .setMessage(R.string.skip_signing_in_plain) .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (which == AlertDialog.BUTTON_POSITIVE) { - redirectTo(); - } - } - }).show(); + .setPositiveButton(R.string.get_it, null) + .show(); } - public void onSignInSuccess() { if (EhApplication.getEhCookieStore(getContext()).hasSignedIn()) { // Has signed in redirectTo(); } else { - mProgress.setVisibility(View.GONE); + if (null != mProgress) { + mProgress.setVisibility(View.GONE); + } whetherToSkip(); } } public void onSignInFailure(Exception e) { - mProgress.setVisibility(View.GONE); + if (null != mProgress) { + mProgress.setVisibility(View.GONE); + } Toast.makeText(getContext(), ExceptionUtils.getReadableString(getContext(), e), Toast.LENGTH_SHORT).show(); whetherToSkip(); } - private class SignInListener extends EhCallback { + private class SignInListener extends EhCallback { public SignInListener(Context context, int stageId, String sceneTag) { super(context, stageId, sceneTag); @@ -261,7 +277,7 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi getApplication().removeGlobalStuff(this); Settings.putDisplayName(result); - LoginScene scene = getScene(); + SignInScene scene = getScene(); if (scene != null) { scene.onSignInSuccess(); } @@ -272,7 +288,7 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi getApplication().removeGlobalStuff(this); e.printStackTrace(); - LoginScene scene = getScene(); + SignInScene scene = getScene(); if (scene != null) { scene.onSignInFailure(e); } @@ -285,7 +301,7 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi @Override public boolean isInstance(SceneFragment scene) { - return scene instanceof LoginScene; + return scene instanceof SignInScene; } } } diff --git a/app/src/main/java/com/hippo/okhttp/CookieDB.java b/app/src/main/java/com/hippo/okhttp/CookieDB.java index 0306a9791..1fb1ed6af 100644 --- a/app/src/main/java/com/hippo/okhttp/CookieDB.java +++ b/app/src/main/java/com/hippo/okhttp/CookieDB.java @@ -111,6 +111,10 @@ public class CookieDB { sDaoSession.getOkHttp3CookieDao().deleteByKey(id); } + static void removeAllCookies() { + sDaoSession.getOkHttp3CookieDao().deleteAll(); + } + static long addCookie(Cookie cookie) { OkHttp3CookieDao dao = sDaoSession.getOkHttp3CookieDao(); diff --git a/app/src/main/java/com/hippo/okhttp/CookieDBStore.java b/app/src/main/java/com/hippo/okhttp/CookieDBStore.java index 8f4c7cbc2..8a9b5bd60 100644 --- a/app/src/main/java/com/hippo/okhttp/CookieDBStore.java +++ b/app/src/main/java/com/hippo/okhttp/CookieDBStore.java @@ -126,6 +126,10 @@ public class CookieDBStore implements CookieJar { } } + public synchronized void removeAll() { + map.clear(); + CookieDB.removeAllCookies(); + } public synchronized void add(Cookie cookie) { String domain = cookie.domain(); diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1bd68e35e..bbf1af6ec 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -61,12 +61,13 @@ 用户名不可为空 密码不可为空 跳过登陆 - 登陆失败。这可能是网站更新导致的。你愿意跳过登陆么? + 登陆失败。这可能是网站更新导致的,也有可能是发生了奇怪的事情。您可以选择在登陆按钮下方通过网页登陆或者输入 cookie,或者跳过登陆。跳过登陆可能导致无法正常使用应用。 再按一次退出 点击重试 EhViewer 将申请设备存储空间访问权限以便下载画廊。你愿意授权吗? 好痛 你同意让开发者收集你的设备信息与使用情况吗?这将对开发有很大帮助。<br><br>数据统计服务由 Google Analytics 提供,其隐私政策可在 <a href="https://www.google.com/policies/privacy/">https://www.google.com/policies/privacy/</a> 查看。<br><br>若您同意参与数据统计,您的设备信息与应用使用情况将会被记录,其包括但不限于:Android API 版本、设备型号、语言所在地、本应用版本号、会话时长、应用功能使用次数。开发者承诺以下信息并不会被记录:电话号码、电子邮件地址、IMEI。<br><br>在您同意参与数据统计之前,您的信息不会被记录。<br><br>被记录的数据会由 Google Analytics 进行分析,分析报表仅可被本应用开发者访问。 + 知道了 搜索 ExHentai diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 6acb11d3b..f8e9b711b 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -61,12 +61,13 @@ 用户名不可為空 密碼不可為空 跳過登陸 - 登陸失敗。這可能是網站更新導致的。你願意跳過登陸麼? + 登陸失敗。這可能是網站更新導致的,也有可能是發生了奇怪的事情。您可以選擇在登陸按鈕下方通過網頁登陸或者輸入 cookie,或者跳過登陸。跳過登陸可能導致無法正常使用應用。 再按一次退出 點擊重試 EhViewer 將申請設備存儲空間訪問權限以便下載畫廊。你願意授權嗎? 好痛 你同意讓開發者收集你的設備信息與使用情況嗎?這將對開發有很大幫助。<br><br>數據統計服務由 Google Analytics 提供,其隱私政策可在 <a href="https://www.google.com/policies/privacy/">https://www.google.com/policies/privacy/</a> 查看。<br><br>若您同意參與數據統計,您的設備信息與應用使用情況將會被記錄,其包括但不限於:Android API 版本、設備型號、語言所在地、本應用版本號、會話時長、應用功能使用次數。開發者承諾以下信息並不會被記錄:電話號碼、電子郵件地址、IMEI。<br><br>在您同意參與數據統計之前,您的信息不會被記錄。<br><br>被記錄的數據會由 Google Analytics 進行分析,分析報表僅可被本應用開發者訪問。 + 知道了 搜索 ExHentai diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 49e1824d2..dbc2ad49a 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -61,12 +61,13 @@ 使用者名稱不可為空 密碼不可為空 跳過登陸 - 登陸失敗。這可能是網站更新導致的。你願意跳過登陸麼? + 登陸失敗。這可能是網站更新導致的,也有可能是發生了奇怪的事情。您可以選擇在登陸按鈕下方通過網頁登陸或者輸入 cookie,或者跳過登陸。跳過登陸可能導致無法正常使用應用。 再按一次退出 點選重試 EhViewer 將申請裝置儲存空間訪問許可權以便下載畫廊。你願意授權嗎? 好痛 你同意讓開發者收集你的裝置資訊與使用情況嗎?這將對開發有很大幫助。<br><br>資料統計服務由 Google Analytics 提供,其隱私政策可在 <a href="https://www.google.com/policies/privacy/">https://www.google.com/policies/privacy/</a> 檢視。<br><br>若您同意參與資料統計,您的裝置資訊與應用使用情況將會被記錄,其包括但不限於:Android API 版本、裝置型號、語言所在地、本應用版本號、會話時長、應用功能使用次數。開發者承諾以下資訊並不會被記錄:電話號碼、電子郵件地址、IMEI。<br><br>在您同意參與資料統計之前,您的資訊不會被記錄。<br><br>被記錄的資料會由 Google Analytics 進行分析,分析報表僅可被本應用開發者訪問。 + 知道了 搜尋 ExHentai diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5743f0dc0..c51ac4c18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -100,12 +100,13 @@ Username cannot be an empty string Password cannot be an empty string Skip signing in - Sign in failed. But perhaps it is a mistake due to website update. Do you want to skip signing in? + Sign in failed. But perhaps it is a mistake due to website update or something wrong happened. You may try sign in via WebView or enter cookie or skip signing in under sign in button. But you may be a "Sad Panda" after skipping signing in. Press twice to exit Click to retry EhViewer will request WRITE_EXTERNAL_STORAGE permission for downloading gallery. Do you want to grant the permission? It hurts Would you mind if the developer collected your device information and your usage? It will help the developer a lot.<br><br>Data analysis service is provided by Google Analytics. Its privacy policy can be found at <a href="https://www.google.com/policies/privacy/">https://www.google.com/policies/privacy/</a>.<br><br>If you agree to join data analysis, your device information and your usage will be collected, including but not limited to Android API version, equipment model, language residence, the application version, conversion time, function times. The developer promise that these information will NOT be collected, including phone number, e-mail address, IMEI.<br><br>Your information will not be collected until you agree to join data analysis.<br><br>The collected information will be analyzed by Google Analytics. The analysis report can only be viewed by the developer of this application. + Got it Search ExHentai