diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterFragment.kt index 7e9e6f31..b34b5522 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterFragment.kt @@ -50,6 +50,7 @@ class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickL ContextCompat.startForegroundService(context, Intent(context, RepeaterService::class.java)) } RepeaterService.Status.ACTIVE -> if (!value) binder.shutdown() + else -> { } } } @@ -80,13 +81,13 @@ class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickL val icon get() = TetherType.ofInterface(iface, p2pInterface).icon val title get() = listOf(ip, mac).filter { !it.isNullOrEmpty() }.joinToString() - val description get() = when (neighbour?.state) { - IpNeighbour.State.INCOMPLETE, null -> "Connecting to $iface" - IpNeighbour.State.VALID -> "Connected to $iface" - IpNeighbour.State.VALID_DELAY -> "Connected to $iface (losing)" - IpNeighbour.State.FAILED -> "Failed to connect to $iface" + val description get() = getString(when (neighbour?.state) { + IpNeighbour.State.INCOMPLETE, null -> R.string.connected_state_incomplete + IpNeighbour.State.VALID -> R.string.connected_state_valid + IpNeighbour.State.VALID_DELAY -> R.string.connected_state_valid_delay + IpNeighbour.State.FAILED -> R.string.connected_state_failed else -> throw IllegalStateException() - } + }, iface) } private class ClientViewHolder(val binding: ListitemClientBinding) : RecyclerView.ViewHolder(binding.root) private inner class ClientAdapter : RecyclerView.Adapter() { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt index b5eec7bc..b64035c4 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt @@ -60,7 +60,7 @@ data class IpNeighbour(val ip: String, val dev: String, val lladdr: String, val private const val ARP_CACHE_EXPIRE = 1L * 1000 * 1000 * 1000 private var arpCache = emptyList>() private var arpCacheTime = -ARP_CACHE_EXPIRE - fun arp(): List> { + private fun arp(): List> { if (System.nanoTime() - arpCacheTime >= ARP_CACHE_EXPIRE) try { arpCache = File("/proc/net/arp").bufferedReader().useLines { it.map { it.split(spaces) } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt index 02768228..08e79668 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt @@ -1,8 +1,9 @@ package be.mygod.vpnhotspot.net import android.content.res.Resources -import be.mygod.vpnhotspot.App +import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.R +import java.util.regex.Pattern enum class TetherType { NONE, WIFI_P2P, USB, WIFI, WIMAX, BLUETOOTH; @@ -15,21 +16,30 @@ enum class TetherType { } companion object { + private val usbRegexes: List + private val wifiRegexes: List + private val wimaxRegexes: List + private val bluetoothRegexes: List + /** * Source: https://android.googlesource.com/platform/frameworks/base/+/61fa313/core/res/res/values/config.xml#328 */ - private val usbRegexes = App.app.resources.getStringArray(Resources.getSystem() - .getIdentifier("config_tether_usb_regexs", "array", "android")) - .map { it.toPattern() } - private val wifiRegexes = App.app.resources.getStringArray(Resources.getSystem() - .getIdentifier("config_tether_wifi_regexs", "array", "android")) - .map { it.toPattern() } - private val wimaxRegexes = App.app.resources.getStringArray(Resources.getSystem() - .getIdentifier("config_tether_wimax_regexs", "array", "android")) - .map { it.toPattern() } - private val bluetoothRegexes = App.app.resources.getStringArray(Resources.getSystem() - .getIdentifier("config_tether_bluetooth_regexs", "array", "android")) - .map { it.toPattern() } + init { + val appRes = app.resources + val sysRes = Resources.getSystem() + usbRegexes = appRes.getStringArray(sysRes + .getIdentifier("config_tether_usb_regexs", "array", "android")) + .map { it.toPattern() } + wifiRegexes = appRes.getStringArray(sysRes + .getIdentifier("config_tether_wifi_regexs", "array", "android")) + .map { it.toPattern() } + wimaxRegexes = appRes.getStringArray(sysRes + .getIdentifier("config_tether_wimax_regexs", "array", "android")) + .map { it.toPattern() } + bluetoothRegexes = appRes.getStringArray(sysRes + .getIdentifier("config_tether_bluetooth_regexs", "array", "android")) + .map { it.toPattern() } + } fun ofInterface(iface: String, p2pDev: String? = null) = when { iface == p2pDev -> WIFI_P2P diff --git a/mobile/src/main/res/layout/fragment_repeater.xml b/mobile/src/main/res/layout/fragment_repeater.xml index 24f99a7d..8c110f24 100644 --- a/mobile/src/main/res/layout/fragment_repeater.xml +++ b/mobile/src/main/res/layout/fragment_repeater.xml @@ -83,7 +83,7 @@ android:layout_height="wrap_content" android:paddingStart="16dp" android:paddingEnd="16dp" - android:text="@string/repeater_connected_devices" + android:text="@string/connected_devices" android:textAppearance="@style/TextAppearance.AppCompat.Medium"/> + android:text="@string/tethering_manage"/> diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index 73eef4c5..10efa167 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -7,7 +7,7 @@ 中继名称 中继密码 - 已连接设备 + 已连接设备 输入 PIN 一键加密 请在 2 分钟内在需要连接的设备上使用一键加密以连接到此中继。 diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index c93878a8..aec195ef 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -7,7 +7,6 @@ Network name Password - Connected devices WPS Enter PIN Push Button @@ -23,7 +22,6 @@ Failed to reset credentials (reason: %s) Service inactive - Connecting… VPN unavailable, please enable any VPN Root unavailable Wi-Fi direct unavailable @@ -37,6 +35,14 @@ no service requests added unknown #%d + Manage… + + Connected devices + Connecting to %s + Connected to %s + Connected to %s (losing) + Failed to connect to %s + Service Downstream DNS server:port Clean/reapply routing rules