Skip to content

Commit b354bfe

Browse files
authored
LocalTask: Don't subclass DmfsTask (#1862)
* LocalTask: Don't subclass DmfsTask Signed-off-by: Sunik Kupfer <kupfer@bitfire.at> * Adapt usages Signed-off-by: Sunik Kupfer <kupfer@bitfire.at> * Update synctools Signed-off-by: Sunik Kupfer <kupfer@bitfire.at> --------- Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
1 parent 29240ea commit b354bfe

File tree

5 files changed

+46
-49
lines changed

5 files changed

+46
-49
lines changed

app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTask.kt

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,49 @@ import android.content.Context
1010
import android.net.Uri
1111
import androidx.core.content.contentValuesOf
1212
import at.bitfire.ical4android.DmfsTask
13-
import at.bitfire.ical4android.DmfsTaskFactory
14-
import at.bitfire.ical4android.DmfsTaskList
1513
import at.bitfire.ical4android.Task
1614
import at.bitfire.ical4android.TaskProvider
1715
import com.google.common.base.MoreObjects
1816
import org.dmfs.tasks.contract.TaskContract.Tasks
1917
import java.util.Optional
18+
import java.util.logging.Logger
2019

2120
/**
2221
* Represents a Dmfs Task (OpenTasks and Tasks.org) entry
2322
*/
24-
class LocalTask: DmfsTask, LocalResource {
23+
class LocalTask(
24+
val dmfsTask: DmfsTask
25+
): LocalResource {
26+
27+
val logger: Logger = Logger.getLogger(javaClass.name)
28+
29+
30+
// LocalResource implementation
31+
32+
override val id: Long?
33+
get() = dmfsTask.id
2534

2635
override var fileName: String?
27-
get() = syncId
28-
set(value) { syncId = value }
36+
get() = dmfsTask.syncId
37+
set(value) { dmfsTask.syncId = value }
38+
39+
override var eTag: String?
40+
get() = dmfsTask.eTag
41+
set(value) { dmfsTask.eTag = value }
2942

3043
/**
3144
* Note: Schedule-Tag for tasks is not supported
3245
*/
3346
override var scheduleTag: String? = null
3447

48+
override val flags: Int
49+
get() = dmfsTask.flags
3550

36-
constructor(taskList: DmfsTaskList<*>, task: Task, fileName: String?, eTag: String?, flags: Int)
37-
: super(taskList, task, fileName, eTag, flags)
51+
fun add() = dmfsTask.add()
3852

39-
private constructor(taskList: DmfsTaskList<*>, values: ContentValues)
40-
: super(taskList, values)
53+
fun update(data: Task) = dmfsTask.update(data)
4154

42-
43-
/* custom queries */
55+
fun delete() = dmfsTask.delete()
4456

4557
override fun clearDirty(fileName: Optional<String>, eTag: String?, scheduleTag: String?) {
4658
if (scheduleTag != null)
@@ -49,46 +61,33 @@ class LocalTask: DmfsTask, LocalResource {
4961
val values = ContentValues(4)
5062
if (fileName.isPresent)
5163
values.put(Tasks._SYNC_ID, fileName.get())
52-
values.put(COLUMN_ETAG, eTag)
53-
values.put(Tasks.SYNC_VERSION, task!!.sequence)
64+
values.put(DmfsTask.COLUMN_ETAG, eTag)
65+
values.put(Tasks.SYNC_VERSION, dmfsTask.task!!.sequence)
5466
values.put(Tasks._DIRTY, 0)
55-
taskList.provider.update(taskSyncURI(), values, null, null)
67+
dmfsTask.update(values)
5668

5769
if (fileName.isPresent)
5870
this.fileName = fileName.get()
5971
this.eTag = eTag
6072
}
6173

62-
fun update(data: Task, fileName: String?, eTag: String?, scheduleTag: String?, flags: Int) {
63-
if (scheduleTag != null)
64-
logger.fine("Schedule-Tag for tasks not supported, won't save")
65-
66-
this.fileName = fileName
67-
this.eTag = eTag
68-
this.flags = flags
69-
70-
// processes this.{fileName, eTag, scheduleTag, flags} and resets DIRTY flag
71-
update(data)
72-
}
73-
7474
override fun updateFlags(flags: Int) {
7575
if (id != null) {
76-
val values = contentValuesOf(COLUMN_FLAGS to flags)
77-
taskList.provider.update(taskSyncURI(), values, null, null)
76+
val values = contentValuesOf(DmfsTask.COLUMN_FLAGS to flags)
77+
dmfsTask.update(values)
7878
}
79-
80-
this.flags = flags
79+
dmfsTask.flags = flags
8180
}
8281

8382
override fun updateSequence(sequence: Int) = throw NotImplementedError()
8483

8584
override fun updateUid(uid: String) {
8685
val values = contentValuesOf(Tasks._UID to uid)
87-
taskList.provider.update(taskSyncURI(), values, null, null)
86+
dmfsTask.update(values)
8887
}
8988

9089
override fun deleteLocal() {
91-
delete()
90+
dmfsTask.delete()
9291
}
9392

9493
override fun resetDeleted() {
@@ -112,9 +111,9 @@ class LocalTask: DmfsTask, LocalResource {
112111
.toString()
113112

114113
override fun getViewUri(context: Context): Uri? = id?.let { id ->
115-
when (taskList.providerName) {
114+
when (dmfsTask.taskList.providerName) {
116115
TaskProvider.ProviderName.OpenTasks -> {
117-
val contentUri = Tasks.getContentUri(taskList.providerName.authority)
116+
val contentUri = Tasks.getContentUri(dmfsTask.taskList.providerName.authority)
118117
ContentUris.withAppendedId(contentUri, id)
119118
}
120119
// Tasks.org can't handle view content URIs (missing intent-filter)
@@ -123,10 +122,4 @@ class LocalTask: DmfsTask, LocalResource {
123122
}
124123
}
125124

126-
127-
object Factory: DmfsTaskFactory<LocalTask> {
128-
override fun fromProvider(taskList: DmfsTaskList<*>, values: ContentValues) =
129-
LocalTask(taskList, values)
130-
}
131-
132125
}

app/src/main/kotlin/at/bitfire/davdroid/resource/LocalTaskList.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LocalTaskList private constructor(
2626
provider: ContentProviderClient,
2727
providerName: TaskProvider.ProviderName,
2828
id: Long
29-
): DmfsTaskList<LocalTask>(account, provider, providerName, LocalTask.Factory, id), LocalCollection<LocalTask> {
29+
): DmfsTaskList(account, provider, providerName, id), LocalCollection<LocalTask> {
3030

3131
private val logger = Logger.getGlobal()
3232

@@ -51,10 +51,11 @@ class LocalTaskList private constructor(
5151
}
5252

5353
override fun findDeleted() = queryTasks(Tasks._DELETED, null)
54+
.map { LocalTask(it) }
5455

5556
override fun findDirty(): List<LocalTask> {
56-
val tasks = queryTasks(Tasks._DIRTY, null)
57-
for (localTask in tasks) {
57+
val dmfsTasks = queryTasks(Tasks._DIRTY, null)
58+
for (localTask in dmfsTasks) {
5859
try {
5960
val task = requireNotNull(localTask.task)
6061
val sequence = task.sequence
@@ -66,11 +67,14 @@ class LocalTaskList private constructor(
6667
logger.log(Level.WARNING, "Couldn't check/increase sequence", e)
6768
}
6869
}
69-
return tasks
70+
return dmfsTasks.map { LocalTask(it) }
7071
}
7172

7273
override fun findByName(name: String) =
73-
queryTasks("${Tasks._SYNC_ID}=?", arrayOf(name)).firstOrNull()
74+
queryTasks("${Tasks._SYNC_ID}=?", arrayOf(name))
75+
.firstOrNull()?.let {
76+
LocalTask(it)
77+
}
7478

7579

7680
override fun markNotDirty(flags: Int): Int {

app/src/main/kotlin/at/bitfire/davdroid/settings/migration/AccountSettingsMigration10.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import android.provider.CalendarContract.Calendars
1212
import android.provider.CalendarContract.Reminders
1313
import androidx.core.content.ContextCompat
1414
import androidx.core.content.contentValuesOf
15-
import at.bitfire.davdroid.resource.LocalTask
1615
import at.bitfire.ical4android.DmfsTask
1716
import at.bitfire.ical4android.TaskProvider
1817
import at.techbee.jtx.JtxContract.asSyncAdapter

app/src/main/kotlin/at/bitfire/davdroid/sync/TasksSyncManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import at.bitfire.davdroid.resource.LocalTaskList
2525
import at.bitfire.davdroid.resource.SyncState
2626
import at.bitfire.davdroid.util.DavUtils
2727
import at.bitfire.davdroid.util.DavUtils.lastSegment
28+
import at.bitfire.ical4android.DmfsTask
2829
import at.bitfire.ical4android.Task
2930
import at.bitfire.synctools.exception.InvalidICalendarException
3031
import dagger.assisted.Assisted
@@ -103,7 +104,7 @@ class TasksSyncManager @AssistedInject constructor(
103104
override fun syncAlgorithm() = SyncAlgorithm.PROPFIND_REPORT
104105

105106
override fun generateUpload(resource: LocalTask): GeneratedResource {
106-
val task = requireNotNull(resource.task)
107+
val task = requireNotNull(resource.dmfsTask.task)
107108
logger.log(Level.FINE, "Preparing upload of task ${resource.id}", task)
108109

109110
// get/create UID
@@ -191,7 +192,7 @@ class TasksSyncManager @AssistedInject constructor(
191192
local.update(newData)
192193
} else {
193194
logger.log(Level.INFO, "Adding $fileName to local task list", newData)
194-
val newLocal = LocalTask(localCollection, newData, fileName, eTag, LocalResource.FLAG_REMOTELY_PRESENT)
195+
val newLocal = LocalTask(DmfsTask(localCollection, newData, fileName, eTag, LocalResource.FLAG_REMOTELY_PRESENT))
195196
SyncException.wrapWithLocalResource(newLocal) {
196197
newLocal.add()
197198
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ androidx-test-junit = "1.3.0"
2020
androidx-work = "2.11.0"
2121
bitfire-cert4android = "42d883e958"
2222
bitfire-dav4jvm = "de16b12343"
23-
bitfire-synctools = "5fb54ec88c"
23+
bitfire-synctools = "de78892b5c"
2424
compose-accompanist = "0.37.3"
2525
compose-bom = "2025.11.01"
2626
conscrypt = "2.5.3"

0 commit comments

Comments
 (0)