summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2023-05-27 14:47:35 +0200
committerThomas <tschneider.ac@gmail.com>2023-05-27 14:47:35 +0200
commitcb2ede287db9ea6b3c4716b154c1c2b803cb86ac (patch)
tree9718327a9f368388927364147b2f84907d303a68
parent88da62b8e8e5c605c1545340dd8897d5e99d018d (diff)
comment #874 - Avoid multiple notification fetchfix
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java44
1 files changed, 18 insertions, 26 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java
index 5c474dcf8..4dae3b5e7 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java
@@ -34,11 +34,7 @@ import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
-import com.bumptech.glide.load.DataSource;
-import com.bumptech.glide.load.engine.GlideException;
-import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.CustomTarget;
-import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import java.util.ArrayList;
@@ -67,7 +63,7 @@ public class NotificationsHelper {
public static HashMap<String, String> since_ids = new HashMap<>();
- public static void task(Context context, String slug) throws DBException {
+ public static synchronized void task(Context context, String slug) throws DBException {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
@@ -77,10 +73,13 @@ public class NotificationsHelper {
return;
}
String last_notifid;
+ last_notifid = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + slug, null);
if (since_ids.containsKey(slug)) {
- last_notifid = since_ids.get(slug);
+ String last_notifid_reccorded = since_ids.get(slug);
+ if (last_notifid_reccorded != null && last_notifid_reccorded.compareToIgnoreCase(last_notifid) == 0) {
+ return;
+ }
} else {
- last_notifid = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + slug, null);
since_ids.put(slug, last_notifid);
}
@@ -383,37 +382,30 @@ public class NotificationsHelper {
Runnable myRunnable = () -> Glide.with(context)
.asBitmap()
.load(finalNotificationUrl != null ? finalNotificationUrl : R.drawable.fedilab_logo_bubbles)
- .listener(new RequestListener<Bitmap>() {
-
- @Override
- public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
- return false;
- }
-
+ .into(new CustomTarget<Bitmap>() {
@Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
+ public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null);
if (lastNotif == null || Helper.compareTo(notification.id, lastNotif) > 0) {
SharedPreferences.Editor editor = prefs.edit();
- since_ids.put(account.user_id + "@" + account.instance, lastNotif);
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
- editor.apply();
- Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
- getMainLogo(context)), finalNotifType, finalTitle, finalMessage);
+ editor.commit();
+ since_ids.put(account.user_id + "@" + account.instance, lastNotif);
+ Helper.notify_user(context, account, intent, resource, finalNotifType, finalTitle, finalMessage);
}
- return false;
}
- })
- .into(new CustomTarget<Bitmap>() {
+
@Override
- public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
+ public void onLoadFailed(@Nullable Drawable errorDrawable) {
+ super.onLoadFailed(errorDrawable);
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null);
if (lastNotif == null || Helper.compareTo(notification.id, lastNotif) > 0) {
SharedPreferences.Editor editor = prefs.edit();
- editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
- editor.apply();
since_ids.put(account.user_id + "@" + account.instance, lastNotif);
- Helper.notify_user(context, account, intent, resource, finalNotifType, finalTitle, finalMessage);
+ editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
+ editor.commit();
+ Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
+ getMainLogo(context)), finalNotifType, finalTitle, finalMessage);
}
}