Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DB StringDefs also in DAOs and methods where they are used #1252

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/src/main/kotlin/at/bitfire/davdroid/db/CollectionDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ interface CollectionDao {
fun getByServiceAndHomeset(serviceId: Long, homeSetId: Long?): List<Collection>

@Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type ORDER BY displayName COLLATE NOCASE, url COLLATE NOCASE")
fun getByServiceAndType(serviceId: Long, type: String): List<Collection>
fun getByServiceAndType(serviceId: Long, @CollectionType type: String): List<Collection>

@Query("SELECT * FROM collection WHERE pushTopic=:topic AND sync")
fun getSyncableByPushTopic(topic: String): Collection?

@Query("SELECT COUNT(*) FROM collection WHERE serviceId=:serviceId AND type=:type")
suspend fun anyOfType(serviceId: Long, type: String): Boolean
suspend fun anyOfType(serviceId: Long, @CollectionType type: String): Boolean

@Query("SELECT COUNT(*) FROM collection WHERE supportsWebPush AND pushTopic IS NOT NULL")
suspend fun anyPushCapable(): Boolean
Expand All @@ -48,13 +48,13 @@ interface CollectionDao {
*/
@Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type " +
"AND (supportsVTODO OR supportsVEVENT OR supportsVJOURNAL OR (supportsVEVENT IS NULL AND supportsVTODO IS NULL AND supportsVJOURNAL IS NULL)) ORDER BY displayName COLLATE NOCASE, URL COLLATE NOCASE")
fun pageByServiceAndType(serviceId: Long, type: String): PagingSource<Int, Collection>
fun pageByServiceAndType(serviceId: Long, @CollectionType type: String): PagingSource<Int, Collection>

@Query("SELECT * FROM collection WHERE serviceId=:serviceId AND sync")
fun getByServiceAndSync(serviceId: Long): List<Collection>

@Query("SELECT collection.* FROM collection, homeset WHERE collection.serviceId=:serviceId AND type=:type AND homeSetId=homeset.id AND homeset.personal ORDER BY collection.displayName COLLATE NOCASE, collection.url COLLATE NOCASE")
fun pagePersonalByServiceAndType(serviceId: Long, type: String): PagingSource<Int, Collection>
fun pagePersonalByServiceAndType(serviceId: Long, @CollectionType type: String): PagingSource<Int, Collection>

@Query("SELECT * FROM collection WHERE serviceId=:serviceId AND url=:url")
fun getByServiceAndUrl(serviceId: Long, url: String): Collection?
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/at/bitfire/davdroid/db/HomeSetDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface HomeSetDao {
fun getByService(serviceId: Long): List<HomeSet>

@Query("SELECT * FROM homeset WHERE serviceId=(SELECT id FROM service WHERE accountName=:accountName AND type=:serviceType) AND privBind ORDER BY displayName, url COLLATE NOCASE")
fun getBindableByAccountAndServiceTypeFlow(accountName: String, serviceType: String): Flow<List<HomeSet>>
fun getBindableByAccountAndServiceTypeFlow(accountName: String, @ServiceType serviceType: String): Flow<List<HomeSet>>

@Query("SELECT * FROM homeset WHERE serviceId=:serviceId AND privBind")
fun getBindableByServiceFlow(serviceId: Long): Flow<List<HomeSet>>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/at/bitfire/davdroid/db/ServiceDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import kotlinx.coroutines.flow.Flow
interface ServiceDao {

@Query("SELECT * FROM service WHERE accountName=:accountName AND type=:type")
fun getByAccountAndType(accountName: String, type: String): Service?
fun getByAccountAndType(accountName: String, @ServiceType type: String): Service?

@Query("SELECT * FROM service WHERE accountName=:accountName AND type=:type")
fun getByAccountAndTypeFlow(accountName: String, type: String): Flow<Service?>
fun getByAccountAndTypeFlow(accountName: String, @ServiceType type: String): Flow<Service?>

@Query("SELECT id FROM service WHERE accountName=:accountName")
suspend fun getIdsByAccountAsync(accountName: String): List<Long>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.Credentials
import at.bitfire.davdroid.db.HomeSet
import at.bitfire.davdroid.db.Service
import at.bitfire.davdroid.db.ServiceType
import at.bitfire.davdroid.resource.LocalAddressBookStore
import at.bitfire.davdroid.resource.LocalCalendarStore
import at.bitfire.davdroid.servicedetection.DavResourceFinder
Expand Down Expand Up @@ -247,7 +248,7 @@ class AccountRepository @Inject constructor(

// helpers

private fun insertService(accountName: String, type: String, info: DavResourceFinder.Configuration.ServiceInfo): Long {
private fun insertService(accountName: String, @ServiceType type: String, info: DavResourceFinder.Configuration.ServiceInfo): Long {
// insert service
val service = Service(0, accountName, type, info.principal)
val serviceId = serviceRepository.insertOrReplace(service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import at.bitfire.dav4jvm.property.webdav.ResourceType
import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.Collection
import at.bitfire.davdroid.db.CollectionType
import at.bitfire.davdroid.db.HomeSet
import at.bitfire.davdroid.network.HttpClient
import at.bitfire.davdroid.servicedetection.RefreshCollectionsWorker
Expand Down Expand Up @@ -248,10 +249,10 @@ class DavCollectionRepository @Inject constructor(
notifyOnChangeListeners()
}

fun pageByServiceAndType(serviceId: Long, type: String) =
fun pageByServiceAndType(serviceId: Long, @CollectionType type: String) =
dao.pageByServiceAndType(serviceId, type)

fun pagePersonalByServiceAndType(serviceId: Long, type: String) =
fun pagePersonalByServiceAndType(serviceId: Long, @CollectionType type: String) =
dao.pagePersonalByServiceAndType(serviceId, type)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package at.bitfire.davdroid.repository

import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.Service
import at.bitfire.davdroid.db.ServiceType
import javax.inject.Inject

class DavServiceRepository @Inject constructor(
Expand All @@ -19,7 +20,7 @@ class DavServiceRepository @Inject constructor(

fun get(id: Long): Service? = dao.get(id)

fun getByAccountAndType(name: String, serviceType: String): Service? =
fun getByAccountAndType(name: String, @ServiceType serviceType: String): Service? =
dao.getByAccountAndType(name, serviceType)

fun getCalDavServiceFlow(accountName: String) =
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/at/bitfire/davdroid/sync/Syncer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.os.DeadObjectException
import androidx.annotation.VisibleForTesting
import at.bitfire.davdroid.InvalidAccountException
import at.bitfire.davdroid.db.Collection
import at.bitfire.davdroid.db.ServiceType
import at.bitfire.davdroid.network.HttpClient
import at.bitfire.davdroid.repository.DavCollectionRepository
import at.bitfire.davdroid.repository.DavServiceRepository
Expand Down Expand Up @@ -82,6 +83,7 @@ abstract class Syncer<StoreType: LocalDataStore<CollectionType>, CollectionType:
lateinit var serviceRepository: DavServiceRepository

abstract val authority: String
@ServiceType
abstract val serviceType: String

val accountSettings by lazy { accountSettingsFactory.create(account) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import at.bitfire.davdroid.db.Collection
import at.bitfire.davdroid.db.CollectionType
import at.bitfire.davdroid.db.Service
import at.bitfire.davdroid.repository.DavCollectionRepository
import at.bitfire.davdroid.settings.Settings
Expand Down Expand Up @@ -41,7 +42,7 @@ class GetServiceCollectionPagerUseCase @Inject constructor(
@OptIn(ExperimentalCoroutinesApi::class)
operator fun invoke(
serviceFlow: Flow<Service?>,
collectionType: String,
@CollectionType collectionType: String,
showOnlyPersonalFlow: Flow<Boolean>
): Flow<PagingData<Collection>> =
combine(serviceFlow, showOnlyPersonalFlow, forceReadOnlyAddressBooksFlow) { service, onlyPersonal, forceReadOnlyAddressBooks ->
Expand Down
Loading