From eb7053cd13ef7ff1cf7d68c001cb05a8ea6dca89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD-=E7=99=BD?= Date: Sun, 1 Sep 2024 15:07:59 +0800 Subject: [PATCH] Drop hosts --- .../java/com/hippo/ehviewer/EhApplication.kt | 13 +- .../main/java/com/hippo/ehviewer/Hosts.java | 342 ------------------ .../main/java/com/hippo/ehviewer/Settings.kt | 5 - .../java/com/hippo/ehviewer/client/EhDns.kt | 140 ------- .../java/com/hippo/ehviewer/ui/EhActivity.kt | 1 + .../ui/fragment/BasePreferenceFragment.kt | 1 - .../ehviewer/ui/fragment/HostsFragment.kt | 244 ------------- app/src/main/res/layout/activity_hosts.xml | 52 --- app/src/main/res/layout/dialog_hosts.xml | 53 --- app/src/main/res/values-ja/strings.xml | 13 - app/src/main/res/values-zh-rCN/strings.xml | 13 - app/src/main/res/values-zh-rHK/strings.xml | 13 - app/src/main/res/values-zh-rTW/strings.xml | 13 - app/src/main/res/values/strings.xml | 16 - app/src/main/res/xml/advanced_settings.xml | 13 - 15 files changed, 2 insertions(+), 930 deletions(-) delete mode 100644 app/src/main/java/com/hippo/ehviewer/Hosts.java delete mode 100644 app/src/main/java/com/hippo/ehviewer/client/EhDns.kt delete mode 100644 app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.kt delete mode 100644 app/src/main/res/layout/activity_hosts.xml delete mode 100644 app/src/main/res/layout/dialog_hosts.xml diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt index 71c005a45..399d0b02d 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt @@ -16,7 +16,6 @@ package com.hippo.ehviewer import android.app.Activity -import android.content.ComponentCallbacks2 import android.text.Html import android.text.method.LinkMovementMethod import android.view.View @@ -29,7 +28,6 @@ import coil.ImageLoaderFactory import coil.disk.DiskCache import coil.util.DebugLogger import com.hippo.ehviewer.client.EhCookieStore -import com.hippo.ehviewer.client.EhDns import com.hippo.ehviewer.client.EhEngine import com.hippo.ehviewer.client.EhTagDatabase import com.hippo.ehviewer.client.data.GalleryDetail @@ -165,13 +163,6 @@ class EhApplication : SceneApplication(), ImageLoaderFactory { } } - override fun onTrimMemory(level: Int) { - super.onTrimMemory(level) - if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) { - galleryDetailCache.evictAll() - } - } - fun putGlobalStuff(o: Any): Int { val id = mIdGenerator.nextId() mGlobalStuffMap[id] = o @@ -220,11 +211,11 @@ class EhApplication : SceneApplication(), ImageLoaderFactory { val nonCacheOkHttpClient by lazy { OkHttpClient.Builder().apply { cookieJar(EhCookieStore) - dns(EhDns) proxySelector(ehProxySelector) addInterceptor(CloudflareInterceptor(application)) }.build() } + val noRedirectOkHttpClient by lazy { nonCacheOkHttpClient.newBuilder() .followRedirects(false) @@ -246,8 +237,6 @@ class EhApplication : SceneApplication(), ImageLoaderFactory { } } - val hosts by lazy { Hosts(application, "hosts.db") } - val favouriteStatusRouter by lazy { FavouriteStatusRouter() } val ehDatabase by lazy { buildMainDB(application) } diff --git a/app/src/main/java/com/hippo/ehviewer/Hosts.java b/app/src/main/java/com/hippo/ehviewer/Hosts.java deleted file mode 100644 index 0b0dc7e5c..000000000 --- a/app/src/main/java/com/hippo/ehviewer/Hosts.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * 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; - -/* - * Created by Hippo on 2018/3/21. - */ - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.util.Pair; - -import androidx.annotation.Nullable; - -import com.hippo.database.MSQLiteBuilder; -import com.hippo.util.SqlUtils; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; - -public class Hosts { - private static final int VERSION_1 = 1; - private static final String TABLE_HOSTS = "HOSTS"; - private static final String COLUMN_HOST = "HOST"; - private static final String COLUMN_IP = "IP"; - - private static final int DB_VERSION = VERSION_1; - - private final SQLiteDatabase db; - - public Hosts(Context context, String name) { - SQLiteOpenHelper helper = new MSQLiteBuilder() - .version(VERSION_1) - .createTable(TABLE_HOSTS) - .insertColumn(TABLE_HOSTS, COLUMN_HOST, String.class) - .insertColumn(TABLE_HOSTS, COLUMN_IP, String.class) - .build(context, name, DB_VERSION); - db = helper.getWritableDatabase(); - } - - @Nullable - public static InetAddress toInetAddress(String host, String ip) { - if (!isValidHost(host)) { - return null; - } - - if (ip == null) { - return null; - } - - byte[] bytes = parseV4(ip); - if (bytes == null) { - bytes = parseV6(ip); - } - if (bytes == null) { - return null; - } - - try { - return InetAddress.getByAddress(host, bytes); - } catch (UnknownHostException e) { - return null; - } - } - - /** - * Returns true if the host is valid. - */ - public static boolean isValidHost(String host) { - if (host == null) { - return false; - } - - if (host.length() > 253) { - return false; - } - - int labelLength = 0; - for (int i = 0, n = host.length(); i < n; i++) { - char ch = host.charAt(i); - - if (ch == '.') { - if (labelLength < 1 || labelLength > 63) { - return false; - } - labelLength = 0; - } else { - labelLength++; - } - - if ((ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '-' && ch != '.') { - return false; - } - } - - return labelLength >= 1 && labelLength <= 63; - } - - /** - * Returns true if ips are valid. - */ - public static boolean isValidIp(String ips) { - if (ips == null) { - return false; - } - String[] list = ips.split("\\+"); - for (String ip : list) { - if (parseV4(ip) == null && parseV6(ip) == null) { - return false; - } - } - return true; - } - - // org.xbill.DNS.Address.parseV4 - @Nullable - private static byte[] parseV4(String s) { - int numDigits; - int currentOctet; - byte[] values = new byte[4]; - int currentValue; - int length = s.length(); - - currentOctet = 0; - currentValue = 0; - numDigits = 0; - for (int i = 0; i < length; i++) { - char c = s.charAt(i); - if (c >= '0' && c <= '9') { - /* Can't have more than 3 digits per octet. */ - if (numDigits == 3) - return null; - /* Octets shouldn't start with 0, unless they are 0. */ - if (numDigits > 0 && currentValue == 0) - return null; - numDigits++; - currentValue *= 10; - currentValue += (c - '0'); - /* 255 is the maximum value for an octet. */ - if (currentValue > 255) - return null; - } else if (c == '.') { - /* Can't have more than 3 dots. */ - if (currentOctet == 3) - return null; - /* Two consecutive dots are bad. */ - if (numDigits == 0) - return null; - values[currentOctet++] = (byte) currentValue; - currentValue = 0; - numDigits = 0; - } else - return null; - } - /* Must have 4 octets. */ - if (currentOctet != 3) - return null; - /* The fourth octet can't be empty. */ - if (numDigits == 0) - return null; - values[currentOctet] = (byte) currentValue; - return values; - } - - // org.xbill.DNS.Address.parseV6 - @Nullable - private static byte[] parseV6(String s) { - int range = -1; - byte[] data = new byte[16]; - - String[] tokens = s.split(":", -1); - - int first = 0; - int last = tokens.length - 1; - - if (tokens[0].length() == 0) { - // If the first two tokens are empty, it means the string - // started with ::, which is fine. If only the first is - // empty, the string started with :, which is bad. - if (last - first > 0 && tokens[1].length() == 0) - first++; - else - return null; - } - - if (tokens[last].length() == 0) { - // If the last two tokens are empty, it means the string - // ended with ::, which is fine. If only the last is - // empty, the string ended with :, which is bad. - if (last - first > 0 && tokens[last - 1].length() == 0) - last--; - else - return null; - } - - if (last - first + 1 > 8) - return null; - - int i, j; - for (i = first, j = 0; i <= last; i++) { - if (tokens[i].length() == 0) { - if (range >= 0) - return null; - range = j; - continue; - } - - if (tokens[i].indexOf('.') >= 0) { - // An IPv4 address must be the last component - if (i < last) - return null; - // There can't have been more than 6 components. - if (i > 6) - return null; - byte[] v4addr = parseV4(tokens[i]); - if (v4addr == null) - return null; - for (int k = 0; k < 4; k++) - data[j++] = v4addr[k]; - break; - } - - try { - for (int k = 0; k < tokens[i].length(); k++) { - char c = tokens[i].charAt(k); - if (Character.digit(c, 16) < 0) - return null; - } - int x = Integer.parseInt(tokens[i], 16); - if (x > 0xFFFF || x < 0) - return null; - data[j++] = (byte) (x >>> 8); - data[j++] = (byte) (x & 0xFF); - } catch (NumberFormatException e) { - return null; - } - } - - if (j < 16 && range < 0) - return null; - - if (range >= 0) { - int empty = 16 - j; - System.arraycopy(data, range, data, range + empty, j - range); - for (i = range; i < range + empty; i++) - data[i] = 0; - } - - return data; - } - - /** - * Gets a InetAddress with the host. - */ - @Nullable - public List get(String host) { - if (!isValidHost(host)) { - return null; - } - try (Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_HOSTS + " WHERE " + COLUMN_HOST + " = ?;", new String[]{host})) { - if (cursor.moveToNext()) { - String[] ips = SqlUtils.getString(cursor, COLUMN_IP, null).split("\\+"); - List addresses = new ArrayList<>(); - for (String ip : ips) { - addresses.add(toInetAddress(host, ip)); - } - return addresses; - } else { - return null; - } - } - } - - private boolean contains(String host) { - try (Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_HOSTS + " WHERE " + COLUMN_HOST + " = ?;", new String[]{host})) { - return cursor.moveToNext(); - } - } - - /** - * Puts the host-ip pair into this hosts. - */ - public boolean put(String host, String ip) { - if (!isValidHost(host) || !isValidIp(ip)) { - return false; - } - - ContentValues values = new ContentValues(); - values.put(COLUMN_HOST, host); - values.put(COLUMN_IP, ip); - - if (contains(host)) { - db.update(TABLE_HOSTS, values, COLUMN_HOST + " = ?", new String[]{host}); - } else { - db.insert(TABLE_HOSTS, null, values); - } - - return true; - } - - /** - * Puts delete the entry with the host. - */ - public void delete(String host) { - db.delete(TABLE_HOSTS, COLUMN_HOST + " = ?", new String[]{host}); - } - - /** - * Get all data from this host. - */ - public List> getAll() { - List> result = new ArrayList<>(); - - try (Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_HOSTS + ";", null)) { - while (cursor.moveToNext()) { - String host = SqlUtils.getString(cursor, COLUMN_HOST, null); - String ip = SqlUtils.getString(cursor, COLUMN_IP, null); - result.add(new Pair<>(host, ip)); - } - } - return result; - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index 173758281..a6cd47fd8 100644 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -176,8 +176,6 @@ object Settings { private val DEFAULT_PROXY_IP: String? = null private const val KEY_PROXY_PORT = "proxy_port" private const val DEFAULT_PROXY_PORT = -1 - private const val KEY_BUILT_IN_HOSTS = "built_in_hosts_2" - private const val DEFAULT_BUILT_IN_HOSTS = false private const val KEY_USER_AGENT = "user_agent" private const val KEY_APP_LINK_VERIFY_TIP = "app_link_verify_tip" private const val DEFAULT_APP_LINK_VERIFY_TIP = false @@ -663,9 +661,6 @@ object Settings { putInt(KEY_PROXY_PORT, value) } - val builtInHosts: Boolean - get() = getBoolean(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS) - val userAgent: String? get() = getString(KEY_USER_AGENT, CHROME_USER_AGENT) fun putUserAgent(value: String?) { diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt b/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt deleted file mode 100644 index 2eac37a7b..000000000 --- a/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.client - -import com.hippo.ehviewer.EhApplication -import com.hippo.ehviewer.Hosts -import com.hippo.ehviewer.Settings -import okhttp3.Dns -import java.net.InetAddress -import java.net.UnknownHostException - -object EhDns : Dns { - private val hosts = EhApplication.hosts - private val builtInHosts: MutableMap> = mutableMapOf() - - init { - /* Pair(ip: String!, blockedByCCP: Boolean!) */ - val ehHosts = arrayOf( - Pair("104.20.18.168", false), - Pair("104.20.19.168", false), - Pair("172.67.2.238", false), - ) - val ehgtHosts = arrayOf( - Pair("81.171.10.48", false), - Pair("178.162.139.24", false), - Pair("62.112.8.21", false), - Pair("89.39.106.43", false), - Pair("109.236.85.28", false), - Pair("2a00:7c80:0:123::3a85", false), - Pair("2a00:7c80:0:12d::38a1", false), - Pair("2a00:7c80:0:13b::37a4", false), - ) - val exHosts = arrayOf( - Pair("178.175.128.251", false), - Pair("178.175.128.252", false), - Pair("178.175.128.253", false), - Pair("178.175.128.254", false), - Pair("178.175.129.251", false), - Pair("178.175.129.252", false), - Pair("178.175.129.253", false), - Pair("178.175.129.254", false), - Pair("178.175.132.19", false), - Pair("178.175.132.20", false), - Pair("178.175.132.21", false), - Pair("178.175.132.22", false), - ) - - put( - "e-hentai.org", - *ehHosts, - ) - put( - "forums.e-hentai.org", - *ehHosts, - ) - put( - "repo.e-hentai.org", - *ehHosts, - ) - put( - "api.e-hentai.org", - *ehHosts, - Pair("5.79.104.110", false), - Pair("37.48.81.204", false), - Pair("37.48.92.161", false), - Pair("212.7.200.104", false), - Pair("212.7.202.51", false), - ) - put( - "ehgt.org", - *ehgtHosts, - ) - put( - "gt0.ehgt.org", - *ehgtHosts, - ) - put( - "gt1.ehgt.org", - *ehgtHosts, - ) - put( - "gt2.ehgt.org", - *ehgtHosts, - ) - put( - "gt3.ehgt.org", - *ehgtHosts, - ) - put( - "ul.ehgt.org", - *ehgtHosts, - ) - - put( - "exhentai.org", - *exHosts, - ) - put( - "s.exhentai.org", - *exHosts, - ) - - put( - "raw.githubusercontent.com", - Pair("151.101.0.133", false), - Pair("151.101.64.133", false), - Pair("151.101.128.133", false), - Pair("151.101.192.133", false), - ) - } - - private fun put( - host: String, - vararg ips: Pair, - ) { - builtInHosts[host] = ips.mapNotNull { pair -> - Hosts.toInetAddress(host, pair.first) - } - } - - @Throws(UnknownHostException::class) - override fun lookup(hostname: String): List { - val address = hosts[hostname] ?: builtInHosts[hostname].takeIf { Settings.builtInHosts } - ?: Dns.SYSTEM.lookup(hostname) - return address.shuffled() - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt b/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt index 239fb5716..68f7bf34a 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt @@ -50,6 +50,7 @@ abstract class EhActivity : AppCompatActivity() { theme.applyStyle(getThemeStyleRes(), true) } + @Suppress("DEPRECATION") override fun onCreate(savedInstanceState: Bundle?) { layoutInflater.factory2 = LayoutInflaterFactory(delegate).addOnViewCreatedListener(WindowInsetsHelper.LISTENER) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.kt index 0b6cc47bd..f542a4c43 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.kt @@ -60,7 +60,6 @@ open class BasePreferenceFragment : "mytags" -> MyTagsFragment() "filter" -> FilterFragment() "security" -> SetSecurityFragment() - "hosts" -> HostsFragment() else -> null } fragment?.let { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.kt deleted file mode 100644 index c23c4b5c5..000000000 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.kt +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright 2022 Tarsin Norbin - * - * This file is part of EhViewer - * - * EhViewer is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * EhViewer is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with EhViewer. - * If not, see . - */ -package com.hippo.ehviewer.ui.fragment - -import android.annotation.SuppressLint -import android.app.Dialog -import android.content.DialogInterface -import android.os.Bundle -import android.util.Pair -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.TextView -import androidx.appcompat.app.AlertDialog -import androidx.fragment.app.DialogFragment -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.floatingactionbutton.FloatingActionButton -import com.google.android.material.textfield.TextInputLayout -import com.hippo.easyrecyclerview.EasyRecyclerView -import com.hippo.easyrecyclerview.LinearDividerItemDecoration -import com.hippo.ehviewer.EhApplication -import com.hippo.ehviewer.Hosts -import com.hippo.ehviewer.R -import com.hippo.view.ViewTransition -import com.hippo.yorozuya.LayoutUtils -import com.hippo.yorozuya.ViewUtils -import rikka.core.res.resolveColor - -class HostsFragment : BaseFragment(), View.OnClickListener { - private var hosts: Hosts? = null - private var data: List>? = null - private var mViewTransition: ViewTransition? = null - private var adapter: HostsAdapter? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - EhApplication.hosts.apply { - hosts = this - data = all - } - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View? { - val view = inflater.inflate(R.layout.activity_hosts, container, false) - val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view) - val tip = ViewUtils.`$$`(view, R.id.tip) as TextView - mViewTransition = ViewTransition(recyclerView, tip) - val fab = view.findViewById(R.id.fab) - adapter = HostsAdapter() - recyclerView.adapter = adapter - recyclerView.layoutManager = - LinearLayoutManager(requireActivity(), RecyclerView.VERTICAL, false) - val decoration = LinearDividerItemDecoration( - LinearDividerItemDecoration.VERTICAL, - requireActivity().theme.resolveColor(R.attr.dividerColor), - LayoutUtils.dp2pix(requireActivity(), 1f), - ) - decoration.setShowLastDivider(true) - recyclerView.addItemDecoration(decoration) - recyclerView.setHasFixedSize(true) - fab.setOnClickListener(this) - return view - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - updateView(false) - } - - fun onItemClick(position: Int): Boolean { - val pair = data!![position] - val args = Bundle() - args.putString(KEY_HOST, pair.first) - args.putString(KEY_IP, pair.second) - val fragment: DialogFragment = EditHostDialogFragment() - fragment.arguments = args - fragment.show(childFragmentManager, DIALOG_TAG_EDIT_HOST) - return true - } - - override fun onClick(v: View) { - AddHostDialogFragment().show(childFragmentManager, DIALOG_TAG_ADD_HOST) - } - - @SuppressLint("NotifyDataSetChanged") - private fun updateView(animation: Boolean) { - if (null == mViewTransition) { - return - } - data = hosts!!.all - if ((data as MutableList>?)?.isEmpty() == true) { - mViewTransition!!.showView(1, animation) - } else { - mViewTransition!!.showView(0, animation) - } - adapter!!.notifyDataSetChanged() - } - - override fun getFragmentTitle(): Int { - return R.string.hosts - } - - abstract class HostDialogFragment : DialogFragment() { - private var hostsFragment: HostsFragment? = null - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - hostsFragment = parentFragment as HostsFragment? - val view = layoutInflater.inflate(R.layout.dialog_hosts, null, false) - val host = view.findViewById(R.id.host) - val ip = view.findViewById(R.id.ip) - val arguments = arguments - if (savedInstanceState == null && arguments != null) { - host.text = arguments.getString(KEY_HOST) - ip.text = arguments.getString(KEY_IP) - } - val builder = AlertDialog.Builder(requireContext()) - builder.setView(view) - onCreateDialogBuilder(builder) - val dialog = builder.create() - dialog.setOnShowListener { d: DialogInterface -> onCreateDialog(d as AlertDialog) } - return dialog - } - - protected abstract fun onCreateDialogBuilder(builder: AlertDialog.Builder) - protected abstract fun onCreateDialog(dialog: AlertDialog) - protected fun put(dialog: AlertDialog) { - val host = dialog.findViewById(R.id.host) - val ip = dialog.findViewById(R.id.ip) - if (host == null || ip == null) { - return - } - val hostString = host.text.toString().trim { it <= ' ' }.lowercase() - val ipString = ip.text.toString().trim { it <= ' ' } - if (!Hosts.isValidHost(hostString)) { - val hostInputLayout = - dialog.findViewById(R.id.host_input_layout) ?: return - hostInputLayout.error = getString(R.string.invalid_host) - return - } - if (!Hosts.isValidIp(ipString)) { - val ipInputLayout = - dialog.findViewById(R.id.ip_input_layout) ?: return - ipInputLayout.error = getString(R.string.invalid_ip) - return - } - hostsFragment!!.hosts!!.put(hostString, ipString) - hostsFragment!!.updateView(true) - dialog.dismiss() - } - - protected fun delete(dialog: AlertDialog) { - val host = dialog.findViewById(R.id.host) ?: return - val hostString = host.text.toString().trim { it <= ' ' }.lowercase() - hostsFragment!!.hosts!!.delete(hostString) - hostsFragment!!.updateView(true) - dialog.dismiss() - } - } - - class AddHostDialogFragment : HostDialogFragment() { - override fun onCreateDialogBuilder(builder: AlertDialog.Builder) { - builder.setTitle(R.string.add_host) - builder.setPositiveButton(R.string.add_host_add, null) - builder.setNegativeButton(android.R.string.cancel, null) - } - - override fun onCreateDialog(dialog: AlertDialog) { - dialog.getButton(DialogInterface.BUTTON_POSITIVE) - .setOnClickListener { put(dialog) } - } - } - - class EditHostDialogFragment : HostDialogFragment() { - override fun onCreateDialogBuilder(builder: AlertDialog.Builder) { - builder.setTitle(R.string.edit_host) - builder.setPositiveButton(R.string.edit_host_confirm, null) - builder.setNegativeButton(R.string.edit_host_delete, null) - } - - override fun onCreateDialog(dialog: AlertDialog) { - val hostInputLayout = - dialog.findViewById(R.id.host_input_layout) ?: return - hostInputLayout.isEnabled = false - dialog.getButton(DialogInterface.BUTTON_POSITIVE) - .setOnClickListener { put(dialog) } - dialog.getButton(DialogInterface.BUTTON_NEGATIVE) - .setOnClickListener { delete(dialog) } - } - } - - private class HostsHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val host: TextView - val ip: TextView - - init { - host = itemView.findViewById(R.id.host) - ip = itemView.findViewById(R.id.ip) - } - } - - private inner class HostsAdapter : RecyclerView.Adapter() { - private val inflater = layoutInflater - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HostsHolder { - return HostsHolder(inflater.inflate(R.layout.item_hosts, parent, false)) - } - - override fun onBindViewHolder(holder: HostsHolder, position: Int) { - val pair = data!![position] - holder.host.text = pair.first - holder.ip.text = pair.second - holder.itemView.setOnClickListener { onItemClick(position) } - } - - override fun getItemCount(): Int { - return data!!.size - } - } - - companion object { - private val DIALOG_TAG_ADD_HOST = AddHostDialogFragment::class.java.name - private val DIALOG_TAG_EDIT_HOST = EditHostDialogFragment::class.java.name - private const val KEY_HOST = "com.hippo.ehviewer.ui.fragment.HostsFragment.HOST" - private const val KEY_IP = "com.hippo.ehviewer.ui.fragment.HostsFragment.IP" - } -} diff --git a/app/src/main/res/layout/activity_hosts.xml b/app/src/main/res/layout/activity_hosts.xml deleted file mode 100644 index c92eb36ab..000000000 --- a/app/src/main/res/layout/activity_hosts.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/layout/dialog_hosts.xml b/app/src/main/res/layout/dialog_hosts.xml deleted file mode 100644 index 96770d046..000000000 --- a/app/src/main/res/layout/dialog_hosts.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 7be9c16f1..476ade966 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -384,10 +384,6 @@ 閲覧キャッシュのサイズ アプリ言語(Language) プロキシ - 既定hosts.txt - ホストをアプリ既定のIPにマッピング\nカスタムhosts.txtに上書きされます。 - カスタムhosts.txt - ホスト名をIPにマッピング\n既定のhosts.txtを上書きできます。 データをエクスポート ダウンロードリストやクイック検索などのデータを外部ストレージにエクスポートします データを%sにエクスポート @@ -431,15 +427,6 @@ ホスト名又はIP ポート 入力したポートは無効です - - カスタムhosts.txt - ホストを追加 - 追加 - ホストを編集 - 適用 - 削除 - 無効なホストです - 無効なIPです 無効なステータスコード:%d diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 2bfbf14c2..db49034f1 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -511,10 +511,6 @@ 阅读缓存大小 App 界面语言 代理 - 内置 hosts.txt - 应用提供的主机到 IP 的映射\n可被自定义 hosts.txt 覆盖 - 自定义 hosts.txt - 将主机名称映射到相应的 IP 地址\n可覆盖内置 hosts.txt 备份收藏列表 备份云端收藏列表到本地 正在备份收藏列表 %s @@ -571,15 +567,6 @@ 主机或 IP 端口 无效的端口 - - 自定义 hosts.txt - 添加 host - 添加 - 编辑 host - 确认 - 删除 - 无效的 host - 无效的 IP 错误状态码:%d diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 4a026177f..b20c4bcb9 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -511,10 +511,6 @@ 閲讀緩存大小 App 界面語言 代理 - 內置 hosts.txt - 應用提供的主機到 IP 的映射\n可被自定義 hosts.txt 覆蓋 - 自定義 hosts.txt - 將主機名稱映射到相應的 IP 地址\n可覆蓋內置 hosts.txt 備份收藏列表 備份雲端收藏列表到本地 正在備份收藏列表 %s @@ -571,15 +567,6 @@ 主機或 IP 端口 無效的端口 - - 自定義 hosts.txt - 添加 host - 添加 - 編輯 host - 確認 - 刪除 - 無效的 host - 無效的 IP 錯誤狀態碼:%d diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 22395404d..e43a9a7c2 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -511,10 +511,6 @@ 閱讀快取大小 App 介面語言 代理 - 內建 hosts.txt - 應用提供的主機到 IP 的對映\n可被自定義 hosts.txt 覆蓋 - 自定義 hosts.txt - 將主機名稱對映到相應的 IP 位址\n可覆蓋內建 hosts.txt 備份收藏列表 備份雲端收藏列表到本機 正在備份收藏列表 %s @@ -571,15 +567,6 @@ 主機或 IP 通訊埠 無效的通訊埠 - - 自訂 hosts.txt - 加入 host - 加入 - 編輯 host - 確認 - 刪除 - 無效的 host - 無效的 IP 錯誤狀態碼:%d diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0eb95f6cc..db76e3ffd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -539,10 +539,6 @@ Proxy %1$s %2$s:%3$d %1$s - Built-in hosts.txt - Apply the built-in host-to-IP mapping provided by the app.\nIt can be overridden by custom hosts.txt - Custom hosts.txt - Map hostnames to IP addresses.\nIt can override built-in hosts.txt User Agent Backup favorite list Backup remote favorite list to local @@ -608,18 +604,6 @@ Host or IP Port Invalid port - - Custom hosts.txt - hosts.txt - Add a host - Host - IP1(+IP2+IP3…) - Add - Edit the host - Confirm - Delete - Invalid host - Invalid IP Bad Request diff --git a/app/src/main/res/xml/advanced_settings.xml b/app/src/main/res/xml/advanced_settings.xml index b102f14d3..b8d3289f5 100644 --- a/app/src/main/res/xml/advanced_settings.xml +++ b/app/src/main/res/xml/advanced_settings.xml @@ -60,19 +60,6 @@ android:title="@string/settings_advanced_proxy" app:iconSpaceReserved="false" /> - - - -