From 226672378959e970db25a09f418fa6653a8dd5c8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 16 Sep 2022 17:03:46 +0200 Subject: [PATCH] Remove `DefaultSharedPreferences` since we now have @DefaultPreferences which provide a singleton. --- .../app/receivers/VectorDebugReceiver.kt | 19 +++++++++++-------- .../im/vector/app/push/fcm/GoogleFcmHelper.kt | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/vector-app/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt b/vector-app/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt index 550dc055d9..4edbdd0591 100644 --- a/vector-app/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt +++ b/vector-app/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt @@ -23,7 +23,7 @@ import android.content.IntentFilter import android.content.SharedPreferences import androidx.core.content.edit import im.vector.app.core.debug.DebugReceiver -import im.vector.app.core.di.DefaultSharedPreferences +import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.utils.lsFiles import timber.log.Timber import javax.inject.Inject @@ -31,7 +31,10 @@ import javax.inject.Inject /** * Receiver to handle some command from ADB */ -class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugReceiver { +class VectorDebugReceiver @Inject constructor( + @DefaultPreferences + private val sharedPreferences: SharedPreferences, +) : BroadcastReceiver(), DebugReceiver { override fun register(context: Context) { context.registerReceiver(this, getIntentFilter(context)) @@ -47,14 +50,14 @@ class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugRece intent.action?.let { when { it.endsWith(DEBUG_ACTION_DUMP_FILESYSTEM) -> lsFiles(context) - it.endsWith(DEBUG_ACTION_DUMP_PREFERENCES) -> dumpPreferences(context) - it.endsWith(DEBUG_ACTION_ALTER_SCALAR_TOKEN) -> alterScalarToken(context) + it.endsWith(DEBUG_ACTION_DUMP_PREFERENCES) -> dumpPreferences() + it.endsWith(DEBUG_ACTION_ALTER_SCALAR_TOKEN) -> alterScalarToken() } } } - private fun dumpPreferences(context: Context) { - logPrefs("DefaultSharedPreferences", DefaultSharedPreferences.getInstance(context)) + private fun dumpPreferences() { + logPrefs("DefaultSharedPreferences", sharedPreferences) } private fun logPrefs(name: String, sharedPreferences: SharedPreferences?) { @@ -67,8 +70,8 @@ class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugRece } } - private fun alterScalarToken(context: Context) { - DefaultSharedPreferences.getInstance(context).edit { + private fun alterScalarToken() { + sharedPreferences.edit { // putString("SCALAR_TOKEN_PREFERENCE_KEY" + Matrix.getInstance(context).defaultSession.myUserId, "bad_token") } } diff --git a/vector-app/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt b/vector-app/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt index d64847c124..7cf90cf874 100755 --- a/vector-app/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt +++ b/vector-app/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt @@ -17,6 +17,7 @@ package im.vector.app.push.fcm import android.app.Activity import android.content.Context +import android.content.SharedPreferences import android.widget.Toast import androidx.core.content.edit import com.google.android.gms.common.ConnectionResult @@ -24,7 +25,7 @@ import com.google.android.gms.common.GoogleApiAvailability import com.google.firebase.messaging.FirebaseMessaging import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder -import im.vector.app.core.di.DefaultSharedPreferences +import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.pushers.PushersManager import timber.log.Timber @@ -35,14 +36,13 @@ import javax.inject.Inject * It has an alter ego in the fdroid variant. */ class GoogleFcmHelper @Inject constructor( - context: Context, + @DefaultPreferences + private val sharedPrefs: SharedPreferences, ) : FcmHelper { companion object { private const val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN" } - private val sharedPrefs = DefaultSharedPreferences.getInstance(context) - override fun isFirebaseAvailable(): Boolean = true override fun getFcmToken(): String? {