|
|
@ -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) |
|
|
|