From 843013a0f0820497cf73799d59e144e69dcb7632 Mon Sep 17 00:00:00 2001 From: Sunik Kupfer Date: Thu, 9 Jan 2025 12:08:11 +0100 Subject: [PATCH] Use StringDef to annotate possible service and collection types (#1227) * Add StringDef annotation to collection type param * Add StringDef annotation to service type param --- .../main/kotlin/at/bitfire/davdroid/db/Collection.kt | 12 +++++++++++- .../main/kotlin/at/bitfire/davdroid/db/Service.kt | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt b/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt index e79668823..1fbc0269f 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt @@ -4,6 +4,7 @@ package at.bitfire.davdroid.db +import androidx.annotation.StringDef import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.ForeignKey @@ -29,6 +30,14 @@ import at.bitfire.ical4android.util.DateUtils import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +@Retention(AnnotationRetention.SOURCE) +@StringDef( + Collection.TYPE_ADDRESSBOOK, + Collection.TYPE_CALENDAR, + Collection.TYPE_WEBCAL +) +annotation class CollectionType + @Entity(tableName = "collection", foreignKeys = [ ForeignKey(entity = Service::class, parentColumns = arrayOf("id"), childColumns = arrayOf("serviceId"), onDelete = ForeignKey.CASCADE), @@ -67,7 +76,8 @@ data class Collection( /** * Type of service. CalDAV or CardDAV */ - var type: String, + @CollectionType + val type: String, /** * Address where this collection lives - with trailing slash diff --git a/app/src/main/kotlin/at/bitfire/davdroid/db/Service.kt b/app/src/main/kotlin/at/bitfire/davdroid/db/Service.kt index 074d7f84d..66837d951 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/db/Service.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/db/Service.kt @@ -4,11 +4,16 @@ package at.bitfire.davdroid.db +import androidx.annotation.StringDef import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey import okhttp3.HttpUrl +@Retention(AnnotationRetention.SOURCE) +@StringDef(Service.TYPE_CALDAV, Service.TYPE_CARDDAV) +annotation class ServiceType + /** * A service entity. * @@ -24,6 +29,8 @@ data class Service( var id: Long, var accountName: String, + + @ServiceType var type: String, var principal: HttpUrl?