From eb0ecd758390664799fa44dd178813a8119d13f3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 14 Dec 2023 08:03:47 +0100 Subject: [PATCH] Fix issue #997 - Store endpoint and create it only if it changes --- .../android/mastodon/services/CustomReceiver.java | 14 ++++++++++++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java b/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java index e89837d1..cfe03a9c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java +++ b/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java @@ -16,13 +16,16 @@ package app.fedilab.android.mastodon.services; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import androidx.annotation.NonNull; +import androidx.preference.PreferenceManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.unifiedpush.android.connector.MessagingReceiver; +import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.NotificationsHelper; import app.fedilab.android.mastodon.helper.PushNotifications; @@ -63,8 +66,15 @@ public class CustomReceiver extends MessagingReceiver { @Override public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) { if (context != null) { - PushNotifications - .registerPushNotifications(context, endpoint, slug); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null); + if(storedEnpoint == null || !storedEnpoint.equalsIgnoreCase(endpoint)) { + PushNotifications + .registerPushNotifications(context, endpoint, slug); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, endpoint); + editor.apply(); + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 473d3eeb..41ccd0b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1146,6 +1146,7 @@ lingva.ml SET_TRANSLATOR_DOMAIN SET_TRANSLATOR + SET_STORED_ENDPOINT SET_TRANSLATOR_VERSION SET_TRANSLATOR_API_KEY