Update deprecated code

This commit is contained in:
Benoit Marty 2020-12-02 13:49:07 +01:00
parent 9881c9f61c
commit f0afd5ceea
2 changed files with 11 additions and 9 deletions

View File

@ -18,7 +18,7 @@ package im.vector.app.gplay.features.settings.troubleshoot
import android.content.Intent import android.content.Intent
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.iid.FirebaseInstanceId import com.google.firebase.messaging.FirebaseMessaging
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.startAddGoogleAccountIntent import im.vector.app.core.utils.startAddGoogleAccountIntent
@ -36,7 +36,7 @@ class TestFirebaseToken @Inject constructor(private val context: AppCompatActivi
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) { override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
status = TestStatus.RUNNING status = TestStatus.RUNNING
try { try {
FirebaseInstanceId.getInstance().instanceId FirebaseMessaging.getInstance().token
.addOnCompleteListener(context) { task -> .addOnCompleteListener(context) { task ->
if (!task.isSuccessful) { if (!task.isSuccessful) {
val errorMsg = if (task.exception == null) "Unknown" else task.exception!!.localizedMessage val errorMsg = if (task.exception == null) "Unknown" else task.exception!!.localizedMessage
@ -57,7 +57,7 @@ class TestFirebaseToken @Inject constructor(private val context: AppCompatActivi
} }
status = TestStatus.FAILED status = TestStatus.FAILED
} else { } else {
task.result?.token?.let { token -> task.result?.let { token ->
val tok = token.substring(0, Math.min(8, token.length)) + "********************" val tok = token.substring(0, Math.min(8, token.length)) + "********************"
description = stringProvider.getString(R.string.settings_troubleshoot_test_fcm_success, tok) description = stringProvider.getString(R.string.settings_troubleshoot_test_fcm_success, tok)
Timber.e("Retrieved FCM token success [$tok].") Timber.e("Retrieved FCM token success [$tok].")

View File

@ -21,7 +21,7 @@ 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
import com.google.android.gms.common.GoogleApiAvailability import com.google.android.gms.common.GoogleApiAvailability
import com.google.firebase.iid.FirebaseInstanceId 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.DefaultSharedPreferences
@ -71,14 +71,16 @@ object FcmHelper {
// 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features' // 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features'
if (checkPlayServices(activity)) { if (checkPlayServices(activity)) {
try { try {
FirebaseInstanceId.getInstance().instanceId FirebaseMessaging.getInstance().token
.addOnSuccessListener(activity) { instanceIdResult -> .addOnSuccessListener { token ->
storeFcmToken(activity, instanceIdResult.token) storeFcmToken(activity, token)
if (registerPusher) { if (registerPusher) {
pushersManager.registerPusherWithFcmKey(instanceIdResult.token) pushersManager.registerPusherWithFcmKey(token)
} }
} }
.addOnFailureListener(activity) { e -> Timber.e(e, "## ensureFcmTokenIsRetrieved() : failed") } .addOnFailureListener { e ->
Timber.e(e, "## ensureFcmTokenIsRetrieved() : failed")
}
} catch (e: Throwable) { } catch (e: Throwable) {
Timber.e(e, "## ensureFcmTokenIsRetrieved() : failed") Timber.e(e, "## ensureFcmTokenIsRetrieved() : failed")
} }