From bf8d7384db7d8d91427d9c3a8e0cd9f0a6a12bd6 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Sun, 7 May 2017 16:14:28 -0400 Subject: [PATCH] Moves out-of-place Firebase InstanceId call to the google build flavor. Closes #274 --- .../java/com/keylesspalace/tusky/MessagingService.java | 5 +++++ .../java/com/keylesspalace/tusky/MessagingService.java | 5 +++++ app/src/main/java/com/keylesspalace/tusky/BaseActivity.java | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/fdroid/java/com/keylesspalace/tusky/MessagingService.java b/app/src/fdroid/java/com/keylesspalace/tusky/MessagingService.java index ca446945..eaa1b1b5 100644 --- a/app/src/fdroid/java/com/keylesspalace/tusky/MessagingService.java +++ b/app/src/fdroid/java/com/keylesspalace/tusky/MessagingService.java @@ -134,4 +134,9 @@ public class MessagingService extends IntentService { .putStringSet("current_ids", currentIds) .apply(); } + + public static String getInstanceToken() { + // This is only used for the "google" build flavor, so this version is just a stub method. + return null; + } } diff --git a/app/src/google/java/com/keylesspalace/tusky/MessagingService.java b/app/src/google/java/com/keylesspalace/tusky/MessagingService.java index c32fff09..4a2a55da 100644 --- a/app/src/google/java/com/keylesspalace/tusky/MessagingService.java +++ b/app/src/google/java/com/keylesspalace/tusky/MessagingService.java @@ -25,6 +25,7 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.text.Spanned; +import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; import com.google.gson.Gson; @@ -125,4 +126,8 @@ public class MessagingService extends FirebaseMessagingService { mastodonAPI = retrofit.create(MastodonAPI.class); } + + public static String getInstanceToken() { + return FirebaseInstanceId.getInstance().getToken(); + } } diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 1803cacd..859b4649 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -204,7 +204,7 @@ public class BaseActivity extends AppCompatActivity { protected void enablePushNotifications() { if (BuildConfig.USES_PUSH_NOTIFICATIONS) { - String token = com.google.firebase.iid.FirebaseInstanceId.getInstance().getToken(); + String token = MessagingService.getInstanceToken(); tuskyAPI.register(getBaseUrl(), getAccessToken(), token).enqueue(new Callback() { @Override public void onResponse(Call call, retrofit2.Response response) {