mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix issue #90 - Cancel notifications when visiting notifications timeline
This commit is contained in:
parent
3ec4437a5b
commit
6fb830aefe
5 changed files with 22 additions and 9 deletions
|
@ -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
|
* Sends notification with intent
|
||||||
*
|
*
|
||||||
|
@ -1011,16 +1016,16 @@ public class Helper {
|
||||||
* @param message String message for the notification
|
* @param message String message for the notification
|
||||||
*/
|
*/
|
||||||
@SuppressLint("UnspecifiedImmutableFlag")
|
@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);
|
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
// prepare intent which is triggered if the user click on the notification
|
// prepare intent which is triggered if the user click on the notification
|
||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||||
int notificationId = (int) System.currentTimeMillis();
|
int requestCode = (int) System.currentTimeMillis();
|
||||||
PendingIntent pIntent;
|
PendingIntent pIntent;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
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 {
|
} 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);
|
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||||
|
@ -1149,7 +1154,7 @@ public class Helper {
|
||||||
.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
||||||
.setGroupSummary(true)
|
.setGroupSummary(true)
|
||||||
.build();
|
.build();
|
||||||
notificationManager.notify(0, summaryNotification);
|
notificationManager.notify(notificationId, summaryNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class MediaHelper {
|
||||||
Uri uri = Uri.fromFile(backupFile);
|
Uri uri = Uri.fromFile(backupFile);
|
||||||
intent.setDataAndType(uri, mime);
|
intent.setDataAndType(uri, mime);
|
||||||
if (!share) {
|
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));
|
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();
|
Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -313,7 +313,7 @@ public class NotificationsHelper {
|
||||||
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, Helper.NOTIFICATION_USER_NOTIF, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||||
R.mipmap.ic_launcher), finalNotifType, finalTitle, finalMessage);
|
R.mipmap.ic_launcher), finalNotifType, finalTitle, finalMessage);
|
||||||
}
|
}
|
||||||
return false;
|
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.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
since_ids.put(account.user_id + "@" + account.instance, lastNotif);
|
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);
|
Uri uri = Uri.parse("file://" + fullPath);
|
||||||
intentOpen.setDataAndType(uri, "text/csv");
|
intentOpen.setDataAndType(uri, "text/csv");
|
||||||
String title = getString(R.string.data_export_theme);
|
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);
|
R.mipmap.ic_launcher), Helper.NotifType.BACKUP, title, message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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,
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -166,6 +167,13 @@ public class FragmentMastodonNotification extends Fragment {
|
||||||
return root;
|
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
|
* Intialize the view for notifications
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue