diff --git a/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTask.kt b/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTask.kt index 60b19c36d..9c54f04ca 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTask.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTask.kt @@ -14,8 +14,6 @@ import at.bitfire.ical4android.DmfsTaskFactory import at.bitfire.ical4android.DmfsTaskList import at.bitfire.ical4android.Task import at.bitfire.ical4android.TaskProvider -import at.bitfire.synctools.storage.BatchOperation -import at.techbee.jtx.JtxContract import com.google.common.base.MoreObjects import org.dmfs.tasks.contract.TaskContract.Tasks import java.util.Optional @@ -25,51 +23,26 @@ import java.util.Optional */ class LocalTask: DmfsTask, LocalResource { - companion object { - const val COLUMN_ETAG = Tasks.SYNC1 - const val COLUMN_FLAGS = Tasks.SYNC2 - } - override var fileName: String? = null + /** + * Note: Schedule-Tag for tasks is not supported + */ override var scheduleTag: String? = null - override var eTag: String? = null - - override var flags = 0 - private set constructor(taskList: DmfsTaskList<*>, task: Task, fileName: String?, eTag: String?, flags: Int) - : super(taskList, task) { - this.fileName = fileName - this.eTag = eTag - this.flags = flags - } + : super(taskList, task, fileName, eTag, flags) - private constructor(taskList: DmfsTaskList<*>, values: ContentValues): super(taskList) { - id = values.getAsLong(Tasks._ID) - fileName = values.getAsString(Tasks._SYNC_ID) - eTag = values.getAsString(COLUMN_ETAG) - flags = values.getAsInteger(COLUMN_FLAGS) ?: 0 - } - - - /* process LocalTask-specific fields */ - - override fun buildTask(builder: BatchOperation.CpoBuilder, update: Boolean) { - super.buildTask(builder, update) - - builder .withValue(Tasks._SYNC_ID, fileName) - .withValue(COLUMN_ETAG, eTag) - .withValue(COLUMN_FLAGS, flags) - } + private constructor(taskList: DmfsTaskList<*>, values: ContentValues) + : super(taskList, values) /* custom queries */ override fun clearDirty(fileName: Optional, eTag: String?, scheduleTag: String?) { if (scheduleTag != null) - logger.fine("Schedule-Tag for tasks not supported yet, won't save") + logger.fine("Schedule-Tag for tasks not supported, won't save") val values = ContentValues(4) if (fileName.isPresent) @@ -85,9 +58,11 @@ class LocalTask: DmfsTask, LocalResource { } fun update(data: Task, fileName: String?, eTag: String?, scheduleTag: String?, flags: Int) { + if (scheduleTag != null) + logger.fine("Schedule-Tag for tasks not supported, won't save") + this.fileName = fileName this.eTag = eTag - this.scheduleTag = scheduleTag this.flags = flags // processes this.{fileName, eTag, scheduleTag, flags} and resets DIRTY flag @@ -123,7 +98,6 @@ class LocalTask: DmfsTask, LocalResource { .add("id", id) .add("fileName", fileName) .add("eTag", eTag) - .add("scheduleTag", scheduleTag) .add("flags", flags) /*.add("task", try { @@ -152,4 +126,5 @@ class LocalTask: DmfsTask, LocalResource { override fun fromProvider(taskList: DmfsTaskList<*>, values: ContentValues) = LocalTask(taskList, values) } + } \ No newline at end of file diff --git a/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTaskList.kt b/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTaskList.kt index d87753cc7..440804280 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTaskList.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTaskList.kt @@ -6,13 +6,12 @@ package at.bitfire.davdroid.resource import android.accounts.Account import android.content.ContentProviderClient -import android.content.ContentValues import androidx.core.content.contentValuesOf +import at.bitfire.ical4android.DmfsTask import at.bitfire.ical4android.DmfsTaskList import at.bitfire.ical4android.DmfsTaskListFactory import at.bitfire.ical4android.TaskProvider import org.dmfs.tasks.contract.TaskContract.TaskListColumns -import org.dmfs.tasks.contract.TaskContract.TaskLists import org.dmfs.tasks.contract.TaskContract.Tasks import java.util.logging.Level import java.util.logging.Logger @@ -31,11 +30,10 @@ class LocalTaskList private constructor( private val logger = Logger.getGlobal() - private var accessLevel: Int = TaskListColumns.ACCESS_LEVEL_UNDEFINED override val readOnly - get() = - accessLevel != TaskListColumns.ACCESS_LEVEL_UNDEFINED && - accessLevel <= TaskListColumns.ACCESS_LEVEL_READ + get() = accessLevel?.let { + it != TaskListColumns.ACCESS_LEVEL_UNDEFINED && it <= TaskListColumns.ACCESS_LEVEL_READ + } ?: false override val dbCollectionId: Long? get() = syncId?.toLongOrNull() @@ -47,32 +45,11 @@ class LocalTaskList private constructor( get() = name ?: id.toString() override var lastSyncState: SyncState? - get() { - try { - provider.query(taskListSyncUri(), arrayOf(TaskLists.SYNC_VERSION), - null, null, null)?.use { cursor -> - if (cursor.moveToNext()) - cursor.getString(0)?.let { - return SyncState.fromString(it) - } - } - } catch (e: Exception) { - logger.log(Level.WARNING, "Couldn't read sync state", e) - } - return null - } + get() = readSyncState()?.let { SyncState.fromString(it) } set(state) { - val values = contentValuesOf(TaskLists.SYNC_VERSION to state?.toString()) - provider.update(taskListSyncUri(), values, null, null) + writeSyncState(state.toString()) } - - override fun populate(values: ContentValues) { - super.populate(values) - accessLevel = values.getAsInteger(TaskListColumns.ACCESS_LEVEL) - } - - override fun findDeleted() = queryTasks(Tasks._DELETED, null) override fun findDirty(): List { @@ -97,7 +74,7 @@ class LocalTaskList private constructor( override fun markNotDirty(flags: Int): Int { - val values = contentValuesOf(LocalTask.COLUMN_FLAGS to flags) + val values = contentValuesOf(DmfsTask.COLUMN_FLAGS to flags) return provider.update(tasksSyncUri(), values, "${Tasks.LIST_ID}=? AND ${Tasks._DIRTY}=0", arrayOf(id.toString())) @@ -105,11 +82,11 @@ class LocalTaskList private constructor( override fun removeNotDirtyMarked(flags: Int) = provider.delete(tasksSyncUri(), - "${Tasks.LIST_ID}=? AND NOT ${Tasks._DIRTY} AND ${LocalTask.COLUMN_FLAGS}=?", + "${Tasks.LIST_ID}=? AND NOT ${Tasks._DIRTY} AND ${DmfsTask.COLUMN_FLAGS}=?", arrayOf(id.toString(), flags.toString())) override fun forgetETags() { - val values = contentValuesOf(LocalTask.COLUMN_ETAG to null) + val values = contentValuesOf(DmfsTask.COLUMN_ETAG to null) provider.update(tasksSyncUri(), values, "${Tasks.LIST_ID}=?", arrayOf(id.toString())) } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/settings/migration/AccountSettingsMigration10.kt b/app/src/main/kotlin/at/bitfire/davdroid/settings/migration/AccountSettingsMigration10.kt index fb561c799..21bcd9248 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/settings/migration/AccountSettingsMigration10.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/settings/migration/AccountSettingsMigration10.kt @@ -13,6 +13,7 @@ import android.provider.CalendarContract.Reminders import androidx.core.content.ContextCompat import androidx.core.content.contentValuesOf import at.bitfire.davdroid.resource.LocalTask +import at.bitfire.ical4android.DmfsTask import at.bitfire.ical4android.TaskProvider import at.techbee.jtx.JtxContract.asSyncAdapter import dagger.Binds @@ -39,7 +40,7 @@ class AccountSettingsMigration10 @Inject constructor( override fun migrate(account: Account) { TaskProvider.acquire(context, TaskProvider.ProviderName.OpenTasks)?.use { provider -> val tasksUri = provider.tasksUri().asSyncAdapter(account) - val emptyETag = contentValuesOf(LocalTask.COLUMN_ETAG to null) + val emptyETag = contentValuesOf(DmfsTask.COLUMN_ETAG to null) provider.client.update(tasksUri, emptyETag, "${TaskContract.Tasks._DIRTY}=0 AND ${TaskContract.Tasks._DELETED}=0", null) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4694197db..c2e2cd37a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,7 +20,7 @@ androidx-test-junit = "1.3.0" androidx-work = "2.11.0" bitfire-cert4android = "42d883e958" bitfire-dav4jvm = "acd9bca096" -bitfire-synctools = "017187c6d8" +bitfire-synctools = "6ff0b64485" compose-accompanist = "0.37.3" compose-bom = "2025.11.01" conscrypt = "2.5.3"