diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index bb83e2289..634cf4fab 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -1001,6 +1001,11 @@ public class Helper { } + + public static final int NOTIFICATION_MEDIA = 451; + public static final int NOTIFICATION_USER_NOTIF = 411; + public static final int NOTIFICATION_THEMING = 412; + /** * Sends notification with intent * @@ -1011,16 +1016,16 @@ public class Helper { * @param message String message for the notification */ @SuppressLint("UnspecifiedImmutableFlag") - public static void notify_user(Context context, Account account, Intent intent, Bitmap icon, NotifType notifType, String title, String message) { + public static void notify_user(Context context, int notificationId, Account account, Intent intent, Bitmap icon, NotifType notifType, String title, String message) { final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); // prepare intent which is triggered if the user click on the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); - int notificationId = (int) System.currentTimeMillis(); + int requestCode = (int) System.currentTimeMillis(); PendingIntent pIntent; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { - pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); + pIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); } else { - pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_ONE_SHOT); + pIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); } intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); @@ -1149,7 +1154,7 @@ public class Helper { .setGroup(account.mastodon_account.acct + "@" + account.instance) .setGroupSummary(true) .build(); - notificationManager.notify(0, summaryNotification); + notificationManager.notify(notificationId, summaryNotification); } /** diff --git a/app/src/main/java/app/fedilab/android/helper/MediaHelper.java b/app/src/main/java/app/fedilab/android/helper/MediaHelper.java index 5000226f6..8cb298d5c 100644 --- a/app/src/main/java/app/fedilab/android/helper/MediaHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/MediaHelper.java @@ -163,7 +163,7 @@ public class MediaHelper { Uri uri = Uri.fromFile(backupFile); intent.setDataAndType(uri, mime); if (!share) { - notify_user(context, BaseMainActivity.accountWeakReference.get(), intent, BitmapFactory.decodeResource(context.getResources(), + notify_user(context, Helper.NOTIFICATION_MEDIA, BaseMainActivity.accountWeakReference.get(), intent, BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show(); } else { diff --git a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java index af95e3d4c..0c1039f78 100644 --- a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java @@ -313,7 +313,7 @@ public class NotificationsHelper { 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(), + notify_user(context, Helper.NOTIFICATION_USER_NOTIF, account, intent, BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), finalNotifType, finalTitle, finalMessage); } return false; @@ -328,7 +328,7 @@ public class NotificationsHelper { 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); - notify_user(context, account, intent, resource, finalNotifType, finalTitle, finalMessage); + notify_user(context, Helper.NOTIFICATION_USER_NOTIF, account, intent, resource, finalNotifType, finalTitle, finalMessage); } } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java index a0d079300..ad07bd7ac 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java @@ -571,7 +571,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements Uri uri = Uri.parse("file://" + fullPath); intentOpen.setDataAndType(uri, "text/csv"); String title = getString(R.string.data_export_theme); - Helper.notify_user(getActivity(), BaseMainActivity.accountWeakReference.get(), intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(), + Helper.notify_user(getActivity(), Helper.NOTIFICATION_THEMING, BaseMainActivity.accountWeakReference.get(), intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(), R.mipmap.ic_launcher), Helper.NotifType.BACKUP, title, message); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java index a2df5672d..36a6a92eb 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java @@ -14,6 +14,7 @@ package app.fedilab.android.ui.fragment.timeline; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -166,6 +167,13 @@ public class FragmentMastodonNotification extends Fragment { return root; } + @Override + public void onResume() { + super.onResume(); + NotificationManager notificationManager = (NotificationManager) requireActivity().getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(Helper.NOTIFICATION_USER_NOTIF); + } + /** * Intialize the view for notifications *