This commit is contained in:
len 2016-11-22 16:06:02 +01:00
parent a13ebc3975
commit 830f792824
3 changed files with 14 additions and 20 deletions

View File

@ -11,6 +11,13 @@ class ChaptersAdapter(val fragment: ChaptersFragment) : FlexibleAdapter<Chapters
setHasStableIds(true) setHasStableIds(true)
} }
var items: List<ChapterModel>
get() = mItems
set(value) {
mItems = value
notifyDataSetChanged()
}
override fun updateDataSet(param: String) { override fun updateDataSet(param: String) {
} }
@ -32,8 +39,4 @@ class ChaptersAdapter(val fragment: ChaptersFragment) : FlexibleAdapter<Chapters
return mItems[position].id!! return mItems[position].id!!
} }
fun setItems(chapters: List<ChapterModel>) {
mItems = chapters
notifyDataSetChanged()
}
} }

View File

@ -182,7 +182,7 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
initialFetchChapters() initialFetchChapters()
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
adapter.setItems(chapters) adapter.items = chapters
} }
private fun initialFetchChapters() { private fun initialFetchChapters() {
@ -360,7 +360,11 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
} }
fun markPreviousAsRead(chapter: ChapterModel) { fun markPreviousAsRead(chapter: ChapterModel) {
presenter.markPreviousChaptersAsRead(chapter) val chapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items
val chapterPos = chapters.indexOf(chapter)
if (chapterPos != -1) {
presenter.markChaptersRead(chapters.take(chapterPos), true)
}
} }
fun downloadChapters(chapters: List<ChapterModel>) { fun downloadChapters(chapters: List<ChapterModel>) {

View File

@ -288,19 +288,6 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
.subscribe() .subscribe()
} }
/**
* Mark the previous chapters to the selected one as read.
* @param chapter the selected chapter.
*/
fun markPreviousChaptersAsRead(chapter: ChapterModel) {
Observable.from(chapters)
.filter { it.isRecognizedNumber && it.chapter_number < chapter.chapter_number }
.doOnNext { it.read = true }
.toList()
.flatMap { db.updateChaptersProgress(it).asRxObservable() }
.subscribe()
}
/** /**
* Downloads the given list of chapters with the manager. * Downloads the given list of chapters with the manager.
* @param chapters the list of chapters to download. * @param chapters the list of chapters to download.