diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index cda999353..ab0f5ab95 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -57,6 +57,16 @@ object BookHelp { return null } + fun delContent(book: Book, bookChapter: BookChapter) { + val filePath = getChapterPath(book, bookChapter) + kotlin.runCatching { + val file = File(filePath) + if (file.exists()) { + file.delete() + } + } + } + private fun getChapterPath(book: Book, bookChapter: BookChapter): String { val bookFolder = formatFolderName(book.name + book.bookUrl) val chapterFile = String.format("%05d-%s", bookChapter.index, formatFolderName(bookChapter.title)) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index b5cecfe0d..11b411413 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -180,6 +180,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag) } + R.id.menu_refresh -> viewModel.refreshContent() } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index 7dcd4254d..fb64672df 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -228,6 +228,17 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } + fun refreshContent() { + execute { + bookData.value?.let { book -> + App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> + BookHelp.delContent(book, chapter) + loadContent(book, durChapterIndex) + } + } + } + } + override fun onCleared() { super.onCleared() ReadAloudService.stop(context)