pull/32/head
kunfei 5 years ago
parent bae96277ff
commit 9c9d5f5883
  1. 23
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 18
      app/src/main/res/menu/book_info.xml

@ -1,6 +1,8 @@
package io.legado.app.ui.bookinfo package io.legado.app.ui.bookinfo
import android.os.Bundle import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
@ -10,19 +12,40 @@ import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.activity_book_info.* 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.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info) { class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info) {
override val viewModel: BookInfoViewModel override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java) get() = getViewModel(BookInfoViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
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.loadBook(intent) viewModel.loadBook(intent)
initView() initView()
} }
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_info, menu)
return super.onCompatCreateOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_edit -> {
if (viewModel.inBookshelf) {
viewModel.bookData.value?.let {
startActivity<BookInfoEditActivity>(Pair("bookUrl", it.bookUrl))
}
}
}
}
return super.onCompatOptionsItemSelected(item)
}
private fun showBook(book: Book) { private fun showBook(book: Book) {
tv_name.text = book.name tv_name.text = book.name
tv_author.text = getString(R.string.author_show, book.author) tv_author.text = getString(R.string.author_show, book.author)

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_edit"
android:icon="@drawable/ic_save"
android:title="@string/edit"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_refresh"
android:icon="@drawable/ic_refresh_black_24dp"
android:title="@string/refresh"
app:showAsAction="ifRoom" />
</menu>
Loading…
Cancel
Save