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 40c9cf32b..a06f8f2d7 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 @@ -17,6 +17,13 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.bookData.observe(this, Observer { showBook(it) }) + viewModel.isLoadingData.observe(this, Observer { + if (it) { + tv_loading.visible() + } else { + tv_loading.gone() + } + }) viewModel.loadBook(intent) } diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index c44140716..235e57483 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -10,6 +10,7 @@ import io.legado.app.data.entities.Book class BookInfoViewModel(application: Application) : BaseViewModel(application) { val bookData = MutableLiveData() + val isLoadingData = MutableLiveData() var inBookshelf = false fun loadBook(intent: Intent) { @@ -20,8 +21,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { bookData.postValue(book) } } ?: intent.getStringExtra("searchBookUrl")?.let { - App.db.searchBookDao().getSearchBook(it)?.let { searchBook -> - bookData.postValue(searchBook.toBook()) + App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book -> + bookData.postValue(book) + if (book.tocUrl.isNullOrEmpty()) { + loadBookInfo() + } else { + loadChapter() + } } } } @@ -31,4 +37,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } + fun loadChapter() { + + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index cf1e0fd1f..a905af79f 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -240,8 +240,7 @@ android:gravity="center" android:text="@string/data_loading" android:textColor="#767676" - android:textSize="16sp" - android:visibility="gone" /> + android:textSize="16sp" /> \ No newline at end of file