Always use register to open the distributor dialog
The forced unregistration always happens in register function
This commit is contained in:
parent
02d54878c3
commit
a4dd08ddb3
@ -46,6 +46,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||||||
private val vectorFeatures: VectorFeatures,
|
private val vectorFeatures: VectorFeatures,
|
||||||
private val fcmHelper: FcmHelper,
|
private val fcmHelper: FcmHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun register(
|
fun register(
|
||||||
activity: FragmentActivity,
|
activity: FragmentActivity,
|
||||||
onDoneRunnable: Runnable? = null,
|
onDoneRunnable: Runnable? = null,
|
||||||
@ -56,7 +57,14 @@ class UnifiedPushHelper @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reRegister(
|
// If registration is forced:
|
||||||
|
// * the current distributor (if any) is removed
|
||||||
|
// * The dialog is opened
|
||||||
|
//
|
||||||
|
// The registration is forced in 2 cases :
|
||||||
|
// * in the settings
|
||||||
|
// * in the troubleshoot list (doFix)
|
||||||
|
fun forceRegister(
|
||||||
activity: FragmentActivity,
|
activity: FragmentActivity,
|
||||||
pushersManager: PushersManager,
|
pushersManager: PushersManager,
|
||||||
onDoneRunnable: Runnable? = null
|
onDoneRunnable: Runnable? = null
|
||||||
@ -86,7 +94,8 @@ class UnifiedPushHelper @Inject constructor(
|
|||||||
// Un-register first
|
// Un-register first
|
||||||
unregister(pushersManager)
|
unregister(pushersManager)
|
||||||
}
|
}
|
||||||
if (UnifiedPush.getDistributor(context).isNotEmpty()) {
|
// the !force should not be needed
|
||||||
|
if (!force && UnifiedPush.getDistributor(context).isNotEmpty()) {
|
||||||
UnifiedPush.registerApp(context)
|
UnifiedPush.registerApp(context)
|
||||||
onDoneRunnable?.run()
|
onDoneRunnable?.run()
|
||||||
return@launch
|
return@launch
|
||||||
@ -94,42 +103,24 @@ class UnifiedPushHelper @Inject constructor(
|
|||||||
|
|
||||||
val distributors = UnifiedPush.getDistributors(context)
|
val distributors = UnifiedPush.getDistributors(context)
|
||||||
|
|
||||||
if (distributors.size == 1 && !force) {
|
if (!force && distributors.size == 1) {
|
||||||
UnifiedPush.saveDistributor(context, distributors.first())
|
UnifiedPush.saveDistributor(context, distributors.first())
|
||||||
UnifiedPush.registerApp(context)
|
UnifiedPush.registerApp(context)
|
||||||
onDoneRunnable?.run()
|
onDoneRunnable?.run()
|
||||||
} else {
|
} else {
|
||||||
openDistributorDialogInternal(
|
openDistributorDialogInternal(
|
||||||
activity = activity,
|
activity = activity,
|
||||||
pushersManager = pushersManager,
|
|
||||||
onDoneRunnable = onDoneRunnable,
|
onDoneRunnable = onDoneRunnable,
|
||||||
distributors = distributors,
|
distributors = distributors
|
||||||
unregisterFirst = force
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openDistributorDialog(
|
|
||||||
activity: FragmentActivity,
|
|
||||||
pushersManager: PushersManager,
|
|
||||||
onDoneRunnable: Runnable,
|
|
||||||
) {
|
|
||||||
val distributors = UnifiedPush.getDistributors(activity)
|
|
||||||
openDistributorDialogInternal(
|
|
||||||
activity,
|
|
||||||
pushersManager,
|
|
||||||
onDoneRunnable, distributors,
|
|
||||||
unregisterFirst = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openDistributorDialogInternal(
|
private fun openDistributorDialogInternal(
|
||||||
activity: FragmentActivity,
|
activity: FragmentActivity,
|
||||||
pushersManager: PushersManager?,
|
|
||||||
onDoneRunnable: Runnable?,
|
onDoneRunnable: Runnable?,
|
||||||
distributors: List<String>,
|
distributors: List<String>
|
||||||
unregisterFirst: Boolean,
|
|
||||||
) {
|
) {
|
||||||
val internalDistributorName = stringProvider.getString(
|
val internalDistributorName = stringProvider.getString(
|
||||||
if (fcmHelper.isFirebaseAvailable()) {
|
if (fcmHelper.isFirebaseAvailable()) {
|
||||||
@ -157,10 +148,6 @@ class UnifiedPushHelper @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
activity.lifecycleScope.launch {
|
activity.lifecycleScope.launch {
|
||||||
if (unregisterFirst) {
|
|
||||||
// Un-register first
|
|
||||||
unregister(pushersManager)
|
|
||||||
}
|
|
||||||
UnifiedPush.saveDistributor(context, distributor)
|
UnifiedPush.saveDistributor(context, distributor)
|
||||||
Timber.i("Saving distributor: $distributor")
|
Timber.i("Saving distributor: $distributor")
|
||||||
UnifiedPush.registerApp(context)
|
UnifiedPush.registerApp(context)
|
||||||
|
@ -158,7 +158,7 @@ class VectorSettingsNotificationPreferenceFragment :
|
|||||||
if (vectorFeatures.allowExternalUnifiedPushDistributors()) {
|
if (vectorFeatures.allowExternalUnifiedPushDistributors()) {
|
||||||
it.summary = unifiedPushHelper.getCurrentDistributorName()
|
it.summary = unifiedPushHelper.getCurrentDistributorName()
|
||||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
unifiedPushHelper.openDistributorDialog(requireActivity(), pushersManager) {
|
unifiedPushHelper.forceRegister(requireActivity(), pushersManager) {
|
||||||
it.summary = unifiedPushHelper.getCurrentDistributorName()
|
it.summary = unifiedPushHelper.getCurrentDistributorName()
|
||||||
session.pushersService().refreshPushers()
|
session.pushersService().refreshPushers()
|
||||||
refreshBackgroundSyncPrefs()
|
refreshBackgroundSyncPrefs()
|
||||||
|
@ -60,7 +60,7 @@ class TestEndpointAsTokenRegistration @Inject constructor(
|
|||||||
)
|
)
|
||||||
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_endpoint_registration_quick_fix) {
|
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_endpoint_registration_quick_fix) {
|
||||||
override fun doFix() {
|
override fun doFix() {
|
||||||
unifiedPushHelper.reRegister(
|
unifiedPushHelper.forceRegister(
|
||||||
context,
|
context,
|
||||||
pushersManager
|
pushersManager
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user