From 243d103ca77ffac5b9e5197517dfd85bcd50fc48 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 14 Apr 2019 13:23:21 +0800 Subject: [PATCH] Refine code style --- .../vpnhotspot/LocalOnlyHotspotService.kt | 22 ++++++++----------- .../be/mygod/vpnhotspot/TetheringService.kt | 2 +- .../mygod/vpnhotspot/manage/TetherManager.kt | 3 +-- .../be/mygod/vpnhotspot/util/SpanFormatter.kt | 3 +-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index fe7cb571..2277ccc4 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -88,19 +88,15 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { } override fun onFailed(reason: Int) { - val message = getString(R.string.tethering_temp_hotspot_failure, - when (reason) { - WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL -> - getString(R.string.tethering_temp_hotspot_failure_no_channel) - WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC -> - getString(R.string.tethering_temp_hotspot_failure_generic) - WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE -> - getString(R.string.tethering_temp_hotspot_failure_incompatible_mode) - WifiManager.LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED -> - getString(R.string.tethering_temp_hotspot_failure_tethering_disallowed) - else -> getString(R.string.failure_reason_unknown, reason) - }) - SmartSnackbar.make(message).show() + SmartSnackbar.make(getString(R.string.tethering_temp_hotspot_failure, when (reason) { + ERROR_NO_CHANNEL -> getString(R.string.tethering_temp_hotspot_failure_no_channel) + ERROR_GENERIC -> getString(R.string.tethering_temp_hotspot_failure_generic) + ERROR_INCOMPATIBLE_MODE -> getString(R.string.tethering_temp_hotspot_failure_incompatible_mode) + ERROR_TETHERING_DISALLOWED -> { + getString(R.string.tethering_temp_hotspot_failure_tethering_disallowed) + } + else -> getString(R.string.failure_reason_unknown, reason) + })).show() startFailure() } }, null) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index 79af6088..00ff8fcf 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -36,7 +36,7 @@ class TetheringService : IpNeighbourMonitoringService() { RoutingManager(caller, downstream, TetherType.ofInterface(downstream).isWifi) { override fun Routing.configure() { forward() - masquerade(RoutingManager.masqueradeMode) + masquerade(masqueradeMode) if (app.pref.getBoolean("service.disableIpv6", true)) disableIpv6() commit() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index 3ca6a172..555a2595 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -105,8 +105,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), fun updateErrorMessage(errored: List) { data.text = errored.filter { TetherType.ofInterface(it) == tetherType }.joinToString("\n") { "$it: " + try { - val error = TetheringManager.getLastTetherError(it) - when (error) { + when (val error = TetheringManager.getLastTetherError(it)) { TetheringManager.TETHER_ERROR_NO_ERROR -> "TETHER_ERROR_NO_ERROR" TetheringManager.TETHER_ERROR_UNKNOWN_IFACE -> "TETHER_ERROR_UNKNOWN_IFACE" TetheringManager.TETHER_ERROR_SERVICE_UNAVAIL -> "TETHER_ERROR_SERVICE_UNAVAIL" diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt index 8ed8a93a..9cb55aae 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt @@ -59,9 +59,8 @@ object SpanFormatter { val argTerm = m.group(1) val modTerm = m.group(2) - val typeTerm = m.group(3) - val cookedArg = when (typeTerm) { + val cookedArg = when (val typeTerm = m.group(3)) { "%" -> "%" "n" -> "\n" else -> {