From 3f5956fd3de403cd2c8c65a0296c201654940650 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Wed, 4 May 2022 18:11:33 +0530 Subject: [PATCH] AccountManager: on upgrade remove recently contacted address book --- .../e/accountmanager/settings/AccountSettings.kt | 11 +++++++++++ .../syncadapter/EeloAddressBooksSyncAdapterService.kt | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/accountmanager/settings/AccountSettings.kt b/app/src/main/java/foundation/e/accountmanager/settings/AccountSettings.kt index 646872ccb..db81d336f 100644 --- a/app/src/main/java/foundation/e/accountmanager/settings/AccountSettings.kt +++ b/app/src/main/java/foundation/e/accountmanager/settings/AccountSettings.kt @@ -98,6 +98,8 @@ class AccountSettings( const val SYNC_INTERVAL_MANUALLY = -1L + const val CONTACTS_APP_INTERACTION = "z-app-generated--contactsinteraction--recent/" + fun initialUserData(credentials: Credentials, baseURL: String?): Bundle { val bundle = Bundle(2) bundle.putString(KEY_SETTINGS_VERSION, CURRENT_VERSION.toString()) @@ -316,6 +318,15 @@ class AccountSettings( @Suppress("unused","FunctionName") private fun update_10_11() { setGroupMethod(GroupMethod.CATEGORIES) + val db = AppDatabase.getInstance(context) + val service = db.serviceDao().getByAccountAndType(account.name, Service.TYPE_CARDDAV) + if (service != null) { + for (collection in db.collectionDao().getByServiceAndSync(service.id)) { + if(collection.url.toString().contains(CONTACTS_APP_INTERACTION)) { + db.collectionDao().delete(collection) + } + } + } } @Suppress("unused","FunctionName") diff --git a/app/src/main/java/foundation/e/accountmanager/syncadapter/EeloAddressBooksSyncAdapterService.kt b/app/src/main/java/foundation/e/accountmanager/syncadapter/EeloAddressBooksSyncAdapterService.kt index 54033ed07..d0dfb97e9 100644 --- a/app/src/main/java/foundation/e/accountmanager/syncadapter/EeloAddressBooksSyncAdapterService.kt +++ b/app/src/main/java/foundation/e/accountmanager/syncadapter/EeloAddressBooksSyncAdapterService.kt @@ -66,8 +66,12 @@ class EeloAddressBooksSyncAdapterService : SyncAdapterService() { val remoteAddressBooks = mutableMapOf() if (service != null) - for (collection in db.collectionDao().getByServiceAndSync(service.id)) + for (collection in db.collectionDao().getByServiceAndSync(service.id)) { + if(collection.url.toString().contains(AccountSettings.CONTACTS_APP_INTERACTION)) { + db.collectionDao().delete(collection) + } remoteAddressBooks[collection.url] = collection + } if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED) { if (remoteAddressBooks.isEmpty()) -- GitLab