Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bitfireAT/davx5-ose.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunik Kupfer <kupfer@bitfire.at>2022-10-13 17:34:47 +0300
committerRicki Hirner <hirner@bitfire.at>2022-10-21 14:41:21 +0300
commit9bd564b2c6f461f05ae6282f2fae47cc8d60c162 (patch)
tree5edde270076ab2e16e8ada57c417602ce5059525
parentbec9f8bcfb9acec55138c078f7bcd6293615c980 (diff)
fix crash when accounts vanish (closes bitfireAT/davx5#140) (bitfireAT/davx5#148)
-rw-r--r--app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.kt17
1 files changed, 15 insertions, 2 deletions
diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.kt b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.kt
index c49a1cbd..7e4e28f0 100644
--- a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.kt
+++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.kt
@@ -75,13 +75,19 @@ open class LocalAddressBook(
return addressBook
}
+ /**
+ * Finds and returns all the local address books belonging to a given main account
+ *
+ * @param mainAccount the main account to use
+ * @return list of [mainAccount]'s address books
+ */
fun findAll(context: Context, provider: ContentProviderClient?, mainAccount: Account) = AccountManager.get(context)
.getAccountsByType(context.getString(R.string.account_type_address_book))
.map { LocalAddressBook(context, it, provider) }
.filter {
try {
it.mainAccount == mainAccount
- } catch(e: IllegalStateException) {
+ } catch(e: IllegalArgumentException) {
false
}
}
@@ -110,6 +116,13 @@ open class LocalAddressBook(
return bundle
}
+ /**
+ * Finds and returns the main account of the given address book's account (sub-account)
+ *
+ * @param account the address book account to find the main account for
+ * @return the associated main account
+ * @throws IllegalArgumentException if the given account is not a address book account or does not have a main account
+ */
fun mainAccount(context: Context, account: Account): Account =
if (account.type == context.getString(R.string.account_type_address_book)) {
val manager = AccountManager.get(context)
@@ -144,7 +157,7 @@ open class LocalAddressBook(
private var _mainAccount: Account? = null
/**
- * The associated main account which this address book accounts belongs to.
+ * The associated main account which this address book's accounts belong to.
*
* @throws IllegalArgumentException when [account] is not an address book account or when no main account is assigned
*/