diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 10b20cba9..96e2b7ea2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -59,7 +59,6 @@
-
diff --git a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt b/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt
deleted file mode 100644
index 590699652..000000000
--- a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt
+++ /dev/null
@@ -1,76 +0,0 @@
-package io.legado.app.ui.bookshelf
-
-import android.os.Bundle
-import android.widget.LinearLayout
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.Observer
-import androidx.paging.LivePagedListBuilder
-import androidx.paging.PagedList
-import androidx.recyclerview.widget.DividerItemDecoration
-import androidx.recyclerview.widget.LinearLayoutManager
-import io.legado.app.App
-import io.legado.app.R
-import io.legado.app.base.VMBaseActivity
-import io.legado.app.data.entities.Book
-import io.legado.app.lib.theme.ATH
-import io.legado.app.utils.getViewModel
-import kotlinx.android.synthetic.main.activity_bookshelf.*
-
-class BookshelfActivity : VMBaseActivity(R.layout.activity_bookshelf) {
- override val viewModel: BookshelfViewModel
- get() = getViewModel(BookshelfViewModel::class.java)
-
- private lateinit var bookshelfAdapter: BookshelfAdapter
- private var bookshelfLiveData: LiveData>? = null
-
- override fun onActivityCreated(savedInstanceState: Bundle?) {
- if (viewModel.bookGroup == null) {
- viewModel.bookGroup = intent.getParcelableExtra("data")
- }
- viewModel.bookGroup?.let {
- title_bar.title = it.groupName
- }
- initRecyclerView()
- upRecyclerData()
- }
-
- private fun initRecyclerView() {
- ATH.applyEdgeEffectColor(rv_bookshelf)
- rv_bookshelf.layoutManager = LinearLayoutManager(this)
- rv_bookshelf.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))
- bookshelfAdapter = BookshelfAdapter()
- rv_bookshelf.adapter = bookshelfAdapter
- }
-
- private fun upRecyclerData() {
- viewModel.bookGroup?.let {
- bookshelfLiveData?.removeObservers(this)
- when (it.groupId) {
- -1 -> {
-
- bookshelfLiveData =
- LivePagedListBuilder(App.db.bookDao().observeAll(), 10).build()
- }
- -2 -> {
- bookshelfLiveData =
- LivePagedListBuilder(App.db.bookDao().observeLocal(), 10).build()
- }
- -3 -> {
- bookshelfLiveData =
- LivePagedListBuilder(App.db.bookDao().observeAudio(), 10).build()
- }
- else -> {
- bookshelfLiveData =
- LivePagedListBuilder(
- App.db.bookDao().observeByGroup(it.groupId),
- 10
- ).build()
- }
- }
- bookshelfLiveData?.observe(
- this,
- Observer { pageList -> bookshelfAdapter.submitList(pageList) })
- }
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfViewModel.kt
deleted file mode 100644
index 3948465ac..000000000
--- a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfViewModel.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package io.legado.app.ui.bookshelf
-
-import android.app.Application
-import io.legado.app.base.BaseViewModel
-import io.legado.app.data.entities.BookGroup
-
-class BookshelfViewModel(application: Application) : BaseViewModel(application) {
-
- var bookGroup: BookGroup? = null
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
index 95890e830..9f191510a 100644
--- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
+++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
@@ -1,16 +1,56 @@
package io.legado.app.ui.main
import android.app.Application
+import io.legado.app.App
import io.legado.app.base.BaseViewModel
+import io.legado.app.constant.BookType
+import io.legado.app.constant.Bus
import io.legado.app.help.storage.Restore
+import io.legado.app.model.WebBook
+import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
class MainViewModel(application: Application) : BaseViewModel(application) {
+ val updateList = arrayListOf()
fun restore() {
launch(IO) {
Restore.importYueDuData(getApplication())
}
}
+
+ fun upChapterList() {
+ execute {
+ App.db.bookDao().getRecentRead().forEach { book ->
+ if (book.origin != BookType.local) {
+ App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
+ synchronized(this) {
+ updateList.add(book.bookUrl)
+ postEvent(Bus.UP_BOOK, book.bookUrl)
+ }
+ WebBook(bookSource).getChapterList(book)
+ .onSuccess(IO) {
+ it?.let {
+ App.db.bookDao().update(book)
+ App.db.bookChapterDao().delByBook(book.bookUrl)
+ App.db.bookChapterDao().insert(*it.toTypedArray())
+ }
+ }
+ .onError {
+ it.printStackTrace()
+ }
+ .onFinally {
+ synchronized(this) {
+ updateList.remove(book.bookUrl)
+ postEvent(Bus.UP_BOOK, book.bookUrl)
+ }
+ }
+ }
+ }
+ delay(50)
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt
similarity index 52%
rename from app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt
rename to app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt
index 1a8ed67f6..603684163 100644
--- a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt
@@ -1,4 +1,4 @@
-package io.legado.app.ui.bookshelf
+package io.legado.app.ui.main.bookshelf
import android.view.LayoutInflater
import android.view.View
@@ -7,12 +7,18 @@ import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
+import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
-import io.legado.app.lib.theme.ATH
+import io.legado.app.lib.theme.ThemeStore
+import io.legado.app.utils.getCompatColor
+import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
+import org.jetbrains.anko.sdk27.listeners.onClick
+import org.jetbrains.anko.sdk27.listeners.onLongClick
-class BookshelfAdapter : PagedListAdapter(DIFF_CALLBACK) {
+class BooksAdapter(private val callBack: CallBack) :
+ PagedListAdapter(DIFF_CALLBACK) {
companion object {
@JvmField
@@ -21,23 +27,28 @@ class BookshelfAdapter : PagedListAdapter(D
oldItem.bookUrl == newItem.bookUrl
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean =
- oldItem.bookUrl == newItem.bookUrl
- && oldItem.durChapterTitle == newItem.durChapterTitle
+ oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.latestChapterTitle == newItem.latestChapterTitle
&& oldItem.durChapterTime == newItem.durChapterTime
&& oldItem.lastCheckTime == newItem.lastCheckTime
}
}
- var callBack: CallBack? = null
+ fun notification(bookUrl: String) {
+ for (i in 0..itemCount) {
+ getItem(i)?.let {
+ if (it.bookUrl == bookUrl) {
+ notifyItemChanged(i)
+ return
+ }
+ }
+ }
+ }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(
- LayoutInflater.from(parent.context).inflate(
- R.layout.item_bookshelf_list,
- parent,
- false
- )
+ LayoutInflater.from(parent.context)
+ .inflate(R.layout.item_bookshelf_list, parent, false)
)
}
@@ -50,27 +61,41 @@ class BookshelfAdapter : PagedListAdapter(D
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
init {
- ATH.applyBackgroundTint(itemView)
+ itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context))
}
- fun bind(book: Book, callBack: CallBack?) = with(itemView) {
+ fun bind(book: Book, callBack: CallBack) = with(itemView) {
+ this.setBackgroundColor(context.getCompatColor(R.color.background))
tv_name.text = book.name
tv_author.text = book.author
tv_read.text = book.durChapterTitle
tv_last.text = book.latestChapterTitle
book.getDisplayCover()?.let {
- ImageLoader.load(context, it)//Glide自动识别http://和file:///
+ ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.img_cover_default)
.error(R.drawable.img_cover_default)
.centerCrop()
.setAsDrawable(iv_cover)
}
- itemView.setOnClickListener { callBack?.open(book) }
+ itemView.onClick { callBack.open(book) }
+ itemView.onLongClick {
+ callBack.openBookInfo(book)
+ true
+ }
+ if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) {
+ bv_unread.invisible()
+ rl_loading.show()
+ } else {
+ rl_loading.hide()
+ bv_unread.setBadgeCount(book.getUnreadChapterNum())
+ bv_unread.setHighlight(book.lastCheckCount > 0)
+ }
}
}
interface CallBack {
fun open(book: Book)
- fun search()
+ fun openBookInfo(book: Book)
+ fun isUpdate(bookUrl: String): Boolean
}
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt
new file mode 100644
index 000000000..ee8236255
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt
@@ -0,0 +1,102 @@
+package io.legado.app.ui.main.bookshelf
+
+import android.os.Bundle
+import android.view.View
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.Observer
+import androidx.paging.LivePagedListBuilder
+import androidx.paging.PagedList
+import androidx.recyclerview.widget.DividerItemDecoration
+import androidx.recyclerview.widget.LinearLayoutManager
+import io.legado.app.App
+import io.legado.app.R
+import io.legado.app.base.VMBaseFragment
+import io.legado.app.data.entities.Book
+import io.legado.app.lib.theme.ATH
+import io.legado.app.lib.theme.accentColor
+import io.legado.app.ui.book.info.BookInfoActivity
+import io.legado.app.ui.book.read.ReadBookActivity
+import io.legado.app.ui.main.MainViewModel
+import io.legado.app.utils.getViewModel
+import io.legado.app.utils.getViewModelOfActivity
+import kotlinx.android.synthetic.main.fragment_books.*
+import org.jetbrains.anko.startActivity
+
+
+class BooksFragment : VMBaseFragment(R.layout.fragment_books),
+ BooksAdapter.CallBack {
+ override val viewModel: BooksViewModel
+ get() = getViewModel(BooksViewModel::class.java)
+
+ private lateinit var activityViewModel: MainViewModel
+ private lateinit var booksAdapter: BooksAdapter
+ private var bookshelfLiveData: LiveData>? = null
+ private val groupId = -1
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ activityViewModel = getViewModelOfActivity(MainViewModel::class.java)
+ initRecyclerView()
+ upRecyclerData()
+ }
+
+ private fun initRecyclerView() {
+ ATH.applyEdgeEffectColor(rv_bookshelf)
+ refresh_layout.setColorSchemeColors(accentColor)
+ refresh_layout.setOnRefreshListener {
+ refresh_layout.isRefreshing = false
+ activityViewModel.upChapterList()
+ }
+ rv_bookshelf.layoutManager = LinearLayoutManager(context)
+ rv_bookshelf.addItemDecoration(
+ DividerItemDecoration(
+ rv_bookshelf.context,
+ LinearLayoutManager.VERTICAL
+ )
+ )
+ booksAdapter = BooksAdapter(this)
+ rv_bookshelf.adapter = booksAdapter
+
+ }
+
+ private fun upRecyclerData() {
+ bookshelfLiveData?.removeObservers(this)
+ when (groupId) {
+ -1 -> {
+
+ bookshelfLiveData =
+ LivePagedListBuilder(App.db.bookDao().observeAll(), 10).build()
+ }
+ -2 -> {
+ bookshelfLiveData =
+ LivePagedListBuilder(App.db.bookDao().observeLocal(), 10).build()
+ }
+ -3 -> {
+ bookshelfLiveData =
+ LivePagedListBuilder(App.db.bookDao().observeAudio(), 10).build()
+ }
+ else -> {
+ bookshelfLiveData =
+ LivePagedListBuilder(
+ App.db.bookDao().observeByGroup(groupId),
+ 10
+ ).build()
+ }
+ }
+ bookshelfLiveData?.observe(
+ this,
+ Observer { pageList -> booksAdapter.submitList(pageList) })
+ }
+
+ override fun open(book: Book) {
+ context?.startActivity(Pair("bookUrl", book.bookUrl))
+ }
+
+ override fun openBookInfo(book: Book) {
+ context?.startActivity(Pair("bookUrl", book.bookUrl))
+ }
+
+ override fun isUpdate(bookUrl: String): Boolean {
+ return bookUrl in activityViewModel.updateList
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksViewModel.kt
new file mode 100644
index 000000000..19fa12c04
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksViewModel.kt
@@ -0,0 +1,9 @@
+package io.legado.app.ui.main.bookshelf
+
+import android.app.Application
+import io.legado.app.base.BaseViewModel
+
+
+class BooksViewModel(application: Application) : BaseViewModel(application) {
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
index 34172056d..86238a663 100644
--- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
@@ -1,101 +1,17 @@
package io.legado.app.ui.main.bookshelf
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.paging.PagedListAdapter
-import androidx.recyclerview.widget.DiffUtil
-import androidx.recyclerview.widget.RecyclerView
-import io.legado.app.R
-import io.legado.app.constant.BookType
-import io.legado.app.data.entities.Book
-import io.legado.app.help.ImageLoader
-import io.legado.app.lib.theme.ThemeStore
-import io.legado.app.utils.getCompatColor
-import io.legado.app.utils.invisible
-import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
-import org.jetbrains.anko.sdk27.listeners.onClick
-import org.jetbrains.anko.sdk27.listeners.onLongClick
+import androidx.fragment.app.Fragment
+import androidx.viewpager2.adapter.FragmentStateAdapter
-class BookshelfAdapter(private val callBack: CallBack) :
- PagedListAdapter(DIFF_CALLBACK) {
- companion object {
- @JvmField
- val DIFF_CALLBACK = object : DiffUtil.ItemCallback() {
- override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean =
- oldItem.bookUrl == newItem.bookUrl
+class BookshelfAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
- override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean =
- oldItem.durChapterTitle == newItem.durChapterTitle
- && oldItem.latestChapterTitle == newItem.latestChapterTitle
- && oldItem.durChapterTime == newItem.durChapterTime
- && oldItem.lastCheckTime == newItem.lastCheckTime
- }
+ override fun getItemCount(): Int {
+ return 3
}
- fun notification(bookUrl: String) {
- for (i in 0..itemCount) {
- getItem(i)?.let {
- if (it.bookUrl == bookUrl) {
- notifyItemChanged(i)
- return
- }
- }
- }
+ override fun createFragment(position: Int): Fragment {
+ return BooksFragment()
}
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
- return MyViewHolder(
- LayoutInflater.from(parent.context)
- .inflate(R.layout.item_bookshelf_list, parent, false)
- )
- }
-
- override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
- currentList?.get(position)?.let {
- holder.bind(it, callBack)
- }
- }
-
- class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
-
- init {
- itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context))
- }
-
- fun bind(book: Book, callBack: CallBack) = with(itemView) {
- this.setBackgroundColor(context.getCompatColor(R.color.background))
- tv_name.text = book.name
- tv_author.text = book.author
- tv_read.text = book.durChapterTitle
- tv_last.text = book.latestChapterTitle
- book.getDisplayCover()?.let {
- ImageLoader.load(context, it)//Glide自动识别http://和file://
- .placeholder(R.drawable.img_cover_default)
- .error(R.drawable.img_cover_default)
- .centerCrop()
- .setAsDrawable(iv_cover)
- }
- itemView.onClick { callBack.open(book) }
- itemView.onLongClick {
- callBack.openBookInfo(book)
- true
- }
- if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) {
- bv_unread.invisible()
- rl_loading.show()
- } else {
- rl_loading.hide()
- bv_unread.setBadgeCount(book.getUnreadChapterNum())
- bv_unread.setHighlight(book.lastCheckCount > 0)
- }
- }
- }
-
- interface CallBack {
- fun open(book: Book)
- fun openBookInfo(book: Book)
- fun isUpdate(bookUrl: String): Boolean
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
index df11b8a71..9b6d5f90b 100644
--- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
@@ -11,46 +11,36 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
-import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.Bus
-import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.*
import io.legado.app.lib.theme.ATH
-import io.legado.app.lib.theme.accentColor
-import io.legado.app.ui.book.info.BookInfoActivity
-import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
-import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity
-import org.jetbrains.anko.textColor
class BookshelfFragment : VMBaseFragment(R.layout.fragment_bookshelf),
SearchView.OnQueryTextListener,
- BookGroupAdapter.CallBack,
- BookshelfAdapter.CallBack {
+ BookGroupAdapter.CallBack {
override val viewModel: BookshelfViewModel
get() = getViewModel(BookshelfViewModel::class.java)
- private lateinit var bookshelfAdapter: BookshelfAdapter
+ private lateinit var booksAdapter: BooksAdapter
private lateinit var bookGroupAdapter: BookGroupAdapter
private var bookGroupLiveData: LiveData>? = null
- private var bookshelfLiveData: LiveData>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
initRecyclerView()
initBookGroupData()
- initBookshelfData()
}
override fun onCompatCreateOptionsMenu(menu: Menu) {
@@ -66,27 +56,14 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b
}
private fun initRecyclerView() {
- ATH.applyEdgeEffectColor(rv_bookshelf)
- refresh_layout.setColorSchemeColors(accentColor)
- refresh_layout.setOnRefreshListener {
- refresh_layout.isRefreshing = false
- viewModel.upChapterList()
- }
+ ATH.applyEdgeEffectColor(view_pager_bookshelf)
rv_book_group.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
bookGroupAdapter = BookGroupAdapter()
rv_book_group.adapter = bookGroupAdapter
bookGroupAdapter.callBack = this
- rv_bookshelf.layoutManager = LinearLayoutManager(context)
- rv_bookshelf.addItemDecoration(
- DividerItemDecoration(
- rv_bookshelf.context,
- LinearLayoutManager.VERTICAL
- )
- )
- bookshelfAdapter = BookshelfAdapter(this)
- rv_bookshelf.adapter = bookshelfAdapter
- observeEvent(Bus.UP_BOOK) { bookshelfAdapter.notification(it) }
+ view_pager_bookshelf.adapter = BookshelfAdapter(this)
+ observeEvent(Bus.UP_BOOK) { booksAdapter.notification(it) }
}
private fun initBookGroupData() {
@@ -95,31 +72,13 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) })
}
- private fun initBookshelfData() {
- bookshelfLiveData?.removeObservers(viewLifecycleOwner)
- bookshelfLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build()
- bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) })
- }
-
override fun open(bookGroup: BookGroup) {
when (bookGroup.groupId) {
-10 -> showGroupInputDialog()
- else -> context?.startActivity(Pair("data", bookGroup))
+ else -> context
}
}
- override fun open(book: Book) {
- context?.startActivity(Pair("bookUrl", book.bookUrl))
- }
-
- override fun openBookInfo(book: Book) {
- context?.startActivity(Pair("bookUrl", book.bookUrl))
- }
-
- override fun isUpdate(bookUrl: String): Boolean {
- return bookUrl in viewModel.updateList
- }
-
override fun onQueryTextSubmit(query: String?): Boolean {
context?.startActivity(Pair("key", query))
return false
diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
index c9baf1494..1bb9a3b64 100644
--- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
@@ -3,18 +3,10 @@ package io.legado.app.ui.main.bookshelf
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
-import io.legado.app.constant.BookType
-import io.legado.app.constant.Bus
import io.legado.app.data.entities.BookGroup
-import io.legado.app.model.WebBook
-import io.legado.app.utils.postEvent
-import kotlinx.coroutines.Dispatchers.IO
-import kotlinx.coroutines.delay
class BookshelfViewModel(application: Application) : BaseViewModel(application) {
- val updateList = arrayListOf()
-
fun saveBookGroup(group: String?) {
if (!group.isNullOrBlank()) {
execute {
@@ -28,37 +20,4 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
}
}
-
- fun upChapterList() {
- execute {
- App.db.bookDao().getRecentRead().forEach { book ->
- if (book.origin != BookType.local) {
- App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
- synchronized(this) {
- updateList.add(book.bookUrl)
- postEvent(Bus.UP_BOOK, book.bookUrl)
- }
- WebBook(bookSource).getChapterList(book)
- .onSuccess(IO) {
- it?.let {
- App.db.bookDao().update(book)
- App.db.bookChapterDao().delByBook(book.bookUrl)
- App.db.bookChapterDao().insert(*it.toTypedArray())
- }
- }
- .onError {
- it.printStackTrace()
- }
- .onFinally {
- synchronized(this) {
- updateList.remove(book.bookUrl)
- postEvent(Bus.UP_BOOK, book.bookUrl)
- }
- }
- }
- }
- delay(50)
- }
- }
- }
}
diff --git a/app/src/main/res/layout/activity_bookshelf.xml b/app/src/main/res/layout/fragment_books.xml
similarity index 50%
rename from app/src/main/res/layout/activity_bookshelf.xml
rename to app/src/main/res/layout/fragment_books.xml
index a18920e81..30f8ce74c 100644
--- a/app/src/main/res/layout/activity_bookshelf.xml
+++ b/app/src/main/res/layout/fragment_books.xml
@@ -1,17 +1,12 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_bookshelf.xml b/app/src/main/res/layout/fragment_bookshelf.xml
index e160da925..8bba3afae 100644
--- a/app/src/main/res/layout/fragment_bookshelf.xml
+++ b/app/src/main/res/layout/fragment_bookshelf.xml
@@ -18,16 +18,9 @@
android:layout_height="wrap_content"
android:overScrollMode="never"/>
-
-
-
+
-
\ No newline at end of file