|
@@ -2,14 +2,12 @@ package me.vadik.knigopis.data
|
|
|
|
|
|
|
|
import io.reactivex.Completable
|
|
import io.reactivex.Completable
|
|
|
import io.reactivex.Maybe
|
|
import io.reactivex.Maybe
|
|
|
|
|
+import me.vadik.knigopis.common.CacheKey
|
|
|
import me.vadik.knigopis.common.CommonCache
|
|
import me.vadik.knigopis.common.CommonCache
|
|
|
import me.vadik.knigopis.common.genericType
|
|
import me.vadik.knigopis.common.genericType
|
|
|
import me.vadik.knigopis.model.FinishedBook
|
|
import me.vadik.knigopis.model.FinishedBook
|
|
|
import me.vadik.knigopis.model.PlannedBook
|
|
import me.vadik.knigopis.model.PlannedBook
|
|
|
|
|
|
|
|
-private const val PLANNED_KEY = "planned"
|
|
|
|
|
-private const val FINISHED_KEY = "finished"
|
|
|
|
|
-
|
|
|
|
|
interface BookCache {
|
|
interface BookCache {
|
|
|
|
|
|
|
|
fun getPlannedBooks(): Maybe<List<PlannedBook>>
|
|
fun getPlannedBooks(): Maybe<List<PlannedBook>>
|
|
@@ -25,15 +23,15 @@ interface BookCache {
|
|
|
class BookCacheImpl(private val commonCache: CommonCache) : BookCache {
|
|
class BookCacheImpl(private val commonCache: CommonCache) : BookCache {
|
|
|
|
|
|
|
|
override fun getPlannedBooks(): Maybe<List<PlannedBook>> =
|
|
override fun getPlannedBooks(): Maybe<List<PlannedBook>> =
|
|
|
- commonCache.getFromJson(PLANNED_KEY, genericType<List<PlannedBook>>())
|
|
|
|
|
|
|
+ commonCache.getFromJson(CacheKey.PLANNED_BOOKS, genericType<List<PlannedBook>>())
|
|
|
|
|
|
|
|
override fun getFinishedBooks(): Maybe<List<FinishedBook>> =
|
|
override fun getFinishedBooks(): Maybe<List<FinishedBook>> =
|
|
|
- commonCache.getFromJson(FINISHED_KEY, genericType<List<FinishedBook>>())
|
|
|
|
|
|
|
+ commonCache.getFromJson(CacheKey.FINISHED_BOOKS, genericType<List<FinishedBook>>())
|
|
|
|
|
|
|
|
override fun savePlannedBooks(planned: List<PlannedBook>): Completable =
|
|
override fun savePlannedBooks(planned: List<PlannedBook>): Completable =
|
|
|
- commonCache.saveToJson(PLANNED_KEY, planned)
|
|
|
|
|
|
|
+ commonCache.saveToJson(CacheKey.PLANNED_BOOKS, planned)
|
|
|
|
|
|
|
|
override fun saveFinishedBooks(finished: List<FinishedBook>): Completable =
|
|
override fun saveFinishedBooks(finished: List<FinishedBook>): Completable =
|
|
|
- commonCache.saveToJson(FINISHED_KEY, finished)
|
|
|
|
|
|
|
+ commonCache.saveToJson(CacheKey.FINISHED_BOOKS, finished)
|
|
|
|
|
|
|
|
}
|
|
}
|