mirror of
https://github.com/etesync/android
synced 2024-11-29 11:28:19 +00:00
SyncManager notifications: create a unique notification for every synced collection
This commit is contained in:
parent
f0e45c71f5
commit
25c54cce62
@ -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 {
|
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;
|
localCollection = calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int notificationId() {
|
||||||
|
return Constants.NOTIFICATION_CALENDAR_SYNC;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSyncErrorTitle() {
|
protected String getSyncErrorTitle() {
|
||||||
return context.getString(R.string.sync_error_calendar, account.name);
|
return context.getString(R.string.sync_error_calendar, account.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepare() {
|
protected void prepare() {
|
||||||
collectionURL = HttpUrl.parse(localCalendar().getName());
|
collectionURL = HttpUrl.parse(localCalendar().getName());
|
||||||
|
@ -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 {
|
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.provider = provider;
|
||||||
this.remote = remote;
|
this.remote = remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int notificationId() {
|
||||||
|
return Constants.NOTIFICATION_CONTACTS_SYNC;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSyncErrorTitle() {
|
protected String getSyncErrorTitle() {
|
||||||
return context.getString(R.string.sync_error_contacts, account.name);
|
return context.getString(R.string.sync_error_contacts, account.name);
|
||||||
|
@ -15,6 +15,7 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SyncResult;
|
import android.content.SyncResult;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -67,7 +68,7 @@ abstract public class SyncManager {
|
|||||||
SYNC_PHASE_SAVE_SYNC_STATE = 10;
|
SYNC_PHASE_SAVE_SYNC_STATE = 10;
|
||||||
|
|
||||||
protected final NotificationManager notificationManager;
|
protected final NotificationManager notificationManager;
|
||||||
protected final int notificationId;
|
protected final String uniqueCollectionId;
|
||||||
|
|
||||||
protected final Context context;
|
protected final Context context;
|
||||||
protected final Account account;
|
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.context = context;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.extras = extras;
|
this.extras = extras;
|
||||||
@ -111,10 +112,12 @@ abstract public class SyncManager {
|
|||||||
httpClient = HttpClient.create(context, account);
|
httpClient = HttpClient.create(context, account);
|
||||||
|
|
||||||
// dismiss previous error notifications
|
// dismiss previous error notifications
|
||||||
|
this.uniqueCollectionId = uniqueCollectionId;
|
||||||
notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
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();
|
protected abstract String getSyncErrorTitle();
|
||||||
|
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
@ -218,10 +221,13 @@ abstract public class SyncManager {
|
|||||||
detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase);
|
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);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
builder .setSmallIcon(R.drawable.ic_launcher)
|
builder .setSmallIcon(R.drawable.ic_launcher)
|
||||||
.setContentTitle(getSyncErrorTitle())
|
.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)
|
.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||||
.setLocalOnly(true);
|
.setLocalOnly(true);
|
||||||
|
|
||||||
@ -233,7 +239,7 @@ abstract public class SyncManager {
|
|||||||
// should never happen
|
// should never happen
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManager.notify(account.name, notificationId, builder.build());
|
notificationManager.notify(uniqueCollectionId, notificationId(), builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
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;
|
this.provider = provider;
|
||||||
localCollection = taskList;
|
localCollection = taskList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int notificationId() {
|
||||||
|
return Constants.NOTIFICATION_TASK_SYNC;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSyncErrorTitle() {
|
protected String getSyncErrorTitle() {
|
||||||
return context.getString(R.string.sync_error_tasks, account.name);
|
return context.getString(R.string.sync_error_tasks, account.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user