pull/32/head
kunfei 5 years ago
parent 6884856370
commit 220f924d66
  1. 7
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt
  3. 3
      app/src/main/res/layout/activity_book_info.xml

@ -17,6 +17,13 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.isLoadingData.observe(this, Observer {
if (it) {
tv_loading.visible()
} else {
tv_loading.gone()
}
})
viewModel.loadBook(intent) viewModel.loadBook(intent)
} }

@ -10,6 +10,7 @@ import io.legado.app.data.entities.Book
class BookInfoViewModel(application: Application) : BaseViewModel(application) { class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val bookData = MutableLiveData<Book>() val bookData = MutableLiveData<Book>()
val isLoadingData = MutableLiveData<Boolean>()
var inBookshelf = false var inBookshelf = false
fun loadBook(intent: Intent) { fun loadBook(intent: Intent) {
@ -20,8 +21,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
bookData.postValue(book) bookData.postValue(book)
} }
} ?: intent.getStringExtra("searchBookUrl")?.let { } ?: intent.getStringExtra("searchBookUrl")?.let {
App.db.searchBookDao().getSearchBook(it)?.let { searchBook -> App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book ->
bookData.postValue(searchBook.toBook()) bookData.postValue(book)
if (book.tocUrl.isNullOrEmpty()) {
loadBookInfo()
} else {
loadChapter()
}
} }
} }
} }
@ -31,4 +37,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
fun loadChapter() {
}
} }

@ -240,8 +240,7 @@
android:gravity="center" android:gravity="center"
android:text="@string/data_loading" android:text="@string/data_loading"
android:textColor="#767676" android:textColor="#767676"
android:textSize="16sp" android:textSize="16sp" />
android:visibility="gone" />
</FrameLayout> </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save