Commit 3c00520a authored by Ricki Hirner's avatar Ricki Hirner 🐑

Notify on read-only address books

* notify when a read-only address book is selected for synchronization
* notify when local changes have been discarded during sync
parent d20aa562
......@@ -21,10 +21,7 @@ import at.bitfire.dav4android.DavAddressBook
import at.bitfire.dav4android.DavResource
import at.bitfire.dav4android.exception.DavException
import at.bitfire.dav4android.property.*
import at.bitfire.davdroid.AccountSettings
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.HttpClient
import at.bitfire.davdroid.R
import at.bitfire.davdroid.*
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.resource.LocalAddressBook
import at.bitfire.davdroid.resource.LocalContact
......@@ -92,6 +89,7 @@ class ContactsSyncManager(
private val MAX_MULTIGET = 10
private var readOnly = false
var numDiscarded = 0
private var hasVCard4 = false
private lateinit var groupMethod: GroupMethod
......@@ -154,7 +152,7 @@ class ContactsSyncManager(
for (contact in localAddressBook.getDeletedContacts()) {
Logger.log.warning("Restoring locally deleted contact (read-only address book!)")
notifyDiscardedChange(contact)
notifyDiscardedChange()
contact.resetDeleted()
}
} else
......@@ -170,7 +168,7 @@ class ContactsSyncManager(
for (contact in localAddressBook.getDirtyContacts()) {
Logger.log.warning("Resetting locally modified contact to ETag=null (read-only address book!)")
notifyDiscardedChange(contact)
notifyDiscardedChange()
contact.clearDirty(null)
}
......@@ -219,17 +217,19 @@ class ContactsSyncManager(
}
}
private fun notifyDiscardedChange(contact: LocalContact) {
private fun notifyDiscardedChange() {
val notification = NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_error_light)
// TODO .setGroup()
.setContentTitle(contact.contact!!.displayName)
.setContentText("Local contact change has been discarded")
.setSubText("Read-only address book")
.setSmallIcon(R.drawable.ic_delete_light)
.setLargeIcon(App.getLauncherBitmap(context))
.setContentTitle(context.getString(R.string.sync_contacts_read_only_address_book))
.setContentText(context.resources.getQuantityString(R.plurals.sync_contacts_local_contact_changes_discarded, ++numDiscarded, numDiscarded))
.setSubText(account.name)
.setCategory(NotificationCompat.CATEGORY_ERROR)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setLocalOnly(true)
.setAutoCancel(true)
.build()
NotificationManagerCompat.from(context).notify(contact.fileName, 0, notification)
NotificationManagerCompat.from(context).notify("discarded_${account.name}", 0, notification)
}
override fun prepareUpload(resource: LocalResource): RequestBody {
......
......@@ -71,7 +71,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
}
lateinit var account: Account
var accountInfo: AccountInfo? = null
private var accountInfo: AccountInfo? = null
override fun onCreate(savedInstanceState: Bundle?) {
......@@ -202,10 +202,13 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
db.setTransactionSuccessful()
db.endTransaction()
info.selected = nowChecked
adapter.notifyDataSetChanged()
}
info.selected = nowChecked
adapter.notifyDataSetChanged()
if (nowChecked && info.type == CollectionInfo.Type.ADDRESS_BOOK && info.readOnly)
Snackbar.make(parent, R.string.account_read_only_address_book_selected, Snackbar.LENGTH_LONG).show()
}
private val onItemLongClickListener = AdapterView.OnItemLongClickListener { parent, view, position, _ ->
......
<!--
~ Copyright © Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
......@@ -121,6 +121,7 @@
<string name="account_create_new_calendar">Create new calendar</string>
<string name="account_no_webcal_handler_found">No Webcal-capable app found</string>
<string name="account_install_icsdroid">Install ICSdroid</string>
<string name="account_read_only_address_book_selected">Read-only address book – local changes will be discarded!</string>
<!-- PermissionsActivity -->
<string name="permissions_title">DAVdroid permissions</string>
......@@ -255,9 +256,14 @@
<string name="exception_ioexception">An I/O error has occurred.</string>
<string name="exception_show_details">Show details</string>
<!-- sync errors and DebugInfoActivity -->
<!-- sync adapters and DebugInfoActivity -->
<string name="authority_log_provider">at.bitfire.davdroid.log</string>
<string name="debug_info_title">Debug info</string>
<string name="sync_contacts_read_only_address_book">Read-only address book</string>
<plurals name="sync_contacts_local_contact_changes_discarded">
<item quantity="one">Local contact change discarded</item>
<item quantity="other">%d local contact changes discarded</item>
</plurals>
<string name="sync_error_permissions">DAVdroid permissions</string>
<string name="sync_error_permissions_text">Additional permissions required</string>
<string name="sync_error_calendar">Calendar synchronization failed (%s)</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment