Remove unnecessary abstraction
This commit is contained in:
@@ -1,32 +0,0 @@
|
|||||||
package be.mygod.vpnhotspot.manage
|
|
||||||
|
|
||||||
import android.content.IntentFilter
|
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import be.mygod.vpnhotspot.net.TetheringManager
|
|
||||||
import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces
|
|
||||||
import be.mygod.vpnhotspot.util.KillableTileService
|
|
||||||
import be.mygod.vpnhotspot.util.broadcastReceiver
|
|
||||||
|
|
||||||
@RequiresApi(24)
|
|
||||||
abstract class TetherListeningTileService : KillableTileService() {
|
|
||||||
protected var tethered: List<String>? = null
|
|
||||||
|
|
||||||
private val receiver = broadcastReceiver { _, intent ->
|
|
||||||
tethered = intent.tetheredIfaces ?: return@broadcastReceiver
|
|
||||||
updateTile()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStartListening() {
|
|
||||||
super.onStartListening()
|
|
||||||
tethered = registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
|
||||||
?.tetheredIfaces
|
|
||||||
updateTile()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStopListening() {
|
|
||||||
unregisterReceiver(receiver)
|
|
||||||
super.onStopListening()
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract fun updateTile()
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot.manage
|
|||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
@@ -13,7 +14,10 @@ import be.mygod.vpnhotspot.R
|
|||||||
import be.mygod.vpnhotspot.TetheringService
|
import be.mygod.vpnhotspot.TetheringService
|
||||||
import be.mygod.vpnhotspot.net.TetherType
|
import be.mygod.vpnhotspot.net.TetherType
|
||||||
import be.mygod.vpnhotspot.net.TetheringManager
|
import be.mygod.vpnhotspot.net.TetheringManager
|
||||||
|
import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces
|
||||||
import be.mygod.vpnhotspot.net.wifi.WifiApManager
|
import be.mygod.vpnhotspot.net.wifi.WifiApManager
|
||||||
|
import be.mygod.vpnhotspot.util.KillableTileService
|
||||||
|
import be.mygod.vpnhotspot.util.broadcastReceiver
|
||||||
import be.mygod.vpnhotspot.util.readableMessage
|
import be.mygod.vpnhotspot.util.readableMessage
|
||||||
import be.mygod.vpnhotspot.util.stopAndUnbind
|
import be.mygod.vpnhotspot.util.stopAndUnbind
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@@ -21,27 +25,37 @@ import java.io.IOException
|
|||||||
import java.lang.reflect.InvocationTargetException
|
import java.lang.reflect.InvocationTargetException
|
||||||
|
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
sealed class TetheringTileService : TetherListeningTileService(), TetheringManager.OnStartTetheringCallback {
|
sealed class TetheringTileService : KillableTileService(), TetheringManager.OnStartTetheringCallback {
|
||||||
protected val tileOff by lazy { Icon.createWithResource(application, icon) }
|
protected val tileOff by lazy { Icon.createWithResource(application, icon) }
|
||||||
protected val tileOn by lazy { Icon.createWithResource(application, R.drawable.ic_quick_settings_tile_on) }
|
protected val tileOn by lazy { Icon.createWithResource(application, R.drawable.ic_quick_settings_tile_on) }
|
||||||
|
|
||||||
protected abstract val labelString: Int
|
protected abstract val labelString: Int
|
||||||
protected abstract val tetherType: TetherType
|
protected abstract val tetherType: TetherType
|
||||||
protected open val icon get() = tetherType.icon
|
protected open val icon get() = tetherType.icon
|
||||||
|
protected var tethered: List<String>? = null
|
||||||
protected val interested get() = tethered?.filter { TetherType.ofInterface(it) == tetherType }
|
protected val interested get() = tethered?.filter { TetherType.ofInterface(it) == tetherType }
|
||||||
protected var binder: TetheringService.Binder? = null
|
protected var binder: TetheringService.Binder? = null
|
||||||
|
|
||||||
|
private val receiver = broadcastReceiver { _, intent ->
|
||||||
|
tethered = intent.tetheredIfaces ?: return@broadcastReceiver
|
||||||
|
updateTile()
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun start()
|
protected abstract fun start()
|
||||||
protected abstract fun stop()
|
protected abstract fun stop()
|
||||||
|
|
||||||
override fun onStartListening() {
|
override fun onStartListening() {
|
||||||
bindService(Intent(this, TetheringService::class.java), this, Context.BIND_AUTO_CREATE)
|
|
||||||
super.onStartListening()
|
super.onStartListening()
|
||||||
|
bindService(Intent(this, TetheringService::class.java), this, Context.BIND_AUTO_CREATE)
|
||||||
|
tethered = registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
||||||
|
?.tetheredIfaces
|
||||||
|
updateTile()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStopListening() {
|
override fun onStopListening() {
|
||||||
super.onStopListening()
|
unregisterReceiver(receiver)
|
||||||
stopAndUnbind(this)
|
stopAndUnbind(this)
|
||||||
|
super.onStopListening()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||||
@@ -55,7 +69,7 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
binder = null
|
binder = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateTile() {
|
protected open fun updateTile() {
|
||||||
qsTile?.run {
|
qsTile?.run {
|
||||||
val interested = interested
|
val interested = interested
|
||||||
when {
|
when {
|
||||||
|
|||||||
Reference in New Issue
Block a user