This commit is contained in:
kunfei
2022-02-16 22:44:39 +08:00
parent 89fa4b5f79
commit 18a7c35196
10 changed files with 88 additions and 4 deletions
@@ -241,14 +241,36 @@ class ReadBookActivity : BaseReadBookActivity(),
showDialogFragment(ChangeSourceDialog(it.name, it.author))
}
}
R.id.menu_refresh -> {
R.id.menu_refresh_dur -> {
if (ReadBook.bookSource == null) {
upContent()
} else {
ReadBook.book?.let {
ReadBook.curTextChapter = null
binding.readView.upContent()
viewModel.refreshContent(it)
viewModel.refreshContentDur(it)
}
}
}
R.id.menu_refresh_after -> {
if (ReadBook.bookSource == null) {
upContent()
} else {
ReadBook.book?.let {
ReadBook.clearTextChapter()
binding.readView.upContent()
viewModel.refreshContentAfter(it)
}
}
}
R.id.menu_refresh_all -> {
if (ReadBook.bookSource == null) {
upContent()
} else {
ReadBook.book?.let {
ReadBook.clearTextChapter()
binding.readView.upContent()
viewModel.refreshContentAll(it)
}
}
}
@@ -253,7 +253,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun refreshContent(book: Book) {
fun refreshContentDur(book: Book) {
execute {
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter ->
@@ -263,6 +263,26 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun refreshContentAfter(book: Book) {
execute {
appDb.bookChapterDao.getChapterList(
book.bookUrl,
ReadBook.durChapterIndex,
book.totalChapterNum
).forEach { chapter ->
BookHelp.delContent(book, chapter)
}
ReadBook.loadContent(false)
}
}
fun refreshContentAll(book: Book) {
execute {
BookHelp.clearCache(book)
ReadBook.loadContent(false)
}
}
fun reverseContent(book: Book) {
execute {
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)