Skip to content

Commit 4a654f9

Browse files
committed
Add read-only state access to LocalTaskList
1 parent f7c9e88 commit 4a654f9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.annotation.SuppressLint
99
import android.content.ContentValues
1010
import android.content.Context
1111
import android.net.Uri
12+
import androidx.core.database.getIntOrNull
1213
import at.bitfire.davdroid.Constants
1314
import at.bitfire.davdroid.db.Collection
1415
import at.bitfire.davdroid.db.SyncState
@@ -69,8 +70,22 @@ class LocalTaskList private constructor(
6970
}
7071

7172
override var readOnly: Boolean
72-
get() = TODO("Not yet implemented")
73-
set(value) {}
73+
get() = provider.client.query(
74+
taskListSyncUri(), arrayOf(TaskListColumns.ACCESS_LEVEL),
75+
null, null, null
76+
)?.use { cursor ->
77+
if (cursor.moveToNext())
78+
return cursor.getIntOrNull(0) == TaskListColumns.ACCESS_LEVEL_READ
79+
else
80+
false
81+
} == true
82+
set(readOnly) {
83+
val values = ContentValues().apply { put(
84+
TaskListColumns.ACCESS_LEVEL,
85+
if (readOnly) TaskListColumns.ACCESS_LEVEL_READ else TaskListColumns.ACCESS_LEVEL_OWNER
86+
)}
87+
provider.client.update(taskListSyncUri(), values, null, null)
88+
}
7489

7590
override val tag: String
7691
get() = "tasks-${account.name}-$id"

0 commit comments

Comments
 (0)