mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
VectorPreferences can be injected.
This commit is contained in:
parent
ad8cb22863
commit
ff6aa1147c
3 changed files with 7 additions and 19 deletions
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 ->
|
||||
|
|
Loading…
Reference in a new issue