Skip to content

Commit

Permalink
Use StringDef to annotate possible service and collection types (#1227)
Browse files Browse the repository at this point in the history
* Add StringDef annotation to collection type param

* Add StringDef annotation to service type param
  • Loading branch information
sunkup authored Jan 9, 2025
1 parent ac8de37 commit 843013a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/at/bitfire/davdroid/db/Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -24,6 +29,8 @@ data class Service(
var id: Long,

var accountName: String,

@ServiceType
var type: String,

var principal: HttpUrl?
Expand Down

0 comments on commit 843013a

Please sign in to comment.