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

improve_thread
Thomas 9 months ago
parent eb0ecd7583
commit 0982e1bb38

@ -66,14 +66,16 @@ public class CustomReceiver extends MessagingReceiver {
@Override @Override
public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) { public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) {
if (context != null) { if (context != null) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); synchronized(this) {
String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
if(storedEnpoint == null || !storedEnpoint.equalsIgnoreCase(endpoint)) { String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null);
PushNotifications if(storedEnpoint == null || !storedEnpoint.equals(endpoint)) {
.registerPushNotifications(context, endpoint, slug); PushNotifications
SharedPreferences.Editor editor = sharedpreferences.edit(); .registerPushNotifications(context, endpoint, slug);
editor.putString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, endpoint); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.apply(); editor.putString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, endpoint);
editor.commit();
}
} }
} }
} }

Loading…
Cancel
Save