From ff6aa1147c66d0a08ac834ec1e0ea3ff73d135eb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 1 Jun 2022 16:33:49 +0200 Subject: [PATCH] VectorPreferences can be injected. --- .../im/vector/app/core/pushers/UnifiedPushHelper.kt | 13 ++++--------- .../VectorSettingsNotificationPreferenceFragment.kt | 8 ++------ .../troubleshoot/TestEndpointAsTokenRegistration.kt | 5 +---- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt index d4af90ca0a..7218f96679 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt @@ -41,6 +41,7 @@ import javax.inject.Inject class UnifiedPushHelper @Inject constructor( private val context: Context, private val stringProvider: StringProvider, + private val vectorPreferences: VectorPreferences, private val matrix: Matrix, ) { companion object { @@ -105,14 +106,12 @@ class UnifiedPushHelper @Inject constructor( fun reRegister( activity: FragmentActivity, pushersManager: PushersManager, - vectorPreferences: VectorPreferences, onDoneRunnable: Runnable? = null ) { gRegister( activity, force = true, pushersManager = pushersManager, - vectorPreferences = vectorPreferences, onDoneRunnable = onDoneRunnable ) } @@ -121,7 +120,6 @@ class UnifiedPushHelper @Inject constructor( activity: FragmentActivity, force: Boolean = false, pushersManager: PushersManager? = null, - vectorPreferences: VectorPreferences? = null, onDoneRunnable: Runnable? = null ) { if (!BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { @@ -132,7 +130,7 @@ class UnifiedPushHelper @Inject constructor( } if (force) { // Un-register first - unregister(pushersManager, vectorPreferences) + unregister(pushersManager) } if (up.getDistributor(context).isNotEmpty()) { up.registerApp(context) @@ -186,12 +184,9 @@ class UnifiedPushHelper @Inject constructor( } } - fun unregister( - pushersManager: PushersManager? = null, - vectorPreferences: VectorPreferences? = null - ) { + fun unregister(pushersManager: PushersManager? = null) { val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME - vectorPreferences?.setFdroidSyncBackgroundMode(mode) + vectorPreferences.setFdroidSyncBackgroundMode(mode) runBlocking { try { pushersManager?.unregisterPusher(getEndpointOrToken().orEmpty()) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt index 0dcb0f37bc..3ded282838 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt @@ -102,10 +102,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( if (isChecked) { unifiedPushHelper.register(requireActivity()) } else { - unifiedPushHelper.unregister( - pushersManager, - vectorPreferences - ) + unifiedPushHelper.unregister(pushersManager) session.pushersService().refreshPushers() } } @@ -154,8 +151,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( it.onPreferenceClickListener = Preference.OnPreferenceClickListener { unifiedPushHelper.reRegister( requireActivity(), - pushersManager, - vectorPreferences + pushersManager ) { session.pushersService().refreshPushers() refreshBackgroundSyncPrefs() diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestEndpointAsTokenRegistration.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestEndpointAsTokenRegistration.kt index c7c997ee82..5cacb8d6d6 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestEndpointAsTokenRegistration.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestEndpointAsTokenRegistration.kt @@ -27,7 +27,6 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.pushers.PushersManager import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.core.resources.StringProvider -import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.api.session.pushers.PusherState import javax.inject.Inject @@ -35,7 +34,6 @@ class TestEndpointAsTokenRegistration @Inject constructor( private val context: FragmentActivity, private val stringProvider: StringProvider, private val pushersManager: PushersManager, - private val vectorPreferences: VectorPreferences, private val activeSessionHolder: ActiveSessionHolder, private val unifiedPushHelper: UnifiedPushHelper, ) : TroubleshootTest(R.string.settings_troubleshoot_test_endpoint_registration_title) { @@ -62,8 +60,7 @@ class TestEndpointAsTokenRegistration @Inject constructor( override fun doFix() { unifiedPushHelper.reRegister( context, - pushersManager, - vectorPreferences + pushersManager ) val workId = pushersManager.enqueueRegisterPusherWithFcmKey(endpoint) WorkManager.getInstance(context).getWorkInfoByIdLiveData(workId).observe(context, Observer { workInfo ->