mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 21:11:52 +01:00
Minor fixes when updating the manga viewer
This commit is contained in:
parent
790e0908a3
commit
788cb843fc
@ -6,10 +6,7 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
|||||||
import eu.kanade.tachiyomi.data.database.DbProvider
|
import eu.kanade.tachiyomi.data.database.DbProvider
|
||||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.LibraryMangaGetResolver
|
import eu.kanade.tachiyomi.data.database.resolvers.*
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.MangaFavoritePutResolver
|
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.MangaFlagsPutResolver
|
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.MangaLastUpdatedPutResolver
|
|
||||||
import eu.kanade.tachiyomi.data.database.tables.CategoryTable
|
import eu.kanade.tachiyomi.data.database.tables.CategoryTable
|
||||||
import eu.kanade.tachiyomi.data.database.tables.ChapterTable
|
import eu.kanade.tachiyomi.data.database.tables.ChapterTable
|
||||||
import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable
|
import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable
|
||||||
@ -80,6 +77,11 @@ interface MangaQueries : DbProvider {
|
|||||||
.withPutResolver(MangaFavoritePutResolver())
|
.withPutResolver(MangaFavoritePutResolver())
|
||||||
.prepare()
|
.prepare()
|
||||||
|
|
||||||
|
fun updateMangaViewer(manga: Manga) = db.put()
|
||||||
|
.`object`(manga)
|
||||||
|
.withPutResolver(MangaViewerPutResolver())
|
||||||
|
.prepare()
|
||||||
|
|
||||||
fun deleteManga(manga: Manga) = db.delete().`object`(manga).prepare()
|
fun deleteManga(manga: Manga) = db.delete().`object`(manga).prepare()
|
||||||
|
|
||||||
fun deleteMangas(mangas: List<Manga>) = db.delete().objects(mangas).prepare()
|
fun deleteMangas(mangas: List<Manga>) = db.delete().objects(mangas).prepare()
|
||||||
@ -108,4 +110,4 @@ interface MangaQueries : DbProvider {
|
|||||||
|
|
||||||
fun getTotalChapterManga() = db.get().listOfObjects(Manga::class.java)
|
fun getTotalChapterManga() = db.get().listOfObjects(Manga::class.java)
|
||||||
.withQuery(RawQuery.builder().query(getTotalChapterMangaQuery()).observesTables(MangaTable.TABLE).build()).prepare();
|
.withQuery(RawQuery.builder().query(getTotalChapterMangaQuery()).observesTables(MangaTable.TABLE).build()).prepare();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package eu.kanade.tachiyomi.data.database.resolvers
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
|
import com.pushtorefresh.storio.sqlite.StorIOSQLite
|
||||||
|
import com.pushtorefresh.storio.sqlite.operations.put.PutResolver
|
||||||
|
import com.pushtorefresh.storio.sqlite.operations.put.PutResult
|
||||||
|
import com.pushtorefresh.storio.sqlite.queries.UpdateQuery
|
||||||
|
import eu.kanade.tachiyomi.data.database.inTransactionReturn
|
||||||
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
|
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||||
|
|
||||||
|
class MangaViewerPutResolver : PutResolver<Manga>() {
|
||||||
|
|
||||||
|
override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn {
|
||||||
|
val updateQuery = mapToUpdateQuery(manga)
|
||||||
|
val contentValues = mapToContentValues(manga)
|
||||||
|
|
||||||
|
val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues)
|
||||||
|
PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder()
|
||||||
|
.table(MangaTable.TABLE)
|
||||||
|
.where("${MangaTable.COL_ID} = ?")
|
||||||
|
.whereArgs(manga.id)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
fun mapToContentValues(manga: Manga) = ContentValues(1).apply {
|
||||||
|
put(MangaTable.COL_VIEWER, manga.viewer)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -99,7 +99,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
|
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent {
|
||||||
val intent = Intent(context, ReaderActivity::class.java)
|
val intent = Intent(context, ReaderActivity::class.java)
|
||||||
intent.putExtra("manga", manga)
|
intent.putExtra("manga", manga.id)
|
||||||
intent.putExtra("chapter", chapter.id)
|
intent.putExtra("chapter", chapter.id)
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
@ -117,10 +117,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
setContentView(R.layout.reader_activity)
|
setContentView(R.layout.reader_activity)
|
||||||
|
|
||||||
if (presenter.needsInit()) {
|
if (presenter.needsInit()) {
|
||||||
val manga = intent.extras.getSerializable("manga") as? Manga
|
val manga = intent.extras.getLong("manga", -1)
|
||||||
val chapter = intent.extras.getLong("chapter", -1)
|
val chapter = intent.extras.getLong("chapter", -1)
|
||||||
|
|
||||||
if (manga == null || chapter == -1L) {
|
if (manga == -1L || chapter == -1L) {
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -157,11 +157,27 @@ class ReaderPresenter(
|
|||||||
return manga == null
|
return manga == null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes this presenter with the given [mangaId] and [initialChapterId]. This method will
|
||||||
|
* fetch the manga from the database and initialize the initial chapter.
|
||||||
|
*/
|
||||||
|
fun init(mangaId: Long, initialChapterId: Long) {
|
||||||
|
if (!needsInit()) return
|
||||||
|
|
||||||
|
db.getManga(mangaId).asRxObservable()
|
||||||
|
.first()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnNext { init(it, initialChapterId) }
|
||||||
|
.subscribeFirst({ _, _ ->
|
||||||
|
// Ignore onNext event
|
||||||
|
}, ReaderActivity::setInitialChapterError)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this presenter with the given [manga] and [initialChapterId]. This method will
|
* Initializes this presenter with the given [manga] and [initialChapterId]. This method will
|
||||||
* set the chapter loader, view subscriptions and trigger an initial load.
|
* set the chapter loader, view subscriptions and trigger an initial load.
|
||||||
*/
|
*/
|
||||||
fun init(manga: Manga, initialChapterId: Long) {
|
private fun init(manga: Manga, initialChapterId: Long) {
|
||||||
if (!needsInit()) return
|
if (!needsInit()) return
|
||||||
|
|
||||||
this.manga = manga
|
this.manga = manga
|
||||||
@ -180,6 +196,7 @@ class ReaderPresenter(
|
|||||||
.fromCallable { chapterList.first { chapterId == it.chapter.id } }
|
.fromCallable { chapterList.first { chapterId == it.chapter.id } }
|
||||||
.flatMap { getLoadObservable(loader!!, it) }
|
.flatMap { getLoadObservable(loader!!, it) }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribeFirst({ _, _ ->
|
.subscribeFirst({ _, _ ->
|
||||||
// Ignore onNext event
|
// Ignore onNext event
|
||||||
}, ReaderActivity::setInitialChapterError)
|
}, ReaderActivity::setInitialChapterError)
|
||||||
@ -374,8 +391,7 @@ class ReaderPresenter(
|
|||||||
fun setMangaViewer(viewer: Int) {
|
fun setMangaViewer(viewer: Int) {
|
||||||
val manga = manga ?: return
|
val manga = manga ?: return
|
||||||
manga.viewer = viewer
|
manga.viewer = viewer
|
||||||
// TODO custom put operation
|
db.updateMangaViewer(manga).executeAsBlocking()
|
||||||
db.insertManga(manga).executeAsBlocking()
|
|
||||||
|
|
||||||
Observable.timer(250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
|
Observable.timer(250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
|
||||||
.subscribeFirst({ view, _ ->
|
.subscribeFirst({ view, _ ->
|
||||||
|
Loading…
Reference in New Issue
Block a user