Fix crash and foreign key issue
This commit is contained in:
@@ -14,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? {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user