pull/32/head
parent
5800bb9e67
commit
2fd8c5f278
@ -1,16 +1,36 @@ |
|||||||
package io.legado.app.ui.bookinfo |
package io.legado.app.ui.bookinfo |
||||||
|
|
||||||
import android.os.Bundle |
import android.os.Bundle |
||||||
|
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 |
||||||
|
import io.legado.app.data.entities.Book |
||||||
|
import io.legado.app.help.ImageLoader |
||||||
import io.legado.app.utils.getViewModel |
import io.legado.app.utils.getViewModel |
||||||
|
import kotlinx.android.synthetic.main.activity_book_info.* |
||||||
|
|
||||||
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?) { |
||||||
|
viewModel.bookData.observe(this, Observer { showBook(it) }) |
||||||
|
viewModel.loadData(intent) |
||||||
|
} |
||||||
|
|
||||||
|
private fun showBook(book: Book) { |
||||||
|
tv_name.text = book.name |
||||||
|
tv_author.text = book.author |
||||||
|
tv_origin.text = book.origin |
||||||
|
tv_lasted.text = book.latestChapterTitle |
||||||
|
tv_intro.text = book.getDisplayIntro() |
||||||
|
book.getDisplayCover()?.let { |
||||||
|
ImageLoader.load(this, it) |
||||||
|
.placeholder(R.drawable.img_cover_default) |
||||||
|
.error(R.drawable.img_cover_default) |
||||||
|
.centerCrop() |
||||||
|
.setAsDrawable(iv_cover) |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,24 @@ |
|||||||
package io.legado.app.ui.bookinfo |
package io.legado.app.ui.bookinfo |
||||||
|
|
||||||
import android.app.Application |
import android.app.Application |
||||||
|
import android.content.Intent |
||||||
|
import androidx.lifecycle.MutableLiveData |
||||||
|
import io.legado.app.App |
||||||
import io.legado.app.base.BaseViewModel |
import io.legado.app.base.BaseViewModel |
||||||
|
import io.legado.app.data.entities.Book |
||||||
|
|
||||||
class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
||||||
|
|
||||||
|
val bookData = MutableLiveData<Book>() |
||||||
|
|
||||||
|
fun loadData(intent: Intent) { |
||||||
|
execute { |
||||||
|
intent.getStringExtra("bookUrl")?.let { |
||||||
|
App.db.bookDao().getBook(it)?.let { book -> |
||||||
|
bookData.postValue(book) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue