From 64f8c5e1d29fa65d4fb92c1534eb60fbe628a26f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 14 Mar 2019 20:46:36 +0000 Subject: [PATCH] Move the sync notification helper under syncadapter and rename it. --- app/src/main/AndroidManifest.xml | 2 +- app/src/main/java/com/etesync/syncadapter/log/Logger.kt | 6 ++---- .../syncadapter/AddressBooksSyncAdapterService.kt | 2 +- .../syncadapter/syncadapter/CalendarSyncManager.kt | 3 +-- .../syncadapter/CalendarsSyncAdapterService.kt | 2 +- .../syncadapter/syncadapter/ContactsSyncAdapterService.kt | 2 +- .../com/etesync/syncadapter/syncadapter/SyncManager.kt | 8 ++++---- .../SyncNotification.kt} | 8 ++++++-- .../syncadapter/syncadapter/TasksSyncAdapterService.kt | 2 +- 9 files changed, 18 insertions(+), 17 deletions(-) rename app/src/main/java/com/etesync/syncadapter/{NotificationHelper.kt => syncadapter/SyncNotification.kt} (94%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d8c2337e..c8ff5974 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -195,7 +195,7 @@ android:parentActivityName=".ui.AccountsActivity"/> > @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class) constructor(protected val context: Context, protected val account: Account, protected val settings: AccountSettings, protected val extras: Bundle, protected val authority: String, protected val syncResult: SyncResult, journalUid: String, protected val serviceType: CollectionInfo.Type, accountName: String) { - protected val notificationManager: NotificationHelper + protected val notificationManager: SyncNotification protected val info: CollectionInfo protected var localCollection: LocalCollection? = null @@ -94,7 +94,7 @@ constructor(protected val context: Context, protected val account: Account, prot info = JournalEntity.fetch(data, serviceEntity, journalUid)!!.info // dismiss previous error notifications - notificationManager = NotificationHelper(context, journalUid, notificationId()) + notificationManager = SyncNotification(context, journalUid, notificationId()) notificationManager.cancel() Logger.log.info(String.format(Locale.getDefault(), "Syncing collection %s (version: %d)", journalUid, info.version)) @@ -233,7 +233,7 @@ constructor(protected val context: Context, protected val account: Account, prot if (remoteEntries!!.isEmpty() || !changeNotification) { return } - val notificationHelper = NotificationHelper(context, + val notificationHelper = SyncNotification(context, System.currentTimeMillis().toString(), notificationId()) var deleted = 0 @@ -533,7 +533,7 @@ constructor(protected val context: Context, protected val account: Account, prot } private fun notifyDiscardedChange() { - val notification = NotificationHelper(context, "discarded_${info.uid}", notificationId()) + val notification = SyncNotification(context, "discarded_${info.uid}", notificationId()) val intent = Intent(context, AccountsActivity::class.java) notification.notify(context.getString(R.string.sync_journal_readonly, info.displayName), context.getString(R.string.sync_journal_readonly_message, numDiscarded), null, intent, R.drawable.ic_error_light) } diff --git a/app/src/main/java/com/etesync/syncadapter/NotificationHelper.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt similarity index 94% rename from app/src/main/java/com/etesync/syncadapter/NotificationHelper.kt rename to app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt index 6c752eb7..57c211d2 100644 --- a/app/src/main/java/com/etesync/syncadapter/NotificationHelper.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncNotification.kt @@ -1,4 +1,4 @@ -package com.etesync.syncadapter +package com.etesync.syncadapter.syncadapter import android.app.Activity import android.app.NotificationChannel @@ -14,6 +14,10 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import at.bitfire.ical4android.CalendarStorageException import at.bitfire.vcard4android.ContactsStorageException +import com.etesync.syncadapter.AccountSettings +import com.etesync.syncadapter.App +import com.etesync.syncadapter.Constants +import com.etesync.syncadapter.R import com.etesync.syncadapter.journalmanager.Exceptions import com.etesync.syncadapter.log.Logger import com.etesync.syncadapter.ui.AccountSettingsActivity @@ -21,7 +25,7 @@ import com.etesync.syncadapter.ui.DebugInfoActivity import com.etesync.syncadapter.ui.WebViewActivity import java.util.logging.Level -class NotificationHelper(internal val context: Context, internal val notificationTag: String, internal val notificationId: Int) { +class SyncNotification(internal val context: Context, internal val notificationTag: String, internal val notificationId: Int) { internal val notificationManager: NotificationManagerCompat lateinit var detailsIntent: Intent diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt index 8c5a503c..454141c9 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/TasksSyncAdapterService.kt @@ -46,7 +46,7 @@ class TasksSyncAdapterService: SyncAdapterService() { override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) { super.onPerformSync(account, extras, authority, provider, syncResult) - val notificationManager = NotificationHelper(context, "journals-tasks", Constants.NOTIFICATION_TASK_SYNC) + val notificationManager = SyncNotification(context, "journals-tasks", Constants.NOTIFICATION_TASK_SYNC) notificationManager.cancel() try {