Prevent duplicate accounts when not pro

pull/1086/head
Alex Baker 5 years ago
parent f6844a7c07
commit 9f760c6bfb

@ -28,10 +28,7 @@ class OpenTaskDao @Inject constructor(
private val tasks = Tasks.getContentUri(authority) private val tasks = Tasks.getContentUri(authority)
private val properties = Properties.getContentUri(authority) private val properties = Properties.getContentUri(authority)
suspend fun newAccounts(): List<String> = suspend fun newAccounts(): List<String> = getListsByAccount().newAccounts(caldavDao)
getListsByAccount()
.newAccounts(caldavDao)
.map { it.key }
suspend fun getListsByAccount(): Map<String, List<CaldavCalendar>> = suspend fun getListsByAccount(): Map<String, List<CaldavCalendar>> =
getLists().groupBy { it.account!! } getLists().groupBy { it.account!! }
@ -248,6 +245,8 @@ class OpenTaskDao @Inject constructor(
suspend fun Map<String, List<CaldavCalendar>>.newAccounts(caldavDao: CaldavDao) = suspend fun Map<String, List<CaldavCalendar>>.newAccounts(caldavDao: CaldavDao) =
filterNot { (_, lists) -> caldavDao.anyExist(lists.map { it.url!! }) } filterNot { (_, lists) -> caldavDao.anyExist(lists.map { it.url!! }) }
.map { it.key }
.distinct()
fun Cursor.getString(columnName: String): String? = fun Cursor.getString(columnName: String): String? =
getString(getColumnIndex(columnName)) getString(getColumnIndex(columnName))

@ -58,13 +58,15 @@ class OpenTasksSynchronizer @Inject constructor(
suspend fun sync() { suspend fun sync() {
val lists = openTaskDao.getListsByAccount() val lists = openTaskDao.getListsByAccount()
lists.newAccounts(caldavDao).forEach { (account, _) -> lists.newAccounts(caldavDao)
caldavDao.insert(CaldavAccount().apply { .filter { caldavDao.getAccountByUuid(it) == null }
name = account.split(":")[1] .forEach {
uuid = account caldavDao.insert(CaldavAccount().apply {
accountType = CaldavAccount.TYPE_OPENTASKS name = it.split(":")[1]
}) uuid = it
} accountType = CaldavAccount.TYPE_OPENTASKS
})
}
caldavDao.getAccounts(CaldavAccount.TYPE_OPENTASKS).forEach { account -> caldavDao.getAccounts(CaldavAccount.TYPE_OPENTASKS).forEach { account ->
if (!lists.containsKey(account.uuid)) { if (!lists.containsKey(account.uuid)) {
setError(account, context.getString(R.string.account_not_found)) setError(account, context.getString(R.string.account_not_found))

Loading…
Cancel
Save