diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 225fe2ea1..bd15cad0a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -51,7 +51,7 @@
-
+
diff --git a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
index 20d233149..6473da76f 100644
--- a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
+++ b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
@@ -13,6 +13,9 @@ interface BookChapterDao {
@Query("select * from chapters where bookUrl = :bookUrl")
fun observeByBook(bookUrl: String): DataSource.Factory
+ @Query("select * from chapters where bookUrl = :bookUrl")
+ fun getChapterList(bookUrl: String): List
+
@Query("select * from chapters where bookUrl = :bookUrl and `index` = :index")
fun getChapter(bookUrl: String, index: Int): BookChapter?
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 a4bb266bd..f0e3215c8 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
@@ -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(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(R.layout.activity_boo
}
}
+ private fun showChapter(chapterList: List) {
+ adapter.clearItems()
+ adapter.addItems(chapterList)
+ }
+
private fun upLoading(isLoading: Boolean) {
if (isLoading) {
tv_loading.visible()
@@ -111,7 +122,13 @@ class BookInfoActivity : VMBaseActivity(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 {
}
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 af4291452..7efde2b00 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
@@ -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)?) {
diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt
new file mode 100644
index 000000000..b6fd0cdfc
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt
@@ -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(context, R.layout.item_chapter_list) {
+
+ override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList) {
+ holder.itemView.apply {
+ tv_chapter_name
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditActivity.kt
similarity index 98%
rename from app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt
rename to app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditActivity.kt
index 11cbbe490..779cf962a 100644
--- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditActivity.kt
@@ -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
diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditViewModel.kt
similarity index 95%
rename from app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditViewModel.kt
rename to app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditViewModel.kt
index b331b8a78..fb33a22e7 100644
--- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditViewModel.kt
+++ b/app/src/main/java/io/legado/app/ui/bookinfo/edit/BookInfoEditViewModel.kt
@@ -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