Merge branch 'master' into devel

remotes/weblate/feature/pagecrop
Koitharu 6 years ago
commit f15f0ce769

@ -15,7 +15,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode gitCommits versionCode gitCommits
versionName '0.1.2' versionName '0.1.3'
buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\"" buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\""

@ -1,5 +1,6 @@
package org.koitharu.kotatsu.domain package org.koitharu.kotatsu.domain
import androidx.room.withTransaction
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import org.koin.core.inject import org.koin.core.inject
import org.koitharu.kotatsu.core.db.MangaDatabase import org.koitharu.kotatsu.core.db.MangaDatabase
@ -31,6 +32,10 @@ class MangaDataRepository : KoinComponent {
} }
suspend fun storeManga(manga: Manga) { suspend fun storeManga(manga: Manga) {
db.mangaDao.upsert(MangaEntity.from(manga), manga.tags.map(TagEntity.Companion::fromMangaTag)) val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
db.withTransaction {
db.tagsDao.upsert(tags)
db.mangaDao.upsert(MangaEntity.from(manga), tags)
}
} }
} }

@ -1,5 +1,6 @@
package org.koitharu.kotatsu.domain.favourites package org.koitharu.kotatsu.domain.favourites
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
@ -48,10 +49,12 @@ class FavouritesRepository : KoinComponent {
suspend fun addToCategory(manga: Manga, categoryId: Long) { suspend fun addToCategory(manga: Manga, categoryId: Long) {
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag) val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
db.withTransaction {
db.tagsDao.upsert(tags) db.tagsDao.upsert(tags)
db.mangaDao.upsert(MangaEntity.from(manga), tags) db.mangaDao.upsert(MangaEntity.from(manga), tags)
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis()) val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
db.favouritesDao.add(entity) db.favouritesDao.add(entity)
}
notifyFavouritesChanged(manga.id) notifyFavouritesChanged(manga.id)
} }

@ -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,6 +25,7 @@ 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.withTransaction {
db.tagsDao.upsert(tags) db.tagsDao.upsert(tags)
db.mangaDao.upsert(MangaEntity.from(manga), tags) db.mangaDao.upsert(MangaEntity.from(manga), tags)
if (db.historyDao.upsert( if (db.historyDao.upsert(
@ -35,9 +37,11 @@ class HistoryRepository : KoinComponent {
page = page, page = page,
scroll = scroll scroll = scroll
) )
)) { )
) {
TrackingRepository().insertOrNothing(manga) TrackingRepository().insertOrNothing(manga)
} }
}
notifyHistoryChanged() notifyHistoryChanged()
} }

Loading…
Cancel
Save