From 9c9d5f5883d182e6d8d44f03597ebd1f8f217676 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 14 Aug 2019 15:01:36 +0800 Subject: [PATCH] up --- .../app/ui/bookinfo/BookInfoActivity.kt | 23 +++++++++++++++++++ app/src/main/res/menu/book_info.xml | 18 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 app/src/main/res/menu/book_info.xml diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index 89333ef25..ee34a35f0 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -1,6 +1,8 @@ package io.legado.app.ui.bookinfo import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import androidx.lifecycle.Observer import io.legado.app.R 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.visible 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 class BookInfoActivity : VMBaseActivity(R.layout.activity_book_info) { override val viewModel: BookInfoViewModel get() = getViewModel(BookInfoViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { + setSupportActionBar(toolbar) viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.isLoadingData.observe(this, Observer { upLoading(it) }) viewModel.loadBook(intent) 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(Pair("bookUrl", it.bookUrl)) + } + } + } + } + return super.onCompatOptionsItemSelected(item) + } + private fun showBook(book: Book) { tv_name.text = book.name tv_author.text = getString(R.string.author_show, book.author) diff --git a/app/src/main/res/menu/book_info.xml b/app/src/main/res/menu/book_info.xml new file mode 100644 index 000000000..5e1832752 --- /dev/null +++ b/app/src/main/res/menu/book_info.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file