Fix RACE to deleteDevice

This commit is contained in:
sim 2023-02-25 18:47:24 +01:00
parent 14601abc88
commit df3bb9a3c6
3 changed files with 8 additions and 6 deletions

View File

@ -178,9 +178,10 @@ class MainActivity : AppCompatActivity() {
.edit()
.remove("PREF_CURRENT_ACCOUNT_STRING")
.apply()
deleteDevice(this)
deleteDevice(this) {
StartService.stopService()
FailureHandler.clearFails()
}
showStart()
finish()
startActivity(intent)

View File

@ -106,7 +106,7 @@ object Api {
Log.d(TAG, "cSync done.")
}
fun Context.apiDeleteDevice() {
fun Context.apiDeleteDevice(block: () -> Unit = {}) {
val deviceId = getDeviceId(this) ?: return
withApiProvider { apiProvider ->
@ -132,6 +132,7 @@ object Api {
override fun onComplete() {
removeUrl(this@apiDeleteDevice)
block()
}
})
removeDeviceId(this)

View File

@ -108,13 +108,13 @@ object Distributor {
return TOKEN_NOK
}
fun deleteDevice(context: Context) {
fun deleteDevice(context: Context, block: () -> Unit = {}) {
val db = getDb(context)
db.listTokens().forEach {
sendUnregistered(context, it)
db.unregisterApp(it)
}
context.apiDeleteDevice()
context.apiDeleteDevice(block)
}
fun createApp(context: Context, appName: String, connectorToken: String, block: () -> Unit) {