Commit eb0ecd75 authored by Thomas's avatar Thomas
Browse files

Fix issue #997 - Store endpoint and create it only if it changes

parent 0d949f8d
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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) {
            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();
            }
        }
    }

+1 −0
Original line number Diff line number Diff line
@@ -1146,6 +1146,7 @@
    <string name="SET_TRANSLATOR_HOST_LINGVA" translatable="false">lingva.ml</string>
    <string name="SET_TRANSLATOR_DOMAIN" translatable="false">SET_TRANSLATOR_DOMAIN</string>
    <string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string>
    <string name="SET_STORED_ENDPOINT" translatable="false">SET_STORED_ENDPOINT</string>
    <string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string>

    <string name="SET_TRANSLATOR_API_KEY" translatable="false">SET_TRANSLATOR_API_KEY</string>