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.about.DonateActivity" />
<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.booksource.BookSourceActivity" />
<activity android:name=".ui.readbook.ReadBookActivity" />

@ -13,6 +13,9 @@ interface BookChapterDao {
@Query("select * from chapters where bookUrl = :bookUrl")
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")
fun getChapter(bookUrl: String, index: Int): BookChapter?

@ -4,10 +4,13 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
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.utils.getViewModel
import io.legado.app.utils.gone
@ -22,13 +25,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
get() = getViewModel(BookInfoViewModel::class.java)
private var changeSourceDialog: ChangeSourceDialog? = null
private lateinit var adapter: ChapterListAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
initRecyclerView()
viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.isLoadingData.observe(this, Observer { upLoading(it) })
viewModel.chapterListData.observe(this, Observer { showChapter(it) })
viewModel.loadBook(intent)
initView()
initOnClick()
savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
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) {
if (isLoading) {
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 {
}

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

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