diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java index f8bb2a99..72d0b0df 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java @@ -64,15 +64,21 @@ public class CalendarSyncManager extends SyncManager { public CalendarSyncManager(Context context, Account account, Bundle extras, String authority, SyncResult result, LocalCalendar calendar) throws InvalidAccountException { - super(Constants.NOTIFICATION_CALENDAR_SYNC, context, account, extras, authority, result); + super(context, account, extras, authority, result, "calendar/" + calendar.getId()); localCollection = calendar; } + @Override + protected int notificationId() { + return Constants.NOTIFICATION_CALENDAR_SYNC; + } + @Override protected String getSyncErrorTitle() { return context.getString(R.string.sync_error_calendar, account.name); } + @Override protected void prepare() { collectionURL = HttpUrl.parse(localCalendar().getName()); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java index 63b9f62b..e7da7443 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java @@ -72,11 +72,16 @@ public class ContactsSyncManager extends SyncManager { public ContactsSyncManager(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult result, CollectionInfo remote) throws InvalidAccountException { - super(Constants.NOTIFICATION_CONTACTS_SYNC, context, account, extras, authority, result); + super(context, account, extras, authority, result, "addressBook"); this.provider = provider; this.remote = remote; } + @Override + protected int notificationId() { + return Constants.NOTIFICATION_CONTACTS_SYNC; + } + @Override protected String getSyncErrorTitle() { return context.getString(R.string.sync_error_contacts, account.name); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index 1f6e2951..354f458b 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -15,6 +15,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SyncResult; +import android.net.Uri; import android.os.Bundle; import android.support.v7.app.NotificationCompat; import android.text.TextUtils; @@ -67,7 +68,7 @@ abstract public class SyncManager { SYNC_PHASE_SAVE_SYNC_STATE = 10; protected final NotificationManager notificationManager; - protected final int notificationId; + protected final String uniqueCollectionId; protected final Context context; protected final Account account; @@ -97,7 +98,7 @@ abstract public class SyncManager { - public SyncManager(int notificationId, Context context, Account account, Bundle extras, String authority, SyncResult syncResult) throws InvalidAccountException { + public SyncManager(Context context, Account account, Bundle extras, String authority, SyncResult syncResult, String uniqueCollectionId) throws InvalidAccountException { this.context = context; this.account = account; this.extras = extras; @@ -111,10 +112,12 @@ abstract public class SyncManager { httpClient = HttpClient.create(context, account); // dismiss previous error notifications + this.uniqueCollectionId = uniqueCollectionId; notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.cancel(account.name, this.notificationId = notificationId); + notificationManager.cancel(uniqueCollectionId, notificationId()); } + protected abstract int notificationId(); protected abstract String getSyncErrorTitle(); @TargetApi(21) @@ -218,10 +221,13 @@ abstract public class SyncManager { detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } + // to make the PendingIntent unique + detailsIntent.setData(Uri.parse("uri://" + getClass().getName() + "/" + uniqueCollectionId)); + NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getSyncErrorTitle()) - .setContentIntent(PendingIntent.getActivity(context, notificationId, detailsIntent, PendingIntent.FLAG_UPDATE_CURRENT)) + .setContentIntent(PendingIntent.getActivity(context, 0, detailsIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setCategory(NotificationCompat.CATEGORY_ERROR) .setLocalOnly(true); @@ -233,7 +239,7 @@ abstract public class SyncManager { // should never happen } - notificationManager.notify(account.name, notificationId, builder.build()); + notificationManager.notify(uniqueCollectionId, notificationId(), builder.build()); } } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java index 3488d699..0c76136c 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java @@ -66,11 +66,16 @@ public class TasksSyncManager extends SyncManager { public TasksSyncManager(Context context, Account account, Bundle extras, String authority, TaskProvider provider, SyncResult result, LocalTaskList taskList) throws InvalidAccountException { - super(Constants.NOTIFICATION_TASK_SYNC, context, account, extras, authority, result); + super(context, account, extras, authority, result, "taskList/" + taskList.getId()); this.provider = provider; localCollection = taskList; } + @Override + protected int notificationId() { + return Constants.NOTIFICATION_TASK_SYNC; + } + @Override protected String getSyncErrorTitle() { return context.getString(R.string.sync_error_tasks, account.name);