mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Fix notification issue
This commit is contained in:
		
							parent
							
								
									6d77ad0faf
								
							
						
					
					
						commit
						6803568af8
					
				
					 1 changed files with 65 additions and 80 deletions
				
			
		|  | @ -172,18 +172,13 @@ public class NotificationsHelper { | |||
|         if (notifications.size() == 0) | ||||
|             return; | ||||
|         //No previous notifications in cache, so no notification will be sent | ||||
|         int newFollows = 0; | ||||
|         int newAdds = 0; | ||||
|         int newMentions = 0; | ||||
|         int newShare = 0; | ||||
|         int newPolls = 0; | ||||
|         int newStatus = 0; | ||||
| 
 | ||||
|         for (Notification notification : notifications) { | ||||
|             String notificationUrl; | ||||
|             String title = null; | ||||
|             String message = null; | ||||
|             String targeted_account = null; | ||||
|             Helper.NotifType notifType = Helper.NotifType.MENTION; | ||||
|         for (Notification notification : notifications) { | ||||
|             switch (notification.type) { | ||||
|                 case "mention": | ||||
|                     notifType = Helper.NotifType.MENTION; | ||||
|  | @ -206,7 +201,6 @@ public class NotificationsHelper { | |||
|                                     message = "\n" + new SpannableString(Html.fromHtml(notification.status.content)); | ||||
|                             } | ||||
|                         } | ||||
|                         newFollows++; | ||||
|                     } | ||||
|                     break; | ||||
|                 case "status": | ||||
|  | @ -230,7 +224,6 @@ public class NotificationsHelper { | |||
|                                     message = "\n" + new SpannableString(Html.fromHtml(notification.status.content)); | ||||
|                             } | ||||
|                         } | ||||
|                         newStatus++; | ||||
|                     } | ||||
|                     break; | ||||
|                 case "reblog": | ||||
|  | @ -241,7 +234,6 @@ public class NotificationsHelper { | |||
|                             message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reblog)); | ||||
|                         else | ||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reblog)); | ||||
|                         newShare++; | ||||
|                     } | ||||
|                     break; | ||||
|                 case "favourite": | ||||
|  | @ -252,7 +244,6 @@ public class NotificationsHelper { | |||
|                             message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_favourite)); | ||||
|                         else | ||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_favourite)); | ||||
|                         newAdds++; | ||||
|                     } | ||||
|                     break; | ||||
|                 case "follow_request": | ||||
|  | @ -264,7 +255,6 @@ public class NotificationsHelper { | |||
|                         else | ||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow_request)); | ||||
|                         targeted_account = notification.account.id; | ||||
|                         newFollows++; | ||||
|                     } | ||||
|                     break; | ||||
|                 case "follow": | ||||
|  | @ -276,7 +266,6 @@ public class NotificationsHelper { | |||
|                         else | ||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow)); | ||||
|                         targeted_account = notification.account.id; | ||||
|                         newFollows++; | ||||
|                     } | ||||
|                     break; | ||||
|                 case "poll": | ||||
|  | @ -287,16 +276,11 @@ public class NotificationsHelper { | |||
|                             message = context.getString(R.string.notif_poll_self); | ||||
|                         else | ||||
|                             message = context.getString(R.string.notif_poll); | ||||
|                         newPolls++; | ||||
|                     } | ||||
|                     break; | ||||
|                 default: | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls + newStatus; | ||||
|         if (allNotifCount > 0) { | ||||
|             if (message != null) { | ||||
|                 //Some others notification | ||||
|                 final Intent intent = new Intent(context, MainActivity.class); | ||||
|                 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); | ||||
|  | @ -305,12 +289,11 @@ public class NotificationsHelper { | |||
|                 if (targeted_account != null && notifType == Helper.NotifType.FOLLLOW) | ||||
|                     intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); | ||||
|                 intent.putExtra(Helper.PREF_INSTANCE, account.instance); | ||||
|             notificationUrl = notifications.get(0).account.avatar; | ||||
|                 notificationUrl = notification.account.avatar; | ||||
|                 Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||
|                 final String finalNotificationUrl = notificationUrl; | ||||
|                 Helper.NotifType finalNotifType = notifType; | ||||
|                 String finalMessage = message; | ||||
|             String finalMessage1 = message; | ||||
|                 String finalTitle = title; | ||||
|                 Runnable myRunnable = () -> Glide.with(context) | ||||
|                         .asBitmap() | ||||
|  | @ -325,13 +308,13 @@ public class NotificationsHelper { | |||
|                             @Override | ||||
|                             public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { | ||||
|                                 String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null); | ||||
|                             if (lastNotif == null || notifications.get(0).id.compareTo(lastNotif) > 0) { | ||||
|                                 if (lastNotif == null || notification.id.compareTo(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(); | ||||
|                                     notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(), | ||||
|                                         R.mipmap.ic_launcher), finalNotifType, finalTitle, finalMessage1); | ||||
|                                             R.mipmap.ic_launcher), finalNotifType, finalTitle, finalMessage); | ||||
|                                 } | ||||
|                                 return false; | ||||
|                             } | ||||
|  | @ -340,7 +323,7 @@ public class NotificationsHelper { | |||
|                             @Override | ||||
|                             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 || notifications.get(0).id.compareTo(lastNotif) > 0) { | ||||
|                                 if (lastNotif == null || notification.id.compareTo(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(); | ||||
|  | @ -358,4 +341,6 @@ public class NotificationsHelper { | |||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue