From dc697af0817dbdfe6c61f8977f578865bb7045aa Mon Sep 17 00:00:00 2001 From: seven332 Date: Fri, 14 Sep 2018 13:32:03 +0800 Subject: [PATCH] Show identity cookies --- .../preference/IdentityCookiePreference.java | 105 ++++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 5 + app/src/main/res/values-zh-rHK/strings.xml | 5 + app/src/main/res/values-zh-rTW/strings.xml | 5 + app/src/main/res/values/strings.xml | 5 + app/src/main/res/xml/eh_settings.xml | 5 + 6 files changed, 130 insertions(+) create mode 100644 app/src/main/java/com/hippo/ehviewer/preference/IdentityCookiePreference.java diff --git a/app/src/main/java/com/hippo/ehviewer/preference/IdentityCookiePreference.java b/app/src/main/java/com/hippo/ehviewer/preference/IdentityCookiePreference.java new file mode 100644 index 000000000..155c5b976 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/preference/IdentityCookiePreference.java @@ -0,0 +1,105 @@ +/* + * Copyright 2018 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.preference; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.support.v7.app.AlertDialog; +import android.util.AttributeSet; +import android.widget.Toast; +import com.hippo.ehviewer.EhApplication; +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.client.EhCookieStore; +import com.hippo.ehviewer.client.EhUrl; +import com.hippo.preference.MessagePreference; +import com.hippo.text.Html; +import java.util.LinkedList; +import java.util.List; +import okhttp3.Cookie; +import okhttp3.HttpUrl; + +public class IdentityCookiePreference extends MessagePreference { + + private String message; + + public IdentityCookiePreference(Context context) { + super(context); + init(); + } + + public IdentityCookiePreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public IdentityCookiePreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init() { + EhCookieStore store = EhApplication.getEhCookieStore(getContext()); + List eCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_E)); + List exCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_EX)); + List cookies = new LinkedList<>(eCookies); + cookies.addAll(exCookies); + + String ipbMemberId = null; + String ipbPassHash = null; + String igneous = null; + + for (int i = 0, n = cookies.size(); i < n; i++) { + Cookie cookie = cookies.get(i); + switch (cookie.name()) { + case EhCookieStore.KEY_IPD_MEMBER_ID: + ipbMemberId = cookie.value(); + break; + case EhCookieStore.KEY_IPD_PASS_HASH: + ipbPassHash = cookie.value(); + break; + case EhCookieStore.KEY_IGNEOUS: + igneous = cookie.value(); + break; + } + } + + if (ipbMemberId != null || ipbPassHash != null || igneous != null) { + message = EhCookieStore.KEY_IPD_MEMBER_ID + ": " + ipbMemberId + "
" + + EhCookieStore.KEY_IPD_PASS_HASH + ": " + ipbPassHash + "
" + + EhCookieStore.KEY_IGNEOUS + ": " + igneous; + setDialogMessage(Html.fromHtml(getContext().getString(R.string.settings_eh_identity_cookies_signed, message))); + message = message.replace("
", "\n"); + } else { + setDialogMessage(getContext().getString(R.string.settings_eh_identity_cookies_tourist)); + } + } + + @Override + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { + super.onPrepareDialogBuilder(builder); + if (message != null) { + builder.setPositiveButton(R.string.settings_eh_identity_cookies_copy, (dialog, which) -> { + ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); + cmb.setPrimaryClip(ClipData.newPlainText(null, message)); + Toast.makeText(getContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); + + IdentityCookiePreference.this.onClick(dialog, which); + }); + } + } +} diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 6aa2b0de9..42e1d00e2 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -391,6 +391,11 @@ 天哪,我的老伙计,你要退出登录吗?我是说,你真的要退出登录吗? 是的,我是说,真的 已退出登录,重启应用以便再次登录 + 身份 Cookie + 可用于登录 + 身份 Cookie 可用于登录该账号。<br><b>注意数据安全</b><br><br>%s + 未登录 + 复制 EHentai 设置 EHentai 网站上的设置 画廊站点 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 6db50111e..8c0667647 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -390,6 +390,11 @@ 天哪,我的老夥計,你要退出登錄嗎?我是説,你真的要退出登錄嗎? 是的,我是説,真的 已退出登錄,重啟應用以便再次登錄 + 身份 Cookie + 可用於登錄 + 身份 Cookie 可用於登錄該賬號。<br><b>注意數據安全</b><br><br>%s + 未登錄 + 複製 EHentai 設置 EHentai 網站上的設置 畫廊站點 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 2a3716d51..bb1a04081 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -390,6 +390,11 @@ 天哪,老兄,你真的要登出嗎?我是說,你真的要登出嗎? 沒錯,我是說,對 已登出,重新啟動程式以再次登入 + 身份 Cookie + 可用於登入 + 身份 Cookie 可用於登入該賬號。<br><b>注意資料安全</b><br><br>%s + 未登入 + 複製 EHentai 設定 EHentai 網站上的設定 圖庫站台 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 389733204..df2b0a330 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -434,6 +434,11 @@ Do you really want to sign out? @android:string/ok Signed out, restart the application to sign in + Identity cookies + It can be used to sign in + Identity cookies can be used to sign in to this account.<br><b>KEEP IT SAFE</b><br><br>%s + Not signed in. + Copy EHentai settings Settings on EHentai website Gallery site diff --git a/app/src/main/res/xml/eh_settings.xml b/app/src/main/res/xml/eh_settings.xml index a260b5e76..030f5f276 100644 --- a/app/src/main/res/xml/eh_settings.xml +++ b/app/src/main/res/xml/eh_settings.xml @@ -24,6 +24,11 @@ android:title="@string/settings_eh_sign_out" android:summary="@string/settings_eh_sign_out_summary"/> + +