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) super.onActivityResult(requestCode, resultCode, data)
when (requestCode) { when (requestCode) {
requestCodeSourceEdit -> if (resultCode == Activity.RESULT_OK) { requestCodeSourceEdit -> if (resultCode == Activity.RESULT_OK) {
viewModel.initData(intent) viewModel.upEditBook()
} }
requestCodeChapterList -> if (resultCode == Activity.RESULT_OK) { requestCodeChapterList -> if (resultCode == Activity.RESULT_OK) {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {

@ -226,4 +226,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
success?.invoke() 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.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.service.help.ReadBook
class BookInfoEditViewModel(application: Application) : BaseViewModel(application) { class BookInfoEditViewModel(application: Application) : BaseViewModel(application) {
var book: Book? = null var book: Book? = null
@ -21,6 +22,9 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
fun saveBook(book: Book, success: (() -> Unit)?) { fun saveBook(book: Book, success: (() -> Unit)?) {
execute { execute {
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
}
App.db.bookDao().insert(book) App.db.bookDao().insert(book)
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()

Loading…
Cancel
Save