Merge branch 'master' into v2.4

This commit is contained in:
Mygod
2019-04-28 14:05:52 +08:00
12 changed files with 66 additions and 48 deletions

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -9,9 +9,8 @@ import androidx.annotation.RequiresApi
import androidx.core.net.toUri
import androidx.core.os.bundleOf
import androidx.core.view.updatePaddingRelative
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.DebugHelper
@@ -105,8 +104,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
fun updateErrorMessage(errored: List<String>) {
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"
@@ -148,15 +146,14 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
override fun stop() = TetheringManager.stop(TetheringManager.TETHERING_USB)
}
@RequiresApi(24)
class Bluetooth(parent: TetheringFragment) : TetherManager(parent), LifecycleObserver {
class Bluetooth(parent: TetheringFragment) : TetherManager(parent), DefaultLifecycleObserver {
private val tethering = BluetoothTethering(parent.requireContext()) { onTetheringStarted() }
init {
parent.lifecycle.addObserver(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() = tethering.close()
override fun onDestroy(owner: LifecycleOwner) = tethering.close()
override val title get() = parent.getString(R.string.tethering_manage_bluetooth)
override val tetherType get() = TetherType.BLUETOOTH

View File

@@ -5,17 +5,15 @@ import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import kotlin.reflect.KClass
/**
* owner also needs to be Context/Fragment.
*/
class ServiceForegroundConnector(private val owner: LifecycleOwner, private val connection: ServiceConnection,
private val clazz: KClass<out Service>) : LifecycleObserver {
private val clazz: KClass<out Service>) : DefaultLifecycleObserver {
init {
owner.lifecycle.addObserver(this)
}
@@ -26,12 +24,10 @@ class ServiceForegroundConnector(private val owner: LifecycleOwner, private val
else -> throw UnsupportedOperationException("Unsupported owner")
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onStart() {
override fun onStart(owner: LifecycleOwner) {
val context = context
context.bindService(Intent(context, clazz.java), connection, Context.BIND_AUTO_CREATE)
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onStop() = context.stopAndUnbind(connection)
override fun onStop(owner: LifecycleOwner) = context.stopAndUnbind(connection)
}

View File

@@ -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 -> {

View File

@@ -5,9 +5,9 @@ import android.os.Looper
import android.view.View
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.LifecycleOwner
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.util.readableMessage
import com.google.android.material.snackbar.Snackbar
@@ -32,17 +32,15 @@ sealed class SmartSnackbar {
}.readableMessage)
}
class Register(lifecycle: Lifecycle, private val view: View) : LifecycleObserver {
class Register(lifecycle: Lifecycle, private val view: View) : DefaultLifecycleObserver {
init {
lifecycle.addObserver(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun onResume() {
override fun onResume(owner: LifecycleOwner) {
holder = view
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun onPause() {
override fun onPause(owner: LifecycleOwner) {
if (holder === view) holder = null
}
}