pull/274/head
gedoor 4 years ago
parent dee5c48259
commit fcc7519021
  1. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt

@ -352,7 +352,7 @@ class BookInfoActivity :
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
requestCodeSourceEdit -> if (resultCode == Activity.RESULT_OK) {
viewModel.initData(intent)
viewModel.upEditBook()
}
requestCodeChapterList -> if (resultCode == Activity.RESULT_OK) {
viewModel.bookData.value?.let {

@ -226,4 +226,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
success?.invoke()
}
}
fun upEditBook() {
bookData.value?.let {
App.db.bookDao().getBook(it.bookUrl)?.let { book ->
bookData.postValue(book)
}
}
}
}

@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
import io.legado.app.service.help.ReadBook
class BookInfoEditViewModel(application: Application) : BaseViewModel(application) {
var book: Book? = null
@ -21,6 +22,9 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
fun saveBook(book: Book, success: (() -> Unit)?) {
execute {
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
}
App.db.bookDao().insert(book)
}.onSuccess {
success?.invoke()

Loading…
Cancel
Save