Rename start/stopTethering to maintain consistency with framework
This commit is contained in:
@@ -44,7 +44,7 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) :
|
|||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
when (intent?.bluetoothState) {
|
when (intent?.bluetoothState) {
|
||||||
BluetoothAdapter.STATE_ON -> try {
|
BluetoothAdapter.STATE_ON -> try {
|
||||||
TetheringManager.start(TetheringManager.TETHERING_BLUETOOTH, true, pendingCallback!!)
|
TetheringManager.startTethering(TetheringManager.TETHERING_BLUETOOTH, true, pendingCallback!!)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
Toast.makeText(context, e.readableMessage, Toast.LENGTH_LONG).show()
|
Toast.makeText(context, e.readableMessage, Toast.LENGTH_LONG).show()
|
||||||
@@ -79,7 +79,7 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) :
|
|||||||
registerBluetoothStateListener(this)
|
registerBluetoothStateListener(this)
|
||||||
pendingCallback = callback
|
pendingCallback = callback
|
||||||
adapter.enable()
|
adapter.enable()
|
||||||
} else TetheringManager.start(TetheringManager.TETHERING_BLUETOOTH, true, callback)
|
} else TetheringManager.startTethering(TetheringManager.TETHERING_BLUETOOTH, true, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,8 +142,8 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
|||||||
override val tetherType get() = TetherType.WIFI
|
override val tetherType get() = TetherType.WIFI
|
||||||
override val type get() = VIEW_TYPE_WIFI
|
override val type get() = VIEW_TYPE_WIFI
|
||||||
|
|
||||||
override fun start() = TetheringManager.start(TetheringManager.TETHERING_WIFI, true, this)
|
override fun start() = TetheringManager.startTethering(TetheringManager.TETHERING_WIFI, true, this)
|
||||||
override fun stop() = TetheringManager.stop(TetheringManager.TETHERING_WIFI)
|
override fun stop() = TetheringManager.stopTethering(TetheringManager.TETHERING_WIFI)
|
||||||
}
|
}
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
class Usb(parent: TetheringFragment) : TetherManager(parent) {
|
class Usb(parent: TetheringFragment) : TetherManager(parent) {
|
||||||
@@ -151,8 +151,8 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
|||||||
override val tetherType get() = TetherType.USB
|
override val tetherType get() = TetherType.USB
|
||||||
override val type get() = VIEW_TYPE_USB
|
override val type get() = VIEW_TYPE_USB
|
||||||
|
|
||||||
override fun start() = TetheringManager.start(TetheringManager.TETHERING_USB, true, this)
|
override fun start() = TetheringManager.startTethering(TetheringManager.TETHERING_USB, true, this)
|
||||||
override fun stop() = TetheringManager.stop(TetheringManager.TETHERING_USB)
|
override fun stop() = TetheringManager.stopTethering(TetheringManager.TETHERING_USB)
|
||||||
}
|
}
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
class Bluetooth(parent: TetheringFragment) : TetherManager(parent), DefaultLifecycleObserver {
|
class Bluetooth(parent: TetheringFragment) : TetherManager(parent), DefaultLifecycleObserver {
|
||||||
@@ -173,7 +173,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
|||||||
|
|
||||||
override fun start() = BluetoothTethering.start(this)
|
override fun start() = BluetoothTethering.start(this)
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
TetheringManager.stop(TetheringManager.TETHERING_BLUETOOTH)
|
TetheringManager.stopTethering(TetheringManager.TETHERING_BLUETOOTH)
|
||||||
Thread.sleep(1) // give others a room to breathe
|
Thread.sleep(1) // give others a room to breathe
|
||||||
onTetheringStarted() // force flush state
|
onTetheringStarted() // force flush state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,15 +118,15 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
override val tetherType get() = TetherType.WIFI
|
override val tetherType get() = TetherType.WIFI
|
||||||
override val icon get() = R.drawable.ic_device_wifi_tethering
|
override val icon get() = R.drawable.ic_device_wifi_tethering
|
||||||
|
|
||||||
override fun start() = TetheringManager.start(TetheringManager.TETHERING_WIFI, true, this)
|
override fun start() = TetheringManager.startTethering(TetheringManager.TETHERING_WIFI, true, this)
|
||||||
override fun stop() = TetheringManager.stop(TetheringManager.TETHERING_WIFI)
|
override fun stop() = TetheringManager.stopTethering(TetheringManager.TETHERING_WIFI)
|
||||||
}
|
}
|
||||||
class Usb : TetheringTileService() {
|
class Usb : TetheringTileService() {
|
||||||
override val labelString get() = R.string.tethering_manage_usb
|
override val labelString get() = R.string.tethering_manage_usb
|
||||||
override val tetherType get() = TetherType.USB
|
override val tetherType get() = TetherType.USB
|
||||||
|
|
||||||
override fun start() = TetheringManager.start(TetheringManager.TETHERING_USB, true, this)
|
override fun start() = TetheringManager.startTethering(TetheringManager.TETHERING_USB, true, this)
|
||||||
override fun stop() = TetheringManager.stop(TetheringManager.TETHERING_USB)
|
override fun stop() = TetheringManager.stopTethering(TetheringManager.TETHERING_USB)
|
||||||
}
|
}
|
||||||
class Bluetooth : TetheringTileService() {
|
class Bluetooth : TetheringTileService() {
|
||||||
private var tethering: BluetoothTethering? = null
|
private var tethering: BluetoothTethering? = null
|
||||||
@@ -136,7 +136,7 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
|
|
||||||
override fun start() = BluetoothTethering.start(this)
|
override fun start() = BluetoothTethering.start(this)
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
TetheringManager.stop(TetheringManager.TETHERING_BLUETOOTH)
|
TetheringManager.stopTethering(TetheringManager.TETHERING_BLUETOOTH)
|
||||||
Thread.sleep(1) // give others a room to breathe
|
Thread.sleep(1) // give others a room to breathe
|
||||||
onTetheringStarted() // force flush state
|
onTetheringStarted() // force flush state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.lang.ref.WeakReference
|
|||||||
*/
|
*/
|
||||||
object TetheringManager {
|
object TetheringManager {
|
||||||
/**
|
/**
|
||||||
* Callback for use with [.startTethering] to find out whether tethering succeeded.
|
* Callback for use with [startTethering] to find out whether tethering succeeded.
|
||||||
*/
|
*/
|
||||||
interface OnStartTetheringCallback {
|
interface OnStartTetheringCallback {
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +134,8 @@ object TetheringManager {
|
|||||||
* @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
|
* @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
|
||||||
*/
|
*/
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
fun start(type: Int, showProvisioningUi: Boolean, callback: OnStartTetheringCallback, handler: Handler? = null) {
|
fun startTethering(type: Int, showProvisioningUi: Boolean, callback: OnStartTetheringCallback,
|
||||||
|
handler: Handler? = null) {
|
||||||
val reference = WeakReference(callback)
|
val reference = WeakReference(callback)
|
||||||
val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback)
|
val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback)
|
||||||
.dexCache(app.deviceStorage.cacheDir)
|
.dexCache(app.deviceStorage.cacheDir)
|
||||||
@@ -170,7 +171,7 @@ object TetheringManager {
|
|||||||
* {@link ConnectivityManager.TETHERING_BLUETOOTH}.
|
* {@link ConnectivityManager.TETHERING_BLUETOOTH}.
|
||||||
*/
|
*/
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
fun stop(type: Int) {
|
fun stopTethering(type: Int) {
|
||||||
stopTethering.invoke(app.connectivity, type)
|
stopTethering.invoke(app.connectivity, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user