diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index d6258f319..de24d9b4e 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -1,5 +1,7 @@ package io.legado.app.ui.book.info +import android.app.Activity +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -27,6 +29,7 @@ import kotlinx.android.synthetic.main.activity_book_info.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity +import org.jetbrains.anko.toast class BookInfoActivity : VMBaseActivity(R.layout.activity_book_info), @@ -43,13 +46,7 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.isLoadingData.observe(this, Observer { upLoading(it) }) viewModel.chapterListData.observe(this, Observer { showChapter(it) }) - viewModel.bookData.value?.let { - showBook(it) - upLoading(false) - viewModel.chapterListData.value?.let { chapters -> - showChapter(chapters) - } - } ?: viewModel.initData(intent) + viewModel.initData(intent) initOnClick() } @@ -65,6 +62,8 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo viewModel.bookData.value?.let { startActivity(Pair("bookUrl", it.bookUrl)) } + } else { + toast("未加入书架,不能编辑") } } R.id.menu_refresh -> { @@ -261,4 +260,11 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo override fun durChapterIndex(): Int { return viewModel.durChapterIndex } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) { + viewModel.initData(intent) + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index fcc4e7e24..9b44da8bc 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.info.edit +import android.app.Activity import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -11,7 +12,8 @@ import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_info_edit.* import org.jetbrains.anko.toast -class BookInfoEditActivity : VMBaseActivity(R.layout.activity_book_info_edit) { +class BookInfoEditActivity : + VMBaseActivity(R.layout.activity_book_info_edit) { override val viewModel: BookInfoEditViewModel get() = getViewModel(BookInfoEditViewModel::class.java) @@ -50,7 +52,14 @@ class BookInfoEditActivity : VMBaseActivity(R.layout.acti val customCoverUrl = tie_cover_url.text?.toString() book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customIntro = tie_book_intro.text?.toString() - viewModel.saveBook(book, success = { finish() }, error = { toast(it) }) + viewModel.saveBook(book, + success = { + setResult(Activity.RESULT_OK) + finish() + }, + error = { + toast(it) + }) } } } \ No newline at end of file