Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 18649f71 authored by Sunik Kupfer's avatar Sunik Kupfer Committed by GitHub
Browse files

DmfsTaskList refactoring (#1934)



* DmfsTaskList refactoring

Signed-off-by: default avatarSunik Kupfer <kupfer@bitfire.at>

* Update synctools

Signed-off-by: default avatarSunik Kupfer <kupfer@bitfire.at>

---------

Signed-off-by: default avatarSunik Kupfer <kupfer@bitfire.at>
parent 377a159e
Loading
Loading
Loading
Loading
+19 −16
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ package at.bitfire.davdroid.resource

import androidx.core.content.contentValuesOf
import at.bitfire.ical4android.DmfsTask
import at.bitfire.ical4android.DmfsTaskList
import at.bitfire.synctools.storage.tasks.DmfsTaskList
import org.dmfs.tasks.contract.TaskContract.TaskListColumns
import org.dmfs.tasks.contract.TaskContract.Tasks
import java.util.logging.Level
@@ -43,11 +43,11 @@ class LocalTaskList (
            dmfsTaskList.writeSyncState(state.toString())
        }

    override fun findDeleted() = dmfsTaskList.queryTasks(Tasks._DELETED, null)
    override fun findDeleted() = dmfsTaskList.findTasks(Tasks._DELETED, null)
        .map { LocalTask(it) }

    override fun findDirty(): List<LocalTask> {
        val dmfsTasks = dmfsTaskList.queryTasks(Tasks._DIRTY, null)
        val dmfsTasks = dmfsTaskList.findTasks(Tasks._DIRTY, null)
        for (localTask in dmfsTasks) {
            try {
                val task = requireNotNull(localTask.task)
@@ -64,28 +64,31 @@ class LocalTaskList (
    }

    override fun findByName(name: String) =
        dmfsTaskList.queryTasks("${Tasks._SYNC_ID}=?", arrayOf(name))
        dmfsTaskList.findTasks("${Tasks._SYNC_ID}=?", arrayOf(name))
            .firstOrNull()?.let {
                LocalTask(it)
            }


    override fun markNotDirty(flags: Int): Int {
        val values = contentValuesOf(DmfsTask.COLUMN_FLAGS to flags)
        return dmfsTaskList.provider.update(dmfsTaskList.tasksSyncUri(), values,
    override fun markNotDirty(flags: Int): Int =
        dmfsTaskList.updateTasks(
            contentValuesOf(DmfsTask.COLUMN_FLAGS to flags),
            "${Tasks.LIST_ID}=? AND ${Tasks._DIRTY}=0",
                arrayOf(dmfsTaskList.id.toString()))
    }
            arrayOf(dmfsTaskList.id.toString())
        )

    override fun removeNotDirtyMarked(flags: Int) =
        dmfsTaskList.provider.delete(dmfsTaskList.tasksSyncUri(),
        dmfsTaskList.deleteTasks(
            "${Tasks.LIST_ID}=? AND NOT ${Tasks._DIRTY} AND ${DmfsTask.COLUMN_FLAGS}=?",
                    arrayOf(dmfsTaskList.id.toString(), flags.toString()))
            arrayOf(dmfsTaskList.id.toString(), flags.toString())
        )

    override fun forgetETags() {
        val values = contentValuesOf(DmfsTask.COLUMN_ETAG to null)
        dmfsTaskList.provider.update(dmfsTaskList.tasksSyncUri(), values, "${Tasks.LIST_ID}=?",
                arrayOf(dmfsTaskList.id.toString()))
        dmfsTaskList.updateTasks(
            contentValuesOf(DmfsTask.COLUMN_ETAG to null),
            "${Tasks.LIST_ID}=?",
                arrayOf(dmfsTaskList.id.toString())
        )
    }

}
 No newline at end of file
+8 −8
Original line number Diff line number Diff line
@@ -6,10 +6,8 @@ package at.bitfire.davdroid.resource

import android.accounts.Account
import android.content.ContentProviderClient
import android.content.ContentUris
import android.content.ContentValues
import android.content.Context
import android.net.Uri
import androidx.core.content.contentValuesOf
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.R
@@ -17,8 +15,9 @@ import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.Collection
import at.bitfire.davdroid.settings.AccountSettings
import at.bitfire.davdroid.util.DavUtils.lastSegment
import at.bitfire.ical4android.DmfsTaskList
import at.bitfire.ical4android.TaskProvider
import at.bitfire.synctools.storage.tasks.DmfsTaskList
import at.bitfire.synctools.storage.tasks.DmfsTaskListProvider
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
@@ -62,11 +61,11 @@ class LocalTaskListStore @AssistedInject constructor(
        val account = Account(service.accountName, context.getString(R.string.account_type))

        logger.log(Level.INFO, "Adding local task list", fromCollection)
        val uri = create(account, client, providerName, fromCollection)
        return LocalTaskList(DmfsTaskList.findByID(account, client, providerName, ContentUris.parseId(uri)))
        val dmfsTaskList = create(account, client, providerName, fromCollection)
        return LocalTaskList(dmfsTaskList)
    }

    private fun create(account: Account, provider: ContentProviderClient, providerName: TaskProvider.ProviderName, fromCollection: Collection): Uri {
    private fun create(account: Account, client: ContentProviderClient, providerName: TaskProvider.ProviderName, fromCollection: Collection): DmfsTaskList {
        // If the collection doesn't have a color, use a default color.
        val collectionWithColor = if (fromCollection.color != null)
            fromCollection
@@ -81,7 +80,8 @@ class LocalTaskListStore @AssistedInject constructor(
            put(TaskLists.SYNC_ENABLED, 1)
            put(TaskLists.VISIBLE, 1)
        }
        return DmfsTaskList.create(account, provider, providerName, values)
        val dmfsTaskListProvider = DmfsTaskListProvider(account, client, providerName)
        return dmfsTaskListProvider.createAndGetTaskList(values)
    }

    private fun valuesFromCollectionInfo(info: Collection, withColor: Boolean): ContentValues {
@@ -102,7 +102,7 @@ class LocalTaskListStore @AssistedInject constructor(
    }

    override fun getAll(account: Account, client: ContentProviderClient) =
        DmfsTaskList.find(account, client, providerName, null, null)
        DmfsTaskListProvider(account, client, providerName).findTaskLists()
            .map { LocalTaskList(it) }

    override fun update(client: ContentProviderClient, localCollection: LocalTaskList, fromCollection: Collection) {
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ androidx-test-junit = "1.3.0"
androidx-work = "2.11.0"
bitfire-cert4android = "42d883e958"
bitfire-dav4jvm = "acf8e4ef9b"
bitfire-synctools = "0c84c5acd4"
bitfire-synctools = "25b92ef99a"
compose-accompanist = "0.37.3"
compose-bom = "2026.01.00"
conscrypt = "2.5.3"