Add UConfigActivity

This commit is contained in:
seven332 committed 2018-02-10 14:02:20 +08:00
1 parent 197a34721b
commit 30819fc7c6
13 files changed
+438 -20

No files matched your search

+6
View File
@@ -132,6 +132,12 @@
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/set_pattern_protection"/>
<activity
android:name=".ui.UConfigActivity"
android:configChanges="screenSize|uiMode"
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/u_config"/>
<service
android:name="com.hippo.ehviewer.download.DownloadService"
android:label="@string/download_service_label"/>
@@ -52,6 +52,9 @@ public class EhUrl {
public static final String URL_FAVORITES_EX = HOST_EX + "favorites.php";
public static final String URL_FORUMS = "https://forums.e-hentai.org/";
public static final String UCONFIG_E = HOST_E + "uconfig.php";
public static final String UCONFIG_EX = HOST_EX + "uconfig.php";
private static final String URL_PREFIX_THUMB_E = "https://ehgt.org/t/";
private static final String URL_PREFIX_THUMB_EX = "https://exhentai.org/t/";
@@ -89,6 +92,16 @@ public class EhUrl {
}
}
public static String getUConfigUrl() {
switch (Settings.getGallerySite()) {
default:
case SITE_E:
return UCONFIG_E;
case SITE_EX:
return UCONFIG_EX;
}
}
public static String getGalleryDetailUrl(long gid, String token, int index, boolean allComment) {
UrlBuilder builder = new UrlBuilder(getHost() + "g/" + gid + '/' + token + '/');
if (index != 0) {
@@ -0,0 +1,255 @@
/*
* 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.ui;
/*
* Created by Hippo on 2018/2/9.
*/
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.TextView;
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.widget.ProgressView;
import okhttp3.Cookie;
import okhttp3.HttpUrl;
public class UConfigActivity extends ToolbarActivity {
private WebView webView;
private ProgressView progress;
private String url;
private boolean loaded;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.flush();
cookieManager.removeAllCookies(null);
cookieManager.removeSessionCookies(null);
} else {
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
cookieSyncManager.startSync();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncManager.stopSync();
}
// Copy cookies from okhttp cookie store to CookieManager
url = EhUrl.getUConfigUrl();
EhCookieStore store = EhApplication.getEhCookieStore(this);
for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
cookieManager.setCookie(url, cookie.toString());
}
setContentView(R.layout.activity_u_config);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new UConfigWebViewClient());
webView.setWebChromeClient(new UConfigWebChromeClient());
webView.loadUrl(url);
progress = (ProgressView) findViewById(R.id.progress);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.activity_u_config, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_apply:
if (loaded) {
webView.loadUrl("javascript:"
+ "(function() {\n"
+ " var apply = document.getElementById(\"apply\").children[0];\n"
+ " apply.click();\n"
+ "})();");
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private Cookie longLive(Cookie cookie) {
return new Cookie.Builder()
.name(cookie.name())
.value(cookie.value())
.domain(cookie.domain())
.path(cookie.path())
.expiresAt(Long.MAX_VALUE)
.build();
}
@Override
protected void onDestroy() {
super.onDestroy();
webView.destroy();
// Put cookies back to okhttp cookie store
CookieManager cookieManager = CookieManager.getInstance();
String cookiesString = cookieManager.getCookie(url);
if (cookiesString != null && !cookiesString.isEmpty()) {
EhCookieStore store = EhApplication.getEhCookieStore(this);
HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);
// The cookies saved in the uconfig page should be shared between e and ex
for (String header : cookiesString.split(";")) {
Cookie eCookie = Cookie.parse(eUrl, header);
if (eCookie != null) {
store.addCookie(longLive(eCookie));
}
Cookie exCookie = Cookie.parse(exUrl, header);
if (exCookie != null) {
store.addCookie(longLive(exCookie));
}
}
}
}
private class UConfigWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Never load other urls
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progress.setVisibility(View.VISIBLE);
loaded = false;
}
@Override
public void onPageFinished(WebView view, String url) {
progress.setVisibility(View.GONE);
loaded = true;
}
}
private class UConfigWebChromeClient extends WebChromeClient {
private Context context = UConfigActivity.this;
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
final JsPromptResult result) {
View promptView = UConfigActivity.this.getLayoutInflater()
.inflate(R.layout.dialog_js_prompt, null, false);
TextView messageView = (TextView) promptView.findViewById(R.id.message);
messageView.setText(message);
final EditText valueView = (EditText) promptView.findViewById(R.id.value);
valueView.setText(defaultValue);
new AlertDialog.Builder(context)
.setView(promptView)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm(valueView.getText().toString());
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
result.cancel();
}
})
.show();
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(context)
.setMessage(message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
result.cancel();
}
})
.show();
return true;
}
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(context)
.setMessage(message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
result.cancel();
}
})
.show();
return true;
}
}
}
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/primary_drawable_dark"
android:pathData="@string/pd_check"/>
</vector>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.hippo.widget.ProgressView
android:id="@+id/progress"
style="@style/ProgressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
</FrameLayout>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/keyline_margin">
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<EditText
android:id="@+id/value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyline_margin"
android:inputType="text"/>
</LinearLayout>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_apply"
android:icon="@drawable/v_check_dark_x24"
android:title="@string/apply"
app:showAsAction="always"/>
</menu>
@@ -348,6 +348,10 @@
<string name="set">设置</string>
<string name="enable_fingerprint">允许使用指纹解锁</string>
<!-- UConfig Activity -->
<string name="u_config">EHentai 设置</string>
<string name="apply">应用</string>
<!-- Gallery Activity -->
<string name="page_menu_title">第 %d 页</string>
<string name="page_menu_refresh">@string/refresh</string>
@@ -365,6 +369,8 @@
<string name="settings_eh_sign_out_warning">天哪,我的老伙计,你要退出登录吗?我是说,你真的要退出登录吗?</string>
<string name="settings_eh_sign_out_yes">是的,我是说,真的</string>
<string name="settings_eh_sign_out_tip">已退出登录,重启应用以便再次登录</string>
<string name="settings_u_config">EHentai 设置</string>
<string name="settings_u_config_summary">EHentai 网站上的设置</string>
<string name="settings_eh_gallery_site">画廊站点</string>
<string name="settings_eh_list_mode">列表模式</string>
<string name="settings_eh_list_mode_detail">详情</string>
@@ -348,6 +348,10 @@
<string name="set">設置</string>
<string name="enable_fingerprint">允許使用指紋解鎖</string>
<!-- UConfig Activity -->
<string name="u_config">EHentai 設置</string>
<string name="apply">應用</string>
<!-- Gallery Activity -->
<string name="page_menu_title">第 %d 頁</string>
<string name="page_menu_refresh">@string/refresh</string>
@@ -365,6 +369,8 @@
<string name="settings_eh_sign_out_warning">天哪,我的老夥計,你要退出登錄嗎?我是説,你真的要退出登錄嗎?</string>
<string name="settings_eh_sign_out_yes">是的,我是説,真的</string>
<string name="settings_eh_sign_out_tip">已退出登錄,重啟應用以便再次登錄</string>
<string name="settings_u_config">EHentai 設置</string>
<string name="settings_u_config_summary">EHentai 網站上的設置</string>
<string name="settings_eh_gallery_site">畫廊站點</string>
<string name="settings_eh_list_mode">列表模式</string>
<string name="settings_eh_list_mode_detail">詳情</string>
@@ -348,6 +348,10 @@
<string name="set">設定</string>
<string name="enable_fingerprint">允許使用指紋解鎖</string>
<!-- UConfig Activity -->
<string name="u_config">EHentai 設定</string>
<string name="apply">應用</string>
<!-- Gallery Activity -->
<string name="page_menu_title">第 %d 頁</string>
<string name="page_menu_refresh">@string/refresh</string>
@@ -365,6 +369,8 @@
<string name="settings_eh_sign_out_warning">天哪,老兄,你真的要登出嗎?我是說,你真的要登出嗎?</string>
<string name="settings_eh_sign_out_yes">沒錯,我是說,對</string>
<string name="settings_eh_sign_out_tip">已登出,重新啟動程式以再次登入</string>
<string name="settings_u_config">EHentai 設定</string>
<string name="settings_u_config_summary">EHentai 網站上的設定</string>
<string name="settings_eh_gallery_site">圖庫站台</string>
<string name="settings_eh_list_mode">列表模式</string>
<string name="settings_eh_list_mode_detail">詳細資料</string>
+1
View File
@@ -60,6 +60,7 @@
<string name="pd_similar" translatable="false">M2,20L17,10L22,22M14,9L2,8L11,2Z</string>
<string name="pd_refresh" translatable="false">M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z</string>
<string name="pd_file_find" translatable="false">M9,13A3,3 0 0,0 12,16A3,3 0 0,0 15,13A3,3 0 0,0 12,10A3,3 0 0,0 9,13M20,19.59V8L14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18C18.45,22 18.85,21.85 19.19,21.6L14.76,17.17C13.96,17.69 13,18 12,18A5,5 0 0,1 7,13A5,5 0 0,1 12,8A5,5 0 0,1 17,13C17,14 16.69,14.96 16.17,15.75L20,19.59Z</string>
<string name="pd_check" translatable="false">M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z</string>
<string name="pd_big_label" translatable="false">M12.88,2H4V11L14.97,22.14L24,13.1L12.88,2ZM7.26,5.26C7.96,4.58,9.06,4.58,9.74,5.26C10.42,5.96,10.42,7.06,9.74,7.74S7.94,8.42,7.26,7.74S6.58,5.94,7.26,5.26ZM14.98,19.3L8.76,12.95L14.88,6.83L21.18,13.11L14.98,19.31ZM11.6,21.56L10.23,23L0,12.74V5H2V11.9L11.6,21.56Z</string>
<string name="pd_big_search" translatable="false">M20.46,14.65C21.86,16.15,20.31,18.6,18.32,17.87C19.78,17.57,20.79,16.37,20.46,14.65ZM4.32,17.87C6.32,18.6,7.86,16.17,6.46,14.65C6.79,16.38,5.78,17.55,4.32,17.87ZM16.87,4.3C16.6,3.56,15.87,3,15,3C13.7,3,12.7,4.24,13.1,5.58C14.2,5.18,15.44,4.48,16.87,4.31ZM24,16C24,18.76,21.76,21,19,21C14.96,21,14.84,16.88,12,16.88S9.04,21,5,21C2.24,21,0,18.76,0,16C0,13.87,1.53,11.43,3.94,7.18C5.84,3.81,8.69,5.92,10.76,6.58C11.54,6.85,12.41,6.88,13.24,6.58C15.3,5.92,18.14,3.81,20.06,7.18C22.46,11.43,24,13.88,24,16ZM8,16C8,14.35,6.65,13,5,13S2,14.35,2,16S3.35,19,5,19S8,17.65,8,16ZM13,14C13,13.45,12.55,13,12,13S11,13.45,11,14S11.45,15,12,15S13,14.55,13,14ZM22,16C22,14.35,20.65,13,19,13S16,14.35,16,16S17.35,19,19,19S22,17.65,22,16ZM9,3C8.14,3,7.4,3.55,7.13,4.3C8.56,4.48,9.79,5.2,10.9,5.58C11.3,4.24,10.3,3,9,3Z</string>
+6
View File
@@ -392,6 +392,10 @@
<string name="set">Set</string>
<string name="enable_fingerprint">Also allow unlock with fingerprint</string>
<!-- UConfig Activity -->
<string name="u_config">EHentai settings</string>
<string name="apply">Apply</string>
<!-- Gallery Activity -->
<string name="page_menu_title">Page %d</string>
<string name="page_menu_refresh">@string/refresh</string>
@@ -408,6 +412,8 @@
<string name="settings_eh_sign_out_warning">Do you really want to sign out?</string>
<string name="settings_eh_sign_out_yes">@android:string/ok</string>
<string name="settings_eh_sign_out_tip">Signed out, restart the application to sign in</string>
<string name="settings_u_config">EHentai settings</string>
<string name="settings_u_config_summary">Settings on EHentai website</string>
<string name="settings_eh_gallery_site">Gallery site</string>
<string name="settings_eh_list_mode">List mode</string>
<string name="settings_eh_list_mode_detail">Detail</string>
+6 -20
View File
@@ -32,6 +32,12 @@
app:entryValues="@array/gallery_site_entry_values"
android:defaultValue="1"/>
<com.hippo.preference.ActivityPreference
android:key="u_config"
android:title="@string/settings_u_config"
android:summary="@string/settings_u_config_summary"
app:activity="com.hippo.ehviewer.ui.UConfigActivity"/>
<com.hippo.preference.ListPreference
android:key="list_mode"
android:title="@string/settings_eh_list_mode"
@@ -69,26 +75,6 @@
android:title="@string/settings_eh_fix_thumb_url"
android:defaultValue="false"/>
<com.hippo.ehviewer.preference.DefaultCategoryPreference
android:key="default_categories"
android:title="@string/settings_eh_default_categories"
android:summary="@string/settings_eh_default_categories_summary"/>
<com.hippo.ehviewer.preference.ExcludedTagNamespacesPreference
android:key="excluded_tag_namespaces"
android:title="@string/settings_eh_excluded_tag_namespaces"
android:summary="@string/settings_eh_excluded_tag_namespaces_summary"/>
<com.hippo.preference.ActivityPreference
android:key="excluded_languages"
android:title="@string/settings_eh_excluded_languages"
android:summary="@string/settings_eh_excluded_languages_summary"
app:activity="com.hippo.ehviewer.ui.ExcludedLanguagesActivity"/>
<com.hippo.ehviewer.preference.HatHProxyPreference
android:key="hath_proxy"
android:title="@string/settings_eh_hath_proxy"/>
<com.hippo.preference.SwitchPreference
android:key="show_jpn_title"
android:title="@string/settings_eh_show_jpn_title"