Avoid unifiedpush selection spam
Change-Id: Id6836b3683414ca7d8dcc3f52c0c4fc3fa202db0
This commit is contained in:
parent
bbbefae75c
commit
509eabfe5c
|
@ -35,6 +35,7 @@ import org.matrix.android.sdk.api.util.MatrixJsonParser
|
|||
import org.unifiedpush.android.connector.UnifiedPush
|
||||
import timber.log.Timber
|
||||
import java.net.URL
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
|
||||
class UnifiedPushHelper @Inject constructor(
|
||||
|
@ -47,12 +48,20 @@ class UnifiedPushHelper @Inject constructor(
|
|||
private val fcmHelper: FcmHelper,
|
||||
) {
|
||||
|
||||
private val isRegistering = AtomicBoolean(false)
|
||||
|
||||
// Called when the home activity starts
|
||||
// or when notifications are enabled
|
||||
fun register(
|
||||
activity: FragmentActivity,
|
||||
onDoneRunnable: Runnable? = null,
|
||||
) {
|
||||
if (!isRegistering.compareAndSet(false, true)) {
|
||||
// There's already a register() in progress, possibly because user hasn't reacted to the dialog yet
|
||||
Timber.i("Skipping register() call with runnable $onDoneRunnable, still in register call")
|
||||
onDoneRunnable?.run()
|
||||
return
|
||||
}
|
||||
registerInternal(
|
||||
activity,
|
||||
onDoneRunnable = onDoneRunnable
|
||||
|
@ -90,6 +99,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
UnifiedPush.saveDistributor(context, context.packageName)
|
||||
UnifiedPush.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
return@launch
|
||||
}
|
||||
if (force) {
|
||||
|
@ -100,6 +110,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
if (!force && UnifiedPush.getDistributor(context).isNotEmpty()) {
|
||||
UnifiedPush.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
return@launch
|
||||
}
|
||||
|
||||
|
@ -109,6 +120,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
UnifiedPush.saveDistributor(context, distributors.first())
|
||||
UnifiedPush.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
} else {
|
||||
openDistributorDialogInternal(
|
||||
activity = activity,
|
||||
|
@ -152,6 +164,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
Timber.i("Saving distributor: $distributor")
|
||||
UnifiedPush.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
}
|
||||
}
|
||||
.setOnCancelListener {
|
||||
|
@ -159,6 +172,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
UnifiedPush.saveDistributor(context, context.packageName)
|
||||
UnifiedPush.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
}
|
||||
.setCancelable(true)
|
||||
.show()
|
||||
|
@ -200,6 +214,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
if (UnifiedPush.getDistributor(context) == context.packageName) {
|
||||
unifiedPushStore.storePushGateway(stringProvider.getString(R.string.pusher_http_url))
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
return
|
||||
}
|
||||
// else, unifiedpush, and pushkey is an endpoint
|
||||
|
@ -216,6 +231,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||
Timber.d("Using custom gateway")
|
||||
unifiedPushStore.storePushGateway(custom)
|
||||
onDoneRunnable?.run()
|
||||
isRegistering.set(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue