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) |         if (notifications.size() == 0) | ||||||
|             return; |             return; | ||||||
|         //No previous notifications in cache, so no notification will be sent |         //No previous notifications in cache, so no notification will be sent | ||||||
|         int newFollows = 0; | 
 | ||||||
|         int newAdds = 0; |         for (Notification notification : notifications) { | ||||||
|         int newMentions = 0; |  | ||||||
|         int newShare = 0; |  | ||||||
|         int newPolls = 0; |  | ||||||
|         int newStatus = 0; |  | ||||||
|             String notificationUrl; |             String notificationUrl; | ||||||
|             String title = null; |             String title = null; | ||||||
|             String message = null; |             String message = null; | ||||||
|             String targeted_account = null; |             String targeted_account = null; | ||||||
|             Helper.NotifType notifType = Helper.NotifType.MENTION; |             Helper.NotifType notifType = Helper.NotifType.MENTION; | ||||||
|         for (Notification notification : notifications) { |  | ||||||
|             switch (notification.type) { |             switch (notification.type) { | ||||||
|                 case "mention": |                 case "mention": | ||||||
|                     notifType = Helper.NotifType.MENTION; |                     notifType = Helper.NotifType.MENTION; | ||||||
|  | @ -206,7 +201,6 @@ public class NotificationsHelper { | ||||||
|                                     message = "\n" + new SpannableString(Html.fromHtml(notification.status.content)); |                                     message = "\n" + new SpannableString(Html.fromHtml(notification.status.content)); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                         newFollows++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "status": |                 case "status": | ||||||
|  | @ -230,7 +224,6 @@ public class NotificationsHelper { | ||||||
|                                     message = "\n" + new SpannableString(Html.fromHtml(notification.status.content)); |                                     message = "\n" + new SpannableString(Html.fromHtml(notification.status.content)); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                         newStatus++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "reblog": |                 case "reblog": | ||||||
|  | @ -241,7 +234,6 @@ public class NotificationsHelper { | ||||||
|                             message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reblog)); |                             message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reblog)); | ||||||
|                         else |                         else | ||||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reblog)); |                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reblog)); | ||||||
|                         newShare++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "favourite": |                 case "favourite": | ||||||
|  | @ -252,7 +244,6 @@ public class NotificationsHelper { | ||||||
|                             message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_favourite)); |                             message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_favourite)); | ||||||
|                         else |                         else | ||||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_favourite)); |                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_favourite)); | ||||||
|                         newAdds++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "follow_request": |                 case "follow_request": | ||||||
|  | @ -264,7 +255,6 @@ public class NotificationsHelper { | ||||||
|                         else |                         else | ||||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow_request)); |                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow_request)); | ||||||
|                         targeted_account = notification.account.id; |                         targeted_account = notification.account.id; | ||||||
|                         newFollows++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "follow": |                 case "follow": | ||||||
|  | @ -276,7 +266,6 @@ public class NotificationsHelper { | ||||||
|                         else |                         else | ||||||
|                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow)); |                             message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow)); | ||||||
|                         targeted_account = notification.account.id; |                         targeted_account = notification.account.id; | ||||||
|                         newFollows++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "poll": |                 case "poll": | ||||||
|  | @ -287,16 +276,11 @@ public class NotificationsHelper { | ||||||
|                             message = context.getString(R.string.notif_poll_self); |                             message = context.getString(R.string.notif_poll_self); | ||||||
|                         else |                         else | ||||||
|                             message = context.getString(R.string.notif_poll); |                             message = context.getString(R.string.notif_poll); | ||||||
|                         newPolls++; |  | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 default: |                 default: | ||||||
|             } |             } | ||||||
| 
 |             if (message != null) { | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls + newStatus; |  | ||||||
|         if (allNotifCount > 0) { |  | ||||||
|                 //Some others notification |                 //Some others notification | ||||||
|                 final Intent intent = new Intent(context, MainActivity.class); |                 final Intent intent = new Intent(context, MainActivity.class); | ||||||
|                 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); |                 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) |                 if (targeted_account != null && notifType == Helper.NotifType.FOLLLOW) | ||||||
|                     intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); |                     intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); | ||||||
|                 intent.putExtra(Helper.PREF_INSTANCE, account.instance); |                 intent.putExtra(Helper.PREF_INSTANCE, account.instance); | ||||||
|             notificationUrl = notifications.get(0).account.avatar; |                 notificationUrl = notification.account.avatar; | ||||||
|                 Handler mainHandler = new Handler(Looper.getMainLooper()); |                 Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||||
|                 final String finalNotificationUrl = notificationUrl; |                 final String finalNotificationUrl = notificationUrl; | ||||||
|                 Helper.NotifType finalNotifType = notifType; |                 Helper.NotifType finalNotifType = notifType; | ||||||
|                 String finalMessage = message; |                 String finalMessage = message; | ||||||
|             String finalMessage1 = message; |  | ||||||
|                 String finalTitle = title; |                 String finalTitle = title; | ||||||
|                 Runnable myRunnable = () -> Glide.with(context) |                 Runnable myRunnable = () -> Glide.with(context) | ||||||
|                         .asBitmap() |                         .asBitmap() | ||||||
|  | @ -325,13 +308,13 @@ public class NotificationsHelper { | ||||||
|                             @Override |                             @Override | ||||||
|                             public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { |                             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); |                                 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(); |                                     SharedPreferences.Editor editor = prefs.edit(); | ||||||
|                                     since_ids.put(account.user_id + "@" + account.instance, lastNotif); |                                     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.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id); | ||||||
|                                     editor.apply(); |                                     editor.apply(); | ||||||
|                                     notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(), |                                     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; |                                 return false; | ||||||
|                             } |                             } | ||||||
|  | @ -340,7 +323,7 @@ public class NotificationsHelper { | ||||||
|                             @Override |                             @Override | ||||||
|                             public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) { |                             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); |                                 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(); |                                     SharedPreferences.Editor editor = prefs.edit(); | ||||||
|                                     editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id); |                                     editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id); | ||||||
|                                     editor.apply(); |                                     editor.apply(); | ||||||
|  | @ -358,4 +341,6 @@ public class NotificationsHelper { | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue