From fc003c5fea23b838c7f003a495a7c07560600b5a Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Sat, 9 Nov 2024 12:19:28 +0100 Subject: [PATCH] Minor changes --- .../resource/LocalAddressBookStore.kt | 28 +++++++++++-------- .../at/bitfire/davdroid/util/CompatUtils.kt | 8 ++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalAddressBookStore.kt b/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalAddressBookStore.kt index 739911c0d..a1394389e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalAddressBookStore.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalAddressBookStore.kt @@ -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) } @@ -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. diff --git a/app/src/main/kotlin/at/bitfire/davdroid/util/CompatUtils.kt b/app/src/main/kotlin/at/bitfire/davdroid/util/CompatUtils.kt index 43eb97114..ba98c016b 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/util/CompatUtils.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/util/CompatUtils.kt @@ -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")