ntfy-android/app/src/main/java/io/heckel/ntfy/data/Repository.kt

48 lines
1.3 KiB
Kotlin
Raw Normal View History

2021-10-27 13:34:09 +13:00
package io.heckel.ntfy.data
2021-10-30 14:13:58 +13:00
import androidx.annotation.WorkerThread
2021-10-27 13:34:09 +13:00
import androidx.lifecycle.LiveData
2021-10-30 14:13:58 +13:00
import androidx.lifecycle.asLiveData
2021-10-27 15:41:19 +13:00
2021-10-30 14:13:58 +13:00
class Repository(private val subscriptionDao: SubscriptionDao) {
fun list(): LiveData<List<Subscription>> {
return subscriptionDao.list().asLiveData()
2021-10-27 15:41:19 +13:00
}
2021-10-30 14:13:58 +13:00
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun get(baseUrl: String, topic: String): Subscription? {
return subscriptionDao.get(baseUrl, topic)
2021-10-27 13:34:09 +13:00
}
2021-10-30 14:13:58 +13:00
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun add(subscription: Subscription) {
subscriptionDao.add(subscription)
2021-10-27 13:34:09 +13:00
}
2021-10-30 14:13:58 +13:00
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun update(subscription: Subscription) {
subscriptionDao.update(subscription)
2021-10-28 09:15:59 +13:00
}
2021-10-27 15:41:19 +13:00
2021-10-30 14:13:58 +13:00
@Suppress("RedundantSuspendModifier")
@WorkerThread
suspend fun remove(subscription: Subscription) {
subscriptionDao.remove(subscription)
2021-10-27 13:34:09 +13:00
}
companion object {
2021-10-27 14:44:12 +13:00
private var instance: Repository? = null
2021-10-27 13:34:09 +13:00
2021-10-30 14:13:58 +13:00
fun getInstance(subscriptionDao: SubscriptionDao): Repository {
2021-10-27 14:44:12 +13:00
return synchronized(Repository::class) {
2021-10-30 14:13:58 +13:00
val newInstance = instance ?: Repository(subscriptionDao)
2021-10-27 13:34:09 +13:00
instance = newInstance
newInstance
}
}
}
}