pull/32/head
kunfei 5 years ago
parent 4bd9d45b94
commit f89ebc0860
  1. 2
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
  3. 21
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  4. 13
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt
  5. 18
      app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt
  6. 2
      app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditViewModel.kt

@ -51,7 +51,7 @@
<activity android:name=".ui.qrcode.QrCodeActivity" /> <activity android:name=".ui.qrcode.QrCodeActivity" />
<activity android:name=".ui.about.DonateActivity" /> <activity android:name=".ui.about.DonateActivity" />
<activity android:name=".ui.bookinfo.BookInfoActivity" /> <activity android:name=".ui.bookinfo.BookInfoActivity" />
<activity android:name=".ui.bookinfo.BookInfoEditActivity" /> <activity android:name=".ui.bookinfo.edit.BookInfoEditActivity" />
<activity android:name=".ui.sourcedebug.SourceDebugActivity" /> <activity android:name=".ui.sourcedebug.SourceDebugActivity" />
<activity android:name=".ui.booksource.BookSourceActivity" /> <activity android:name=".ui.booksource.BookSourceActivity" />
<activity android:name=".ui.readbook.ReadBookActivity" /> <activity android:name=".ui.readbook.ReadBookActivity" />

@ -13,6 +13,9 @@ interface BookChapterDao {
@Query("select * from chapters where bookUrl = :bookUrl") @Query("select * from chapters where bookUrl = :bookUrl")
fun observeByBook(bookUrl: String): DataSource.Factory<Int, BookChapter> fun observeByBook(bookUrl: String): DataSource.Factory<Int, BookChapter>
@Query("select * from chapters where bookUrl = :bookUrl")
fun getChapterList(bookUrl: String): List<BookChapter>
@Query("select * from chapters where bookUrl = :bookUrl and `index` = :index") @Query("select * from chapters where bookUrl = :bookUrl and `index` = :index")
fun getChapter(bookUrl: String, index: Int): BookChapter? fun getChapter(bookUrl: String, index: Int): BookChapter?

@ -4,10 +4,13 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
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.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.ui.bookinfo.edit.BookInfoEditActivity
import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone import io.legado.app.utils.gone
@ -22,13 +25,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
get() = getViewModel(BookInfoViewModel::class.java) get() = getViewModel(BookInfoViewModel::class.java)
private var changeSourceDialog: ChangeSourceDialog? = null private var changeSourceDialog: ChangeSourceDialog? = null
private lateinit var adapter: ChapterListAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
initRecyclerView()
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.chapterListData.observe(this, Observer { showChapter(it) })
viewModel.loadBook(intent) viewModel.loadBook(intent)
initView() initOnClick()
savedInstanceState?.let { savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
changeSourceDialog?.callBack = this changeSourceDialog?.callBack = this
@ -98,6 +104,11 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
} }
private fun showChapter(chapterList: List<BookChapter>) {
adapter.clearItems()
adapter.addItems(chapterList)
}
private fun upLoading(isLoading: Boolean) { private fun upLoading(isLoading: Boolean) {
if (isLoading) { if (isLoading) {
tv_loading.visible() tv_loading.visible()
@ -111,7 +122,13 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
} }
private fun initView() { private fun initRecyclerView() {
adapter = ChapterListAdapter(this)
rv_chapter_list.layoutManager = LinearLayoutManager(this)
rv_chapter_list.adapter = adapter
}
private fun initOnClick() {
tv_read.onClick { tv_read.onClick {
} }

@ -21,6 +21,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
App.db.bookDao().getBook(it)?.let { book -> App.db.bookDao().getBook(it)?.let { book ->
inBookshelf = true inBookshelf = true
bookData.postValue(book) bookData.postValue(book)
val chapterList = App.db.bookChapterDao().getChapterList(it)
if (chapterList.isNotEmpty()) {
chapterListData.postValue(chapterList)
} else {
loadChapter(book)
}
} }
} ?: intent.getStringExtra("searchBookUrl")?.let { } ?: intent.getStringExtra("searchBookUrl")?.let {
App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book -> App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book ->
@ -28,7 +34,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo() loadBookInfo()
} else { } else {
loadChapter() loadChapter(book)
} }
} }
} }
@ -39,8 +45,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
isLoadingData.postValue(false) isLoadingData.postValue(false)
} }
fun loadChapter() { fun loadChapter(book: Book) {
isLoadingData.postValue(false) isLoadingData.postValue(false)
App.db.bookSourceDao().getBookSource(book.origin)?.let {
}
} }
fun saveBook(success: (() -> Unit)?) { fun saveBook(success: (() -> Unit)?) {

@ -0,0 +1,18 @@
package io.legado.app.ui.bookinfo
import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookChapter
import kotlinx.android.synthetic.main.item_chapter_list.view.*
class ChapterListAdapter(context: Context) : SimpleRecyclerAdapter<BookChapter>(context, R.layout.item_chapter_list) {
override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList<Any>) {
holder.itemView.apply {
tv_chapter_name
}
}
}

@ -1,4 +1,4 @@
package io.legado.app.ui.bookinfo package io.legado.app.ui.bookinfo.edit
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu

@ -1,4 +1,4 @@
package io.legado.app.ui.bookinfo package io.legado.app.ui.bookinfo.edit
import android.app.Application import android.app.Application
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
Loading…
Cancel
Save