Fix issue #90 - Cancel notifications when visiting notifications timeline

pull/95/head
Thomas 3 years ago
parent 3ec4437a5b
commit 6fb830aefe

@ -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);
}
/**

@ -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 {

@ -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);
}
}

@ -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();

@ -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 <http://www.gnu.org/licenses>. */
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
*

Loading…
Cancel
Save