pull/48/head
kunfei 5 years ago
parent b7af733e26
commit a4f7315492
  1. 20
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt

@ -1,5 +1,7 @@
package io.legado.app.ui.book.info package io.legado.app.ui.book.info
import android.app.Activity
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem 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 kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info), class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info),
@ -43,13 +46,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.isLoadingData.observe(this, Observer { upLoading(it) }) viewModel.isLoadingData.observe(this, Observer { upLoading(it) })
viewModel.chapterListData.observe(this, Observer { showChapter(it) }) viewModel.chapterListData.observe(this, Observer { showChapter(it) })
viewModel.bookData.value?.let { viewModel.initData(intent)
showBook(it)
upLoading(false)
viewModel.chapterListData.value?.let { chapters ->
showChapter(chapters)
}
} ?: viewModel.initData(intent)
initOnClick() initOnClick()
} }
@ -65,6 +62,8 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
startActivity<BookInfoEditActivity>(Pair("bookUrl", it.bookUrl)) startActivity<BookInfoEditActivity>(Pair("bookUrl", it.bookUrl))
} }
} else {
toast("未加入书架,不能编辑")
} }
} }
R.id.menu_refresh -> { R.id.menu_refresh -> {
@ -261,4 +260,11 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override fun durChapterIndex(): Int { override fun durChapterIndex(): Int {
return viewModel.durChapterIndex 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)
}
}
} }

@ -1,5 +1,6 @@
package io.legado.app.ui.book.info.edit package io.legado.app.ui.book.info.edit
import android.app.Activity
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -11,7 +12,8 @@ import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_book_info_edit.* import kotlinx.android.synthetic.main.activity_book_info_edit.*
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
class BookInfoEditActivity : VMBaseActivity<BookInfoEditViewModel>(R.layout.activity_book_info_edit) { class BookInfoEditActivity :
VMBaseActivity<BookInfoEditViewModel>(R.layout.activity_book_info_edit) {
override val viewModel: BookInfoEditViewModel override val viewModel: BookInfoEditViewModel
get() = getViewModel(BookInfoEditViewModel::class.java) get() = getViewModel(BookInfoEditViewModel::class.java)
@ -50,7 +52,14 @@ class BookInfoEditActivity : VMBaseActivity<BookInfoEditViewModel>(R.layout.acti
val customCoverUrl = tie_cover_url.text?.toString() val customCoverUrl = tie_cover_url.text?.toString()
book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl
book.customIntro = tie_book_intro.text?.toString() 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)
})
} }
} }
} }
Loading…
Cancel
Save