|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package org.koitharu.kotatsu.domain.history
|
|
|
|
package org.koitharu.kotatsu.domain.history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.room.withTransaction
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import org.koin.core.KoinComponent
|
|
|
|
import org.koin.core.KoinComponent
|
|
|
|
@ -24,19 +25,22 @@ class HistoryRepository : KoinComponent {
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Float) {
|
|
|
|
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Float) {
|
|
|
|
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
|
|
|
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
|
|
|
db.tagsDao.upsert(tags)
|
|
|
|
db.withTransaction {
|
|
|
|
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
|
|
|
db.tagsDao.upsert(tags)
|
|
|
|
if (db.historyDao.upsert(
|
|
|
|
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
|
|
|
HistoryEntity(
|
|
|
|
if (db.historyDao.upsert(
|
|
|
|
mangaId = manga.id,
|
|
|
|
HistoryEntity(
|
|
|
|
createdAt = System.currentTimeMillis(),
|
|
|
|
mangaId = manga.id,
|
|
|
|
updatedAt = System.currentTimeMillis(),
|
|
|
|
createdAt = System.currentTimeMillis(),
|
|
|
|
chapterId = chapterId,
|
|
|
|
updatedAt = System.currentTimeMillis(),
|
|
|
|
page = page,
|
|
|
|
chapterId = chapterId,
|
|
|
|
scroll = scroll
|
|
|
|
page = page,
|
|
|
|
)
|
|
|
|
scroll = scroll
|
|
|
|
)) {
|
|
|
|
)
|
|
|
|
TrackingRepository().insertOrNothing(manga)
|
|
|
|
)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
TrackingRepository().insertOrNothing(manga)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notifyHistoryChanged()
|
|
|
|
notifyHistoryChanged()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|