Handle bluetooth error message correctly

This commit is contained in:
Mygod
2020-06-11 06:24:12 +08:00
parent 2223082841
commit b656b71577
3 changed files with 17 additions and 8 deletions

View File

@@ -137,7 +137,10 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
}
@RequiresApi(24)
class Bluetooth(parent: TetheringFragment) : TetherManager(parent), DefaultLifecycleObserver {
private val tethering = BluetoothTethering(parent.requireContext()) { onTetheringStarted() }
private val tethering = BluetoothTethering(parent.requireContext()) {
data.text = makeErrorMessage()
data.notifyChange()
}
init {
parent.viewLifecycleOwner.lifecycle.addObserver(this)
@@ -151,9 +154,15 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
override val isStarted get() = tethering.active == true
override fun onException() = ManageBar.start(parent.context ?: app)
override fun makeErrorMessage(errored: List<String>) = listOfNotNull(
private var baseError: CharSequence? = null
private fun makeErrorMessage(): CharSequence = listOfNotNull(
if (tethering.active == null) tethering.activeFailureCause?.readableMessage else null,
super.makeErrorMessage(errored).let { if (it.isEmpty()) null else it }).joinToString("\n")
baseError).joinToString("\n")
override fun makeErrorMessage(errored: List<String>): CharSequence {
baseError = super.makeErrorMessage(errored).let { if (it.isEmpty()) null else it }
return makeErrorMessage()
}
override fun start() = BluetoothTethering.start(this)
override fun stop() {