We need an Activity to display the dialog

This commit is contained in:
Benoit Marty 2022-06-01 16:24:13 +02:00 committed by Benoit Marty
parent ddf6a69a69
commit ad8cb22863
4 changed files with 14 additions and 4 deletions

View file

@ -19,6 +19,7 @@ package im.vector.app.core.pushers
import android.content.Context
import android.content.pm.PackageManager
import androidx.core.content.edit
import androidx.fragment.app.FragmentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.squareup.moshi.JsonClass
import im.vector.app.BuildConfig
@ -91,18 +92,24 @@ class UnifiedPushHelper @Inject constructor(
}
}
fun register(onDoneRunnable: Runnable? = null) {
fun register(
activity: FragmentActivity,
onDoneRunnable: Runnable? = null,
) {
gRegister(
activity,
onDoneRunnable = onDoneRunnable
)
}
fun reRegister(
activity: FragmentActivity,
pushersManager: PushersManager,
vectorPreferences: VectorPreferences,
onDoneRunnable: Runnable? = null
) {
gRegister(
activity,
force = true,
pushersManager = pushersManager,
vectorPreferences = vectorPreferences,
@ -111,6 +118,7 @@ class UnifiedPushHelper @Inject constructor(
}
private fun gRegister(
activity: FragmentActivity,
force: Boolean = false,
pushersManager: PushersManager? = null,
vectorPreferences: VectorPreferences? = null,
@ -163,7 +171,7 @@ class UnifiedPushHelper @Inject constructor(
}
}.toTypedArray()
MaterialAlertDialogBuilder(context)
MaterialAlertDialogBuilder(activity)
.setTitle(stringProvider.getString(R.string.unifiedpush_getdistributors_dialog_title))
.setItems(distributorsNameArray) { _, which ->
val distributor = distributorsArray[which]

View file

@ -189,7 +189,7 @@ class HomeActivity :
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.Home
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
unifiedPushHelper.register {
unifiedPushHelper.register(this) {
if (unifiedPushHelper.isEmbeddedDistributor()) {
FcmHelper.ensureFcmTokenIsRetrieved(
this,

View file

@ -100,7 +100,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)?.let {
it.setTransactionalSwitchChangeListener(lifecycleScope) { isChecked ->
if (isChecked) {
unifiedPushHelper.register()
unifiedPushHelper.register(requireActivity())
} else {
unifiedPushHelper.unregister(
pushersManager,
@ -153,6 +153,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
unifiedPushHelper.reRegister(
requireActivity(),
pushersManager,
vectorPreferences
) {

View file

@ -61,6 +61,7 @@ class TestEndpointAsTokenRegistration @Inject constructor(
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_endpoint_registration_quick_fix) {
override fun doFix() {
unifiedPushHelper.reRegister(
context,
pushersManager,
vectorPreferences
)