diff --git a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java index 78cc2950d..d5414647f 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java @@ -1620,9 +1620,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_boost" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_boost"); startActivity(intent); } }); @@ -1632,9 +1630,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_fav" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_fav"); startActivity(intent); } }); @@ -1644,9 +1640,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_follow" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_follow"); startActivity(intent); } }); @@ -1656,9 +1650,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_mention" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_mention"); startActivity(intent); } }); @@ -1668,9 +1660,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_poll" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_poll"); startActivity(intent); } }); @@ -1680,9 +1670,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_backup" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_backup"); startActivity(intent); } }); @@ -1692,9 +1680,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - if( account != null) { - intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_store" + account.getAcct() + "@" + account.getInstance()); - } + intent.putExtra(Settings.EXTRA_CHANNEL_ID, "channel_store"); startActivity(intent); } }); 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 d973918c8..c2b5d66d7 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -1058,63 +1058,66 @@ public class Helper { * Sends notification with intent * @param context Context * @param intent Intent associated to the notifcation - * @param notificationId int id of the notification * @param icon Bitmap profile picture * @param title String title of the notification * @param message String message for the notification */ - public static void notify_user(Context context, Account account, Intent intent, int notificationId, Bitmap icon, NotifType notifType, String title, String message ) { + public static void notify_user(Context context, Account account, Intent intent, Bitmap icon, NotifType notifType, String title, String message ) { final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); // prepare intent which is triggered if the user click on the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + int notificationId = Integer.parseInt(account.getId()); + PendingIntent pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_ONE_SHOT); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // build notification String channelId; String channelTitle; + switch(notifType){ case BOOST: channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance(); channelTitle = context.getString(R.string.channel_notif_boost); break; case FAV: - channelId = "channel_fav"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_fav); + channelId = "channel_fav"; + channelTitle = context.getString(R.string.channel_notif_fav); break; case FOLLLOW: - channelId = "channel_follow"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_follow); + channelId = "channel_follow"; + channelTitle = context.getString(R.string.channel_notif_follow); break; case MENTION: - channelId = "channel_mention"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_mention); + channelId = "channel_mention"; + channelTitle = context.getString(R.string.channel_notif_mention); break; case POLL: - channelId = "channel_poll"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_poll); + channelId = "channel_poll"; + channelTitle = context.getString(R.string.channel_notif_poll); break; case BACKUP: - channelId = "channel_backup"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_backup); + channelId = "channel_backup"; + channelTitle = context.getString(R.string.channel_notif_backup); break; case STORE: - channelId = "channel_store"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_media); + channelId = "channel_store"; + channelTitle = context.getString(R.string.channel_notif_media); break; case TOOT: - channelId = "channel_toot"+account.getAcct()+"@"+account.getInstance(); - channelTitle = account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_toot); + channelId = "channel_toot"; + channelTitle = context.getString(R.string.channel_notif_toot); break; default: - channelId = "channel_boost"+account.getAcct()+"@"+account.getInstance(); - channelTitle =account.getAcct()+"@"+account.getInstance() + " - " + context.getString(R.string.channel_notif_boost); + channelId = "channel_boost"; + channelTitle = context.getString(R.string.channel_notif_boost); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) .setSmallIcon(R.drawable.fedilab_notification_icon) .setTicker(message) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) + .setGroup(account.getAcct()+"@"+account.getInstance()) .setContentIntent(pIntent) .setContentText(message); int ledColour = Color.BLUE; @@ -1212,8 +1215,6 @@ public class Helper { copy(fileVideo, fileVideoTargeded); file = fileVideoTargeded; } - Random r = new Random(); - final int notificationIdTmp = r.nextInt(10000); // prepare intent which is triggered if the // notification is selected final Intent intent = new Intent(); @@ -1238,7 +1239,7 @@ public class Helper { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - notify_user(context, account, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), + notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); return false; @@ -1251,7 +1252,7 @@ public class Helper { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - notify_user(context, account, intent, notificationIdTmp, resource, NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); + notify_user(context, account, intent, resource, NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName)); Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); } }); @@ -4102,8 +4103,6 @@ public class Helper { String mime = Helper.getMimeType(url); File file = new File(download.getFileUri().getPath()); final Intent intent = new Intent(); - Random r = new Random(); - final int notificationIdTmp = r.nextInt(10000); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.parse("file://" + file.getAbsolutePath() ); intent.setDataAndType(uri, mime); @@ -4111,7 +4110,7 @@ public class Helper { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - Helper.notify_user(context, account, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), + Helper.notify_user(context, account, 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)); } } @@ -4304,8 +4303,6 @@ public class Helper { } catch (Exception ignored) { } final Intent intent = new Intent(); - Random r = new Random(); - final int notificationIdTmp = r.nextInt(10000); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File(filename)); intent.setDataAndType(uri, "text/csv"); @@ -4313,7 +4310,7 @@ public class Helper { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - Helper.notify_user(context, account,intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), + Helper.notify_user(context, account,intent, BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.muted_instance_exported), context.getString(R.string.download_from, backupDBPath)); } }.start(); diff --git a/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java b/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java index 24fe19839..01af19a39 100644 --- a/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java +++ b/app/src/main/java/app/fedilab/android/jobs/NotificationsSyncJob.java @@ -266,13 +266,6 @@ public class NotificationsSyncJob extends Job { if( targeted_account != null && notifType == Helper.NotifType.FOLLLOW) intent.putExtra(INTENT_TARGETED_ACCOUNT, targeted_account); intent.putExtra(PREF_INSTANCE, account.getInstance()); - long notif_id; - if( account.getId() != null && account.getId().matches("-?\\d+(\\.\\d+)?")){ - notif_id = Long.parseLong(account.getId()); - }else{ - notif_id = new Random().nextLong(); - } - final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1); if( notificationUrl != null ){ final String finalTitle = title; Handler mainHandler = new Handler(Looper.getMainLooper()); @@ -294,7 +287,7 @@ public class NotificationsSyncJob extends Job { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - notify_user(getContext(), account, intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(), + notify_user(getContext(), account, intent, BitmapFactory.decodeResource(getContext().getResources(), R.drawable.mastodonlogo), finalNotifType, finalTitle, message); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){ @@ -308,7 +301,7 @@ public class NotificationsSyncJob extends Job { .into(new SimpleTarget() { @Override public void onResourceReady(@NonNull Bitmap resource, Transition transition) { - notify_user(getContext(), account, intent, notificationId, resource, finalNotifType, finalTitle, message); + notify_user(getContext(), account, intent, resource, finalNotifType, finalTitle, message); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){ SharedPreferences.Editor editor = sharedpreferences.edit(); diff --git a/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java b/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java index 48b51f3e0..83eb6b6ec 100644 --- a/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java +++ b/app/src/main/java/app/fedilab/android/services/BackupStatusInDataBaseService.java @@ -125,10 +125,8 @@ public class BackupStatusInDataBaseService extends IntentService { message = getString(R.string.data_backup_success, String.valueOf(backupStatus.size())); Intent mainActivity = new Intent(BackupStatusInDataBaseService.this, MainActivity.class); mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_INTENT); - long notif_id = Long.parseLong(account.getId()); - int notificationId = ((notif_id + 4) > 2147483647) ? (int) (2147483647 - notif_id - 4) : (int) (notif_id + 4); String title = getString(R.string.data_backup_toots, account.getAcct()); - Helper.notify_user(getApplicationContext(),account, mainActivity, notificationId, BitmapFactory.decodeResource(getResources(), + Helper.notify_user(getApplicationContext(),account, mainActivity, BitmapFactory.decodeResource(getResources(), R.drawable.mastodonlogo), Helper.NotifType.BACKUP, title, message); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/services/BackupStatusService.java b/app/src/main/java/app/fedilab/android/services/BackupStatusService.java index cafe8cd7b..05061e8c3 100644 --- a/app/src/main/java/app/fedilab/android/services/BackupStatusService.java +++ b/app/src/main/java/app/fedilab/android/services/BackupStatusService.java @@ -182,10 +182,8 @@ public class BackupStatusService extends IntentService { intentOpen.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.parse("file://" + fullPath); intentOpen.setDataAndType(uri, "text/csv"); - long notif_id = Long.parseLong(account.getId()); - int notificationId = ((notif_id + 3) > 2147483647) ? (int) (2147483647 - notif_id - 3) : (int) (notif_id + 3); String title = getString(R.string.data_export_toots, account.getAcct()); - Helper.notify_user(getApplicationContext(), account, intentOpen, notificationId, BitmapFactory.decodeResource(getResources(), + Helper.notify_user(getApplicationContext(), account, intentOpen, BitmapFactory.decodeResource(getResources(), R.drawable.mastodonlogo),Helper.NotifType.BACKUP, title, message); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java index df6bfddfe..481035081 100644 --- a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java +++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java @@ -393,8 +393,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece if (targeted_account != null) { intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); } - long notif_id = Long.parseLong(account.getId()); - final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1); final String finalTitle = title; Handler mainHandler = new Handler(Looper.getMainLooper()); Helper.NotifType finalNotifType = notifType; @@ -413,7 +411,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - Helper.notify_user(getApplicationContext(),account, intent, notificationId, BitmapFactory.decodeResource(getResources(), + Helper.notify_user(getApplicationContext(),account, intent, BitmapFactory.decodeResource(getResources(), R.drawable.mastodonlogo), finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance()); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { @@ -428,7 +426,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece @Override public void onResourceReady(@NonNull Bitmap resource, Transition transition) { - Helper.notify_user(getApplicationContext(), account,intent, notificationId, resource, finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance()); + Helper.notify_user(getApplicationContext(), account,intent, resource, finalNotifType, finalTitle, "@" + account.getAcct() + "@" + account.getInstance()); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { SharedPreferences.Editor editor = sharedpreferences.edit(); diff --git a/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java b/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java index a054e2db1..a42913e3d 100644 --- a/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java +++ b/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java @@ -514,8 +514,6 @@ public class Sqlite extends SQLiteOpenHelper { src.close(); dst.close(); final Intent intent = new Intent(); - Random r = new Random(); - final int notificationIdTmp = r.nextInt(10000); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.fromFile(dbDest); intent.setDataAndType(uri, "*/*"); @@ -524,7 +522,7 @@ public class Sqlite extends SQLiteOpenHelper { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - Helper.notify_user(context, account, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(), + Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, backupDBPath)); Toasty.success(context, context.getString(R.string.data_base_exported),Toast.LENGTH_LONG).show(); }