1
0
mirror of https://github.com/etesync/android synced 2025-06-28 19:02:38 +00:00

Move the sync notification helper under syncadapter and rename it.

This commit is contained in:
Tom Hacohen 2019-03-14 20:46:36 +00:00
parent ac22ece30d
commit 64f8c5e1d2
9 changed files with 18 additions and 17 deletions

View File

@ -195,7 +195,7 @@
android:parentActivityName=".ui.AccountsActivity"/> android:parentActivityName=".ui.AccountsActivity"/>
<activity <activity
android:name=".NotificationHelper$NotificationHandlerActivity" android:name=".syncadapter.SyncNotification$NotificationHandlerActivity"
android:theme="@style/Theme.Transparent" /> android:theme="@style/Theme.Transparent" />
<activity <activity

View File

@ -21,10 +21,8 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import com.etesync.syncadapter.App import com.etesync.syncadapter.App
import com.etesync.syncadapter.Constants import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.NotificationHelper import com.etesync.syncadapter.syncadapter.SyncNotification
import com.etesync.syncadapter.R import com.etesync.syncadapter.R
import com.etesync.syncadapter.model.ServiceDB
import com.etesync.syncadapter.model.Settings
import com.etesync.syncadapter.ui.AppSettingsActivity import com.etesync.syncadapter.ui.AppSettingsActivity
import org.apache.commons.lang3.time.DateFormatUtils import org.apache.commons.lang3.time.DateFormatUtils
import java.io.File import java.io.File
@ -79,7 +77,7 @@ object Logger : SharedPreferences.OnSharedPreferenceChangeListener {
builder.setSmallIcon(R.drawable.ic_sd_storage_light) builder.setSmallIcon(R.drawable.ic_sd_storage_light)
.setLargeIcon(App.getLauncherBitmap(context)) .setLargeIcon(App.getLauncherBitmap(context))
.setContentTitle(context.getString(R.string.logging_davdroid_file_logging)) .setContentTitle(context.getString(R.string.logging_davdroid_file_logging))
.setChannelId(NotificationHelper.CHANNEL_ID) .setChannelId(SyncNotification.CHANNEL_ID)
val logDir = debugDir(context) ?: return val logDir = debugDir(context) ?: return
val logFile = File(logDir, val logFile = File(logDir,

View File

@ -41,7 +41,7 @@ class AddressBooksSyncAdapterService : SyncAdapterService() {
override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) { override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) {
super.onPerformSync(account, extras, authority, provider, syncResult) super.onPerformSync(account, extras, authority, provider, syncResult)
val notificationManager = NotificationHelper(context, "journals-contacts", Constants.NOTIFICATION_CONTACTS_SYNC) val notificationManager = SyncNotification(context, "journals-contacts", Constants.NOTIFICATION_CONTACTS_SYNC)
notificationManager.cancel() notificationManager.cancel()
try { try {

View File

@ -19,7 +19,6 @@ import at.bitfire.ical4android.InvalidCalendarException
import at.bitfire.vcard4android.ContactsStorageException import at.bitfire.vcard4android.ContactsStorageException
import com.etesync.syncadapter.AccountSettings import com.etesync.syncadapter.AccountSettings
import com.etesync.syncadapter.Constants import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.NotificationHelper
import com.etesync.syncadapter.R import com.etesync.syncadapter.R
import com.etesync.syncadapter.journalmanager.Exceptions import com.etesync.syncadapter.journalmanager.Exceptions
import com.etesync.syncadapter.journalmanager.JournalEntryManager import com.etesync.syncadapter.journalmanager.JournalEntryManager
@ -129,7 +128,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
private fun createInviteAttendeesNotification(event: Event, icsContent: String) { private fun createInviteAttendeesNotification(event: Event, icsContent: String) {
val intent = EventEmailInvitation(context, account).createIntent(event, icsContent) val intent = EventEmailInvitation(context, account).createIntent(event, icsContent)
if (intent != null) { if (intent != null) {
val notificationHelper = NotificationHelper(context, event.uid!!, event.uid!!.hashCode()) val notificationHelper = SyncNotification(context, event.uid!!, event.uid!!.hashCode())
notificationHelper.notify( notificationHelper.notify(
context.getString( context.getString(
R.string.sync_calendar_attendees_notification_title, event.summary), R.string.sync_calendar_attendees_notification_title, event.summary),

View File

@ -39,7 +39,7 @@ class CalendarsSyncAdapterService : SyncAdapterService() {
override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) { override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) {
super.onPerformSync(account, extras, authority, provider, syncResult) super.onPerformSync(account, extras, authority, provider, syncResult)
val notificationManager = NotificationHelper(context, "journals-calendar", Constants.NOTIFICATION_CALENDAR_SYNC) val notificationManager = SyncNotification(context, "journals-calendar", Constants.NOTIFICATION_CALENDAR_SYNC)
notificationManager.cancel() notificationManager.cancel()
try { try {

View File

@ -30,7 +30,7 @@ class ContactsSyncAdapterService : SyncAdapterService() {
override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) { override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) {
super.onPerformSync(account, extras, authority, provider, syncResult) super.onPerformSync(account, extras, authority, provider, syncResult)
val notificationManager = NotificationHelper(context, "journals-contacts", Constants.NOTIFICATION_CONTACTS_SYNC) val notificationManager = SyncNotification(context, "journals-contacts", Constants.NOTIFICATION_CONTACTS_SYNC)
notificationManager.cancel() notificationManager.cancel()
try { try {

View File

@ -41,7 +41,7 @@ import java.util.logging.Level
abstract class SyncManager<T: LocalResource<*>> @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class) abstract class SyncManager<T: LocalResource<*>> @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) { 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 val info: CollectionInfo
protected var localCollection: LocalCollection<T>? = null protected var localCollection: LocalCollection<T>? = null
@ -94,7 +94,7 @@ constructor(protected val context: Context, protected val account: Account, prot
info = JournalEntity.fetch(data, serviceEntity, journalUid)!!.info info = JournalEntity.fetch(data, serviceEntity, journalUid)!!.info
// dismiss previous error notifications // dismiss previous error notifications
notificationManager = NotificationHelper(context, journalUid, notificationId()) notificationManager = SyncNotification(context, journalUid, notificationId())
notificationManager.cancel() notificationManager.cancel()
Logger.log.info(String.format(Locale.getDefault(), "Syncing collection %s (version: %d)", journalUid, info.version)) 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) { if (remoteEntries!!.isEmpty() || !changeNotification) {
return return
} }
val notificationHelper = NotificationHelper(context, val notificationHelper = SyncNotification(context,
System.currentTimeMillis().toString(), notificationId()) System.currentTimeMillis().toString(), notificationId())
var deleted = 0 var deleted = 0
@ -533,7 +533,7 @@ constructor(protected val context: Context, protected val account: Account, prot
} }
private fun notifyDiscardedChange() { 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) 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) 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)
} }

View File

@ -1,4 +1,4 @@
package com.etesync.syncadapter package com.etesync.syncadapter.syncadapter
import android.app.Activity import android.app.Activity
import android.app.NotificationChannel import android.app.NotificationChannel
@ -14,6 +14,10 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import at.bitfire.ical4android.CalendarStorageException import at.bitfire.ical4android.CalendarStorageException
import at.bitfire.vcard4android.ContactsStorageException 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.journalmanager.Exceptions
import com.etesync.syncadapter.log.Logger import com.etesync.syncadapter.log.Logger
import com.etesync.syncadapter.ui.AccountSettingsActivity import com.etesync.syncadapter.ui.AccountSettingsActivity
@ -21,7 +25,7 @@ import com.etesync.syncadapter.ui.DebugInfoActivity
import com.etesync.syncadapter.ui.WebViewActivity import com.etesync.syncadapter.ui.WebViewActivity
import java.util.logging.Level 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 internal val notificationManager: NotificationManagerCompat
lateinit var detailsIntent: Intent lateinit var detailsIntent: Intent

View File

@ -46,7 +46,7 @@ class TasksSyncAdapterService: SyncAdapterService() {
override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) { override fun onPerformSync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) {
super.onPerformSync(account, extras, authority, provider, 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() notificationManager.cancel()
try { try {