Compare commits

...

2 Commits

Author SHA1 Message Date
de49877178 Fix crash and foreign key issue 2020-03-30 20:55:53 +03:00
450daf17fd Fix foreign key error 2020-03-29 17:57:04 +03:00
6 changed files with 51 additions and 25 deletions

View File

@@ -15,7 +15,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode gitCommits
versionName '0.1.2'
versionName '0.1.4'
buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\""
@@ -36,6 +36,9 @@ android {
buildTypes {
debug {
applicationIdSuffix = '.debug'
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.domain
import androidx.room.withTransaction
import org.koin.core.KoinComponent
import org.koin.core.inject
import org.koitharu.kotatsu.core.db.MangaDatabase
@@ -13,13 +14,18 @@ class MangaDataRepository : KoinComponent {
private val db: MangaDatabase by inject()
suspend fun savePreferences(mangaId: Long, mode: ReaderMode) {
db.preferencesDao().upsert(
MangaPrefsEntity(
mangaId = mangaId,
mode = mode.id
suspend fun savePreferences(manga: Manga, mode: ReaderMode) {
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
db.withTransaction {
db.tagsDao().upsert(tags)
db.mangaDao().upsert(MangaEntity.from(manga), tags)
db.preferencesDao().upsert(
MangaPrefsEntity(
mangaId = manga.id,
mode = mode.id
)
)
)
}
}
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
@@ -31,6 +37,10 @@ class MangaDataRepository : KoinComponent {
}
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)
}
}
}

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.domain.favourites
import androidx.room.withTransaction
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.core.KoinComponent
@@ -48,10 +49,12 @@ class FavouritesRepository : KoinComponent {
suspend fun addToCategory(manga: Manga, categoryId: Long) {
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
db.tagsDao().upsert(tags)
db.mangaDao().upsert(MangaEntity.from(manga), tags)
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
db.favouritesDao().add(entity)
db.withTransaction {
db.tagsDao().upsert(tags)
db.mangaDao().upsert(MangaEntity.from(manga), tags)
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
db.favouritesDao().add(entity)
}
notifyFavouritesChanged(manga.id)
}

View File

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

View File

@@ -182,6 +182,9 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list), Mang
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
if (context == null) {
return
}
when (key) {
getString(R.string.key_list_mode) -> initListMode(settings.listMode)
getString(R.string.key_grid_size) -> UiUtils.SpanCountResolver.update(recyclerView)

View File

@@ -8,6 +8,7 @@ import moxy.presenterScope
import okhttp3.OkHttpClient
import okhttp3.Request
import org.koin.core.get
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.model.Manga
import org.koitharu.kotatsu.core.model.MangaPage
import org.koitharu.kotatsu.core.prefs.ReaderMode
@@ -39,7 +40,7 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
mode = MangaUtils.determineReaderMode(pages)
if (mode != null) {
prefs.savePreferences(
mangaId = manga.id,
manga = manga,
mode = mode
)
}
@@ -49,6 +50,9 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
viewState.onInitReader(manga, mode)
} catch (_: CancellationException) {
} catch (e: Throwable) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
viewState.onError(e)
} finally {
viewState.onLoadingStateChanged(isLoading = false)
@@ -59,7 +63,7 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
fun setMode(manga: Manga, mode: ReaderMode) {
presenterScope.launch(Dispatchers.IO) {
MangaDataRepository().savePreferences(
mangaId = manga.id,
manga = manga,
mode = mode
)
}