pull/32/head
kunfei 5 years ago
parent 82ceb97dfe
commit 46b5131872
  1. 10
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 1
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  3. 11
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -57,6 +57,16 @@ object BookHelp {
return null 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 { private fun getChapterPath(book: Book, bookChapter: BookChapter): String {
val bookFolder = formatFolderName(book.name + book.bookUrl) val bookFolder = formatFolderName(book.name + book.bookUrl)
val chapterFile = String.format("%05d-%s", bookChapter.index, formatFolderName(bookChapter.title)) val chapterFile = String.format("%05d-%s", bookChapter.index, formatFolderName(bookChapter.title))

@ -180,6 +180,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag) changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag)
} }
R.id.menu_refresh -> viewModel.refreshContent()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

@ -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() { override fun onCleared() {
super.onCleared() super.onCleared()
ReadAloudService.stop(context) ReadAloudService.stop(context)

Loading…
Cancel
Save