pull/51/head
kunfei 5 years ago
parent eaedae175b
commit 4a208b4729
  1. 10
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -169,6 +169,15 @@ object ReadBook {
} }
} }
/**
* 加载章节内容
*/
fun loadContent() {
loadContent(durChapterIndex)
loadContent(durChapterIndex + 1)
loadContent(durChapterIndex - 1)
}
fun loadContent(index: Int) { fun loadContent(index: Int) {
book?.let { book -> book?.let { book ->
if (addLoading(index)) { if (addLoading(index)) {
@ -287,7 +296,6 @@ object ReadBook {
} }
interface CallBack { interface CallBack {
fun loadContent()
fun upContent(position: Int = 0) fun upContent(position: Int = 0)
fun upView() fun upView()
fun upPageProgress() fun upPageProgress()

@ -243,15 +243,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
return false return false
} }
/**
* 加载章节内容
*/
override fun loadContent() {
ReadBook.loadContent(ReadBook.durChapterIndex)
ReadBook.loadContent(ReadBook.durChapterIndex + 1)
ReadBook.loadContent(ReadBook.durChapterIndex - 1)
}
/** /**
* 内容加载完成 * 内容加载完成
*/ */
@ -433,7 +424,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
page_view.upBg() page_view.upBg()
page_view.upStyle() page_view.upStyle()
if (it) { if (it) {
loadContent() ReadBook.loadContent()
} else { } else {
page_view.upContent() page_view.upContent()
} }

@ -49,7 +49,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.durChapterIndex = count - 1 ReadBook.durChapterIndex = count - 1
} }
ReadBook.chapterSize = count ReadBook.chapterSize = count
ReadBook.callBack?.loadContent() ReadBook.loadContent()
} }
if (ReadBook.inBookshelf) { if (ReadBook.inBookshelf) {
ReadBook.saveRead() ReadBook.saveRead()
@ -93,7 +93,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
App.db.bookChapterDao().insert(*cList.toTypedArray()) App.db.bookChapterDao().insert(*cList.toTypedArray())
ReadBook.chapterSize = cList.size ReadBook.chapterSize = cList.size
ReadBook.callBack?.loadContent() ReadBook.loadContent()
} else { } else {
changeDruChapterIndex(cList) changeDruChapterIndex(cList)
} }
@ -146,7 +146,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
App.db.bookDao().update(book) App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray()) App.db.bookChapterDao().insert(*chapters.toTypedArray())
ReadBook.chapterSize = chapters.size ReadBook.chapterSize = chapters.size
ReadBook.callBack?.loadContent() ReadBook.loadContent()
} }
} }
@ -160,7 +160,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.durPageIndex = 0 ReadBook.durPageIndex = 0
} }
ReadBook.saveRead() ReadBook.saveRead()
ReadBook.callBack?.loadContent() ReadBook.loadContent()
} }
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {

Loading…
Cancel
Save