1
0
mirror of https://github.com/etesync/android synced 2024-11-15 20:38:58 +00:00

Sync: fix the sync notification to work with etesync 2.0

This commit is contained in:
Tom Hacohen 2020-09-10 15:46:56 +03:00
parent f29d117cc6
commit 86ea7e878e
7 changed files with 44 additions and 29 deletions

View File

@ -44,7 +44,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
get() = context.getString(R.string.sync_error_calendar, account.name)
override val syncSuccessfullyTitle: String
get() = context.getString(R.string.sync_successfully_calendar, info.displayName,
get() = context.getString(R.string.sync_successfully_calendar, localCalendar().displayName,
account.name)
init {

View File

@ -36,6 +36,7 @@ import com.etesync.syncadapter.resource.*
import com.etesync.syncadapter.ui.AccountsActivity
import com.etesync.syncadapter.ui.DebugInfoActivity
import com.etesync.syncadapter.ui.ViewCollectionActivity
import com.etesync.syncadapter.ui.etebase.CollectionActivity
import org.jetbrains.anko.defaultSharedPreferences
import java.io.Closeable
import java.io.FileNotFoundException
@ -64,6 +65,11 @@ constructor(protected val context: Context, protected val account: Account, prot
protected lateinit var itemMgr: ItemManager
protected lateinit var cachedCollection: CachedCollection
// Sync counters
private var syncItemsTotal = 0
private var syncItemsDeleted = 0
private var syncItemsChanged = 0
protected var journal: JournalEntryManager? = null
private var _journalEntity: JournalEntity? = null
@ -140,6 +146,10 @@ constructor(protected val context: Context, protected val account: Account, prot
@TargetApi(21)
fun performSync() {
syncItemsTotal = 0
syncItemsDeleted = 0
syncItemsChanged = 0
var syncPhase = R.string.sync_phase_prepare
try {
Logger.log.info("Sync phase: " + context.getString(syncPhase))
@ -331,39 +341,28 @@ constructor(protected val context: Context, protected val account: Account, prot
private fun notifyUserOnSync() {
val changeNotification = context.defaultSharedPreferences.getBoolean(App.CHANGE_NOTIFICATION, true)
val remoteEntries = remoteEntries
if ((remoteEntries == null) || remoteEntries.isEmpty() || !changeNotification) {
if (!changeNotification || (syncItemsTotal == 0)) {
return
}
val notificationHelper = SyncNotification(context,
System.currentTimeMillis().toString(), notificationId())
var deleted = 0
var added = 0
var changed = 0
for (entry in remoteEntries) {
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
val action = cEntry.action
when (action) {
ADD -> added++
SyncEntry.Actions.DELETE -> deleted++
SyncEntry.Actions.CHANGE -> changed++
}
}
val resources = context.resources
val intent = ViewCollectionActivity.newIntent(context, account, info)
val intent = if (isLegacy) {
ViewCollectionActivity.newIntent(context, account, info)
} else {
CollectionActivity.newIntent(context, account, cachedCollection.col.uid)
}
notificationHelper.notify(syncSuccessfullyTitle,
String.format(context.getString(R.string.sync_successfully_modified),
resources.getQuantityString(R.plurals.sync_successfully,
remoteEntries!!.size, remoteEntries!!.size)),
syncItemsTotal, syncItemsTotal)),
String.format(context.getString(R.string.sync_successfully_modified_full),
resources.getQuantityString(R.plurals.sync_successfully,
added, added),
syncItemsChanged, syncItemsChanged),
resources.getQuantityString(R.plurals.sync_successfully,
changed, changed),
resources.getQuantityString(R.plurals.sync_successfully,
deleted, deleted)),
syncItemsDeleted, syncItemsDeleted)),
intent)
}
@ -443,6 +442,7 @@ constructor(protected val context: Context, protected val account: Account, prot
// Process new vcards from server
val size = items.size
var i = 0
syncItemsTotal += size
for (item in items) {
if (Thread.interrupted()) {
@ -451,6 +451,12 @@ constructor(protected val context: Context, protected val account: Account, prot
i++
Logger.log.info("Processing (${i}/${size}) UID=${item.uid} Etag=${item.etag}")
if (item.isDeleted) {
syncItemsDeleted++
} else {
syncItemsChanged++
}
processItem(item)
persistItem(item)
}
@ -491,6 +497,8 @@ constructor(protected val context: Context, protected val account: Account, prot
val strTotal = remoteEntries!!.size.toString()
var i = 0
syncItemsTotal += remoteEntries!!.size
for (entry in remoteEntries!!) {
if (Thread.interrupted()) {
throw InterruptedException()
@ -508,6 +516,13 @@ constructor(protected val context: Context, protected val account: Account, prot
error = e.toString()
}
val action = cEntry.action
when (action) {
ADD -> syncItemsChanged++
SyncEntry.Actions.DELETE -> syncItemsDeleted++
SyncEntry.Actions.CHANGE -> syncItemsChanged++
}
persistSyncEntry(entry.uid, cEntry, error)
remoteCTag = entry.uid

View File

@ -44,7 +44,7 @@ class TasksSyncManager(
get() = context.getString(R.string.sync_error_tasks, account.name)
override val syncSuccessfullyTitle: String
get() = context.getString(R.string.sync_successfully_tasks, info.displayName,
get() = context.getString(R.string.sync_successfully_tasks, localTaskList().name!!,
account.name)
init {

View File

@ -317,7 +317,7 @@
<string name="sync_successfully_contacts" formatted="false">Kontakter endret (%s)</string>
<string name="sync_successfully_tasks" formatted="false">Gjøremålene «%s» er endret (%s)</string>
<string name="sync_successfully_modified" formatted="false">%s endret.</string>
<string name="sync_successfully_modified_full" formatted="false">%s lagt til.\n%s oppdatert.\n%s slettet.</string>
<string name="sync_successfully_modified_full" formatted="false">%s oppdatert.\n%s slettet.</string>
<string name="sync_journal_readonly">Journalen \"%s\" er skrivebeskyttet</string>
<string name="sync_journal_readonly_message">Journalen er skrivebeskyttet, så alle endringene dine (%d) har blitt omgjort.</string>
<!-- Calendar invites -->

View File

@ -287,7 +287,7 @@
<string name="sync_successfully_calendar" formatted="false">Kalendarz \"%s\" został zmodyfikowany (%s)</string>
<string name="sync_successfully_contacts" formatted="false">Kontakty zostały zmodyfikowane (%s)</string>
<string name="sync_successfully_modified" formatted="false">%s został zmodyfikowany.</string>
<string name="sync_successfully_modified_full" formatted="false">%s został dodany. \n%s został zaktualizowany.\n%s został usunięty.</string>
<string name="sync_successfully_modified_full" formatted="false">%s został zaktualizowany.\n%s został usunięty.</string>
<!-- cert4android -->
<string name="certificate_notification_connection_security">EteSync: Bezpieczeństwo połączenia</string>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="sync_successfully">
<item quantity="one">%d entry</item>
<item quantity="other">%d entries</item>
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
</plurals>
</resources>

View File

@ -390,7 +390,7 @@
<string name="sync_successfully_contacts" formatted="false">Contacts modified (%s)</string>
<string name="sync_successfully_tasks" formatted="false">Tasks \"%s\" modified (%s)</string>
<string name="sync_successfully_modified" formatted="false">%s modified.</string>
<string name="sync_successfully_modified_full" formatted="false">%s added.\n%s updated.\n%s deleted.</string>
<string name="sync_successfully_modified_full" formatted="false">%s updated.\n%s deleted.</string>
<string name="sync_journal_readonly">Journal \"%s\" is read only</string>
<string name="sync_journal_readonly_message">The journal is read only so all of your changes (%d) have been reverted.</string>