pull/2062/head
821938089 2 years ago
parent f441dae227
commit 44baa04fa6
  1. 6
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  5. 5
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -39,6 +39,12 @@ object BookHelp {
FileUtils.delete(filePath)
}
fun updateCacheFolder(oldBook: Book, newBook: Book) {
val oldFolderPath = FileUtils.getPath(downloadDir, cacheFolderName, oldBook.getFolderName())
val newFolderPath = FileUtils.getPath(downloadDir, cacheFolderName, newBook.getFolderName())
FileUtils.move(oldFolderPath, newFolderPath)
}
/**
* 清除已删除书的缓存
*/

@ -216,9 +216,9 @@ class BookInfoActivity :
toastOnUi(getString(R.string.upload_book_success))
else
toastOnUi(getString(R.string.upload_book_fail))
}catch (e : Exception){
} catch (e: Exception) {
toastOnUi(e.localizedMessage)
}finally {
} finally {
waitDialog.dismiss()
}
}
@ -271,6 +271,8 @@ class BookInfoActivity :
} else {
binding.tvToc.text = getString(R.string.toc_s, chapterList.last().title)
}
binding.tvLasted.text =
getString(R.string.lasted_show, chapterList.last().title)
}
}
}

@ -154,6 +154,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
chapterListData.postValue(emptyList())
} else {
bookSource?.let { bookSource ->
val oldBook = book.copy()
val preUpdateJs = bookSource.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) {
AnalyzeRule(book, bookSource).evalJS(preUpdateJs)
@ -161,8 +162,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
WebBook.getChapterList(this, bookSource, book)
.onSuccess(IO) {
if (inBookshelf) {
if (oldBook.bookUrl == book.bookUrl) {
appDb.bookDao.update(book)
appDb.bookChapterDao.delByBook(book.bookUrl)
} else {
appDb.bookDao.insert(book)
BookHelp.updateCacheFolder(oldBook, book)
}
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray())
}
chapterListData.postValue(it)

@ -148,14 +148,21 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} else {
ReadBook.bookSource?.let {
viewModelScope.launch(IO) {
val oldBook = book.copy()
val preUpdateJs = it.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) {
AnalyzeRule(book, it).evalJS(preUpdateJs)
}
WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList ->
appDb.bookChapterDao.insert(*cList.toTypedArray())
if (oldBook.bookUrl == book.bookUrl) {
appDb.bookDao.update(book)
} else {
appDb.bookDao.insert(book)
BookHelp.updateCacheFolder(oldBook, book)
}
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
appDb.bookChapterDao.insert(*cList.toTypedArray())
ReadBook.chapterSize = cList.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)

@ -11,6 +11,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppWebDav
import io.legado.app.help.BookHelp
import io.legado.app.help.DefaultData
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig
@ -116,6 +117,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
waitUpTocBooks.remove(bookUrl)
upTocAdd(bookUrl)
execute(context = upTocPool) {
val oldBook = book.copy()
val preUpdateJs = source.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) {
AnalyzeRule(book, source).evalJS(preUpdateJs)
@ -129,8 +131,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} else {
upTocAdd(book.bookUrl)
appDb.bookDao.insert(book)
BookHelp.updateCacheFolder(oldBook, book)
}
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.delByBook(bookUrl)
appDb.bookChapterDao.insert(*toc.toTypedArray())
addDownload(source, book)
}.onError(upTocPool) {

Loading…
Cancel
Save