Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Nov 9, 2024
1 parent 8534a31 commit fc003c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ class LocalAddressBookStore @Inject constructor(
localCollection.readOnly = nowReadOnly

// update raw contacts
val rawContactValues = ContentValues(1)
rawContactValues.put(RawContacts.RAW_CONTACT_IS_READ_ONLY, if (nowReadOnly) 1 else 0)
val rawContactValues = ContentValues(1).apply {
put(RawContacts.RAW_CONTACT_IS_READ_ONLY, if (nowReadOnly) 1 else 0)
}
provider.update(localCollection.rawContactsSyncUri(), rawContactValues, null, null)

// update data rows
val dataValues = ContentValues(1)
dataValues.put(ContactsContract.Data.IS_READ_ONLY, if (nowReadOnly) 1 else 0)
val dataValues = ContentValues(1).apply {
put(ContactsContract.Data.IS_READ_ONLY, if (nowReadOnly) 1 else 0)
}
provider.update(localCollection.syncAdapterURI(ContactsContract.Data.CONTENT_URI), dataValues, null, null)

// update group rows
val groupValues = ContentValues(1)
groupValues.put(Groups.GROUP_IS_READ_ONLY, if (nowReadOnly) 1 else 0)
val groupValues = ContentValues(1).apply {
put(Groups.GROUP_IS_READ_ONLY, if (nowReadOnly) 1 else 0)
}
provider.update(localCollection.groupsSyncUri(), groupValues, null, null)
}

Expand All @@ -145,13 +148,14 @@ class LocalAddressBookStore @Inject constructor(
/**
* Contacts Provider Settings (equal for every address book)
*/
val contactsProviderSettings = ContentValues(2).apply {
// SHOULD_SYNC is just a hint that an account's contacts (the contacts of this local address book) are syncable.
put(ContactsContract.Settings.SHOULD_SYNC, 1)
val contactsProviderSettings
get() = ContentValues(2).apply {
// SHOULD_SYNC is just a hint that an account's contacts (the contacts of this local address book) are syncable.
put(ContactsContract.Settings.SHOULD_SYNC, 1)

// UNGROUPED_VISIBLE is required for making contacts work over Bluetooth (especially with some car systems).
put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1)
}
// UNGROUPED_VISIBLE is required for making contacts work over Bluetooth (especially with some car systems).
put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1)
}

/**
* Determines whether the address book should be set to read-only.
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/at/bitfire/davdroid/util/CompatUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import java.util.logging.Logger
*/
fun AccountManager.setAndVerifyUserData(account: Account, key: String, value: String?) {
for (i in 1..10) {
if (getUserData(account, key) != value)
setUserData(account, key, value)
if (getUserData(account, key) == value)
/* already set / success */
return

setUserData(account, key, value)

// wait a bit because AccountManager access sometimes seems a bit asynchronous
Thread.sleep(100)
}
Logger.getGlobal().warning("AccountManager failed to set $account user data $key := $value")
Expand Down

0 comments on commit fc003c5

Please sign in to comment.