mirror of
https://github.com/etesync/android
synced 2024-12-23 07:08:16 +00:00
Sync: fix the sync notification to work with etesync 2.0
This commit is contained in:
parent
f29d117cc6
commit
86ea7e878e
@ -44,7 +44,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
get() = context.getString(R.string.sync_error_calendar, account.name)
|
get() = context.getString(R.string.sync_error_calendar, account.name)
|
||||||
|
|
||||||
override val syncSuccessfullyTitle: String
|
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)
|
account.name)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -36,6 +36,7 @@ import com.etesync.syncadapter.resource.*
|
|||||||
import com.etesync.syncadapter.ui.AccountsActivity
|
import com.etesync.syncadapter.ui.AccountsActivity
|
||||||
import com.etesync.syncadapter.ui.DebugInfoActivity
|
import com.etesync.syncadapter.ui.DebugInfoActivity
|
||||||
import com.etesync.syncadapter.ui.ViewCollectionActivity
|
import com.etesync.syncadapter.ui.ViewCollectionActivity
|
||||||
|
import com.etesync.syncadapter.ui.etebase.CollectionActivity
|
||||||
import org.jetbrains.anko.defaultSharedPreferences
|
import org.jetbrains.anko.defaultSharedPreferences
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.FileNotFoundException
|
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 itemMgr: ItemManager
|
||||||
protected lateinit var cachedCollection: CachedCollection
|
protected lateinit var cachedCollection: CachedCollection
|
||||||
|
|
||||||
|
// Sync counters
|
||||||
|
private var syncItemsTotal = 0
|
||||||
|
private var syncItemsDeleted = 0
|
||||||
|
private var syncItemsChanged = 0
|
||||||
|
|
||||||
protected var journal: JournalEntryManager? = null
|
protected var journal: JournalEntryManager? = null
|
||||||
private var _journalEntity: JournalEntity? = null
|
private var _journalEntity: JournalEntity? = null
|
||||||
|
|
||||||
@ -140,6 +146,10 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
|
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
fun performSync() {
|
fun performSync() {
|
||||||
|
syncItemsTotal = 0
|
||||||
|
syncItemsDeleted = 0
|
||||||
|
syncItemsChanged = 0
|
||||||
|
|
||||||
var syncPhase = R.string.sync_phase_prepare
|
var syncPhase = R.string.sync_phase_prepare
|
||||||
try {
|
try {
|
||||||
Logger.log.info("Sync phase: " + context.getString(syncPhase))
|
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() {
|
private fun notifyUserOnSync() {
|
||||||
val changeNotification = context.defaultSharedPreferences.getBoolean(App.CHANGE_NOTIFICATION, true)
|
val changeNotification = context.defaultSharedPreferences.getBoolean(App.CHANGE_NOTIFICATION, true)
|
||||||
val remoteEntries = remoteEntries
|
|
||||||
if ((remoteEntries == null) || remoteEntries.isEmpty() || !changeNotification) {
|
if (!changeNotification || (syncItemsTotal == 0)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val notificationHelper = SyncNotification(context,
|
val notificationHelper = SyncNotification(context,
|
||||||
System.currentTimeMillis().toString(), notificationId())
|
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 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,
|
notificationHelper.notify(syncSuccessfullyTitle,
|
||||||
String.format(context.getString(R.string.sync_successfully_modified),
|
String.format(context.getString(R.string.sync_successfully_modified),
|
||||||
resources.getQuantityString(R.plurals.sync_successfully,
|
resources.getQuantityString(R.plurals.sync_successfully,
|
||||||
remoteEntries!!.size, remoteEntries!!.size)),
|
syncItemsTotal, syncItemsTotal)),
|
||||||
String.format(context.getString(R.string.sync_successfully_modified_full),
|
String.format(context.getString(R.string.sync_successfully_modified_full),
|
||||||
resources.getQuantityString(R.plurals.sync_successfully,
|
resources.getQuantityString(R.plurals.sync_successfully,
|
||||||
added, added),
|
syncItemsChanged, syncItemsChanged),
|
||||||
resources.getQuantityString(R.plurals.sync_successfully,
|
resources.getQuantityString(R.plurals.sync_successfully,
|
||||||
changed, changed),
|
syncItemsDeleted, syncItemsDeleted)),
|
||||||
resources.getQuantityString(R.plurals.sync_successfully,
|
|
||||||
deleted, deleted)),
|
|
||||||
intent)
|
intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,6 +442,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
// Process new vcards from server
|
// Process new vcards from server
|
||||||
val size = items.size
|
val size = items.size
|
||||||
var i = 0
|
var i = 0
|
||||||
|
syncItemsTotal += size
|
||||||
|
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
@ -451,6 +451,12 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
i++
|
i++
|
||||||
Logger.log.info("Processing (${i}/${size}) UID=${item.uid} Etag=${item.etag}")
|
Logger.log.info("Processing (${i}/${size}) UID=${item.uid} Etag=${item.etag}")
|
||||||
|
|
||||||
|
if (item.isDeleted) {
|
||||||
|
syncItemsDeleted++
|
||||||
|
} else {
|
||||||
|
syncItemsChanged++
|
||||||
|
}
|
||||||
|
|
||||||
processItem(item)
|
processItem(item)
|
||||||
persistItem(item)
|
persistItem(item)
|
||||||
}
|
}
|
||||||
@ -491,6 +497,8 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
val strTotal = remoteEntries!!.size.toString()
|
val strTotal = remoteEntries!!.size.toString()
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
|
syncItemsTotal += remoteEntries!!.size
|
||||||
|
|
||||||
for (entry in remoteEntries!!) {
|
for (entry in remoteEntries!!) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
throw InterruptedException()
|
throw InterruptedException()
|
||||||
@ -508,6 +516,13 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
error = e.toString()
|
error = e.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val action = cEntry.action
|
||||||
|
when (action) {
|
||||||
|
ADD -> syncItemsChanged++
|
||||||
|
SyncEntry.Actions.DELETE -> syncItemsDeleted++
|
||||||
|
SyncEntry.Actions.CHANGE -> syncItemsChanged++
|
||||||
|
}
|
||||||
|
|
||||||
persistSyncEntry(entry.uid, cEntry, error)
|
persistSyncEntry(entry.uid, cEntry, error)
|
||||||
|
|
||||||
remoteCTag = entry.uid
|
remoteCTag = entry.uid
|
||||||
|
@ -44,7 +44,7 @@ class TasksSyncManager(
|
|||||||
get() = context.getString(R.string.sync_error_tasks, account.name)
|
get() = context.getString(R.string.sync_error_tasks, account.name)
|
||||||
|
|
||||||
override val syncSuccessfullyTitle: String
|
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)
|
account.name)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -317,7 +317,7 @@
|
|||||||
<string name="sync_successfully_contacts" formatted="false">Kontakter endret (%s)</string>
|
<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_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" 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">Journalen \"%s\" er skrivebeskyttet</string>
|
||||||
<string name="sync_journal_readonly_message">Journalen er skrivebeskyttet, så alle endringene dine (%d) har blitt omgjort.</string>
|
<string name="sync_journal_readonly_message">Journalen er skrivebeskyttet, så alle endringene dine (%d) har blitt omgjort.</string>
|
||||||
<!-- Calendar invites -->
|
<!-- Calendar invites -->
|
||||||
|
@ -287,7 +287,7 @@
|
|||||||
<string name="sync_successfully_calendar" formatted="false">Kalendarz \"%s\" został zmodyfikowany (%s)</string>
|
<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_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" 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 -->
|
<!-- cert4android -->
|
||||||
<string name="certificate_notification_connection_security">EteSync: Bezpieczeństwo połączenia</string>
|
<string name="certificate_notification_connection_security">EteSync: Bezpieczeństwo połączenia</string>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<plurals name="sync_successfully">
|
<plurals name="sync_successfully">
|
||||||
<item quantity="one">%d entry</item>
|
<item quantity="one">%d item</item>
|
||||||
<item quantity="other">%d entries</item>
|
<item quantity="other">%d items</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
</resources>
|
</resources>
|
@ -390,7 +390,7 @@
|
|||||||
<string name="sync_successfully_contacts" formatted="false">Contacts modified (%s)</string>
|
<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_tasks" formatted="false">Tasks \"%s\" modified (%s)</string>
|
||||||
<string name="sync_successfully_modified" formatted="false">%s modified.</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">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>
|
<string name="sync_journal_readonly_message">The journal is read only so all of your changes (%d) have been reverted.</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user