Remove DefaultSharedPreferences since we now have @DefaultPreferences which provide a singleton.

This commit is contained in:
Benoit Marty 2022-09-16 17:03:46 +02:00 committed by Benoit Marty
parent c735ea5e3d
commit 2266723789
2 changed files with 15 additions and 12 deletions

View File

@ -23,7 +23,7 @@ import android.content.IntentFilter
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
import im.vector.app.core.debug.DebugReceiver 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 im.vector.app.core.utils.lsFiles
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -31,7 +31,10 @@ import javax.inject.Inject
/** /**
* Receiver to handle some command from ADB * 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) { override fun register(context: Context) {
context.registerReceiver(this, getIntentFilter(context)) context.registerReceiver(this, getIntentFilter(context))
@ -47,14 +50,14 @@ class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugRece
intent.action?.let { intent.action?.let {
when { when {
it.endsWith(DEBUG_ACTION_DUMP_FILESYSTEM) -> lsFiles(context) it.endsWith(DEBUG_ACTION_DUMP_FILESYSTEM) -> lsFiles(context)
it.endsWith(DEBUG_ACTION_DUMP_PREFERENCES) -> dumpPreferences(context) it.endsWith(DEBUG_ACTION_DUMP_PREFERENCES) -> dumpPreferences()
it.endsWith(DEBUG_ACTION_ALTER_SCALAR_TOKEN) -> alterScalarToken(context) it.endsWith(DEBUG_ACTION_ALTER_SCALAR_TOKEN) -> alterScalarToken()
} }
} }
} }
private fun dumpPreferences(context: Context) { private fun dumpPreferences() {
logPrefs("DefaultSharedPreferences", DefaultSharedPreferences.getInstance(context)) logPrefs("DefaultSharedPreferences", sharedPreferences)
} }
private fun logPrefs(name: String, sharedPreferences: SharedPreferences?) { private fun logPrefs(name: String, sharedPreferences: SharedPreferences?) {
@ -67,8 +70,8 @@ class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugRece
} }
} }
private fun alterScalarToken(context: Context) { private fun alterScalarToken() {
DefaultSharedPreferences.getInstance(context).edit { sharedPreferences.edit {
// putString("SCALAR_TOKEN_PREFERENCE_KEY" + Matrix.getInstance(context).defaultSession.myUserId, "bad_token") // putString("SCALAR_TOKEN_PREFERENCE_KEY" + Matrix.getInstance(context).defaultSession.myUserId, "bad_token")
} }
} }

View File

@ -17,6 +17,7 @@ package im.vector.app.push.fcm
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import android.widget.Toast import android.widget.Toast
import androidx.core.content.edit import androidx.core.content.edit
import com.google.android.gms.common.ConnectionResult 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 com.google.firebase.messaging.FirebaseMessaging
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder 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.FcmHelper
import im.vector.app.core.pushers.PushersManager import im.vector.app.core.pushers.PushersManager
import timber.log.Timber import timber.log.Timber
@ -35,14 +36,13 @@ import javax.inject.Inject
* It has an alter ego in the fdroid variant. * It has an alter ego in the fdroid variant.
*/ */
class GoogleFcmHelper @Inject constructor( class GoogleFcmHelper @Inject constructor(
context: Context, @DefaultPreferences
private val sharedPrefs: SharedPreferences,
) : FcmHelper { ) : FcmHelper {
companion object { companion object {
private const val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN" private const val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN"
} }
private val sharedPrefs = DefaultSharedPreferences.getInstance(context)
override fun isFirebaseAvailable(): Boolean = true override fun isFirebaseAvailable(): Boolean = true
override fun getFcmToken(): String? { override fun getFcmToken(): String? {