Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mabDc committed Aug 14, 2019
1 parent d60628b commit 2b54834
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ interface ChapterDao {
@Query("SELECT * FROM Chapter WHERE id = :chapterId")
fun getChapter(chapterId: Long): Chapter?

@Query("DELETE FROM Chapter WHERE manga_id = :mangaId")
fun deleteChapters(mangaId: Long)

@Delete
fun deleteChapters(list: List<Chapter>)

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/top/rechinx/meow/ui/details/DetailPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class DetailPresenter(val sourceId: Long, val url: String): BasePresenter<Detail
pager = ChapterPager(source, url)
pager.results.observeOn(Schedulers.io())
.map {
chapterDao.deleteChapters(manga?.id!!)
it.first to it.second.map { chapter -> networkToLocalChapter(chapter, manga?.id!!) }
}.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -117,6 +118,7 @@ class DetailPresenter(val sourceId: Long, val url: String): BasePresenter<Detail
}

fun networkToLocalChapter(sChapter: SChapter, mangaId: Long): Chapter {
/*
var localChapter = chapterDao.getChapter(sChapter.url!!, mangaId)
if(localChapter == null) {
val newChapter = Chapter.create().apply {
Expand All @@ -128,6 +130,15 @@ class DetailPresenter(val sourceId: Long, val url: String): BasePresenter<Detail
localChapter = newChapter
}
return localChapter
*/

val newChapter = Chapter.create().apply {
manga_id = mangaId
}
newChapter.copyFrom(sChapter)
val insertedId = chapterDao.insertChapter(newChapter)
newChapter.id = insertedId
return newChapter
}

/**
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/top/rechinx/meow/ui/result/ResultPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ class ResultPresenter(val query: String): BasePresenter<ResultActivity>(), KoinC
try {
if(it.list.isEmpty()) throw Exception()
for(item in it.list) {
val manga = Manga()
manga.copyFrom(item)
manga.sourceId = source.id
manga.sourceName = source.name
emitter.onNext(manga)
Thread.sleep(Random().nextInt(200).toLong())
if(item.title != null && item.title!!.contains(query)){
val manga = Manga()
manga.copyFrom(item)
manga.sourceId = source.id
manga.sourceName = source.name
emitter.onNext(manga)
Thread.sleep(Random().nextInt(200).toLong())
}
}
emitter.onComplete()
} catch (e: Exception) {
Expand Down

0 comments on commit 2b54834

Please sign in to comment.