diff --git a/app/src/main/java/com/hippo/ehviewer/Hosts.java b/app/src/main/java/com/hippo/ehviewer/Hosts.java index 39b8f29b0..fc820f97a 100644 --- a/app/src/main/java/com/hippo/ehviewer/Hosts.java +++ b/app/src/main/java/com/hippo/ehviewer/Hosts.java @@ -142,7 +142,7 @@ public class Hosts { } @Nullable - private static InetAddress toInetAddress(String host, String ip) { + public static InetAddress toInetAddress(String host, String ip) { if (!isValidHost(host)) { return null; } diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index 3ac143126..226fda5c7 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -952,6 +952,17 @@ public class Settings { return getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE); } + public static final String KEY_BUILT_IN_HOSTS = "built_in_hosts"; + private static final boolean DEFAULT_BUILT_IN_HOSTS = false; + + public static boolean getBuiltInHosts() { + return getBoolean(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS); + } + + public static void putBuiltInHosts(boolean value) { + putBoolean(KEY_BUILT_IN_HOSTS, value); + } + /******************** ****** Guide ********************/ diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhDns.java b/app/src/main/java/com/hippo/ehviewer/client/EhDns.java index 2472d95d4..0d3e44f10 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhDns.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhDns.java @@ -23,15 +23,34 @@ package com.hippo.ehviewer.client; import android.content.Context; import com.hippo.ehviewer.EhApplication; import com.hippo.ehviewer.Hosts; +import com.hippo.ehviewer.Settings; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import okhttp3.Dns; public class EhDns implements Dns { + private static final Map builtInHosts; + + static { + Map map = new HashMap<>(); + put(map, "e-hentai.org", "104.24.255.11"); + put(map, "forums.e-hentai.org", "94.100.18.243"); + builtInHosts = map; + } + + private static void put(Map map, String host, String ip) { + InetAddress address = Hosts.toInetAddress(host, ip); + if (address != null) { + map.put(host, address); + } + } + private final Hosts hosts; public EhDns(Context context) { @@ -47,6 +66,13 @@ public class EhDns implements Dns { return Collections.singletonList(inetAddress); } + if (Settings.getBuiltInHosts()) { + inetAddress = builtInHosts.get(hostname); + if (inetAddress != null) { + return Collections.singletonList(inetAddress); + } + } + try { return Arrays.asList(InetAddress.getAllByName(hostname)); } catch (NullPointerException e) { diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index b64a39b27..70d674ca3 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -493,8 +493,10 @@ 清理内存缓存 清理缩略图、画廊信息的内存缓存 阅读缓存大小 + 内置 hosts.txt + 应用提供的主机到IP的映射\n可被自定义 hosts.txt 覆盖 自定义 hosts.txt - 将主机名称映射到相应的IP地址 + 将主机名称映射到相应的IP地址\n可覆盖内置 hosts.txt 图案保护 未设置图案保护 已设置图案保护 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 8e53ef61c..8520ccee0 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -493,8 +493,10 @@ 清理內存緩存 清理縮略圖、畫廊信息的內存緩存 閲讀緩存大小 + 內置 hosts.txt + 應用提供的主機到IP的映射\n可被自定義 hosts.txt 覆蓋 自定義 hosts.txt - 將主機名稱對映到相應的IP位址 + 將主機名稱映射到相應的IP地址\n可覆蓋內置 hosts.txt 圖案保護 未設置圖案保護 已設置圖案保護 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 481f21160..c7d018f49 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -493,8 +493,10 @@ 清除記憶體快取 清除縮圖、圖庫詳細資料的記憶體快取 閱讀快取大小 + 內建 hosts.txt + 應用提供的主機到IP的對映\n可被自定義 hosts.txt 覆蓋 自定義 hosts.txt - 將主機名稱對映到相應的IP位址 + 將主機名稱對映到相應的IP位址\n可覆蓋內建 hosts.txt 繪圖解鎖 尚未設定繪圖解鎖 已設定繪圖解鎖 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 645b461fe..c98da26dc 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -536,8 +536,10 @@ Clear memory cache Clear thumb, gallery info memory cache Read cache size + Built-in hosts.txt + The host-to-IP mapping provided by the app\nIt can be overrode by custom hosts.txt Custom hosts.txt - Map hostnames to IP addresses + Map hostnames to IP addresses\nIt can override built-in hosts.txt Pattern protection Pattern protection has not been set Pattern protection has been set diff --git a/app/src/main/res/xml/advanced_settings.xml b/app/src/main/res/xml/advanced_settings.xml index 5a3774322..731f59ebd 100644 --- a/app/src/main/res/xml/advanced_settings.xml +++ b/app/src/main/res/xml/advanced_settings.xml @@ -48,12 +48,18 @@ app:entryValues="@array/read_cache_size_entry_values" android:defaultValue="160"/> + + + app:activity="com.hippo.ehviewer.ui.HostsActivity"/>