mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
76a1faab3a
@ -1,5 +1,6 @@
|
|||||||
package io.legado.app.data.dao
|
package io.legado.app.data.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import io.legado.app.constant.BookType
|
import io.legado.app.constant.BookType
|
||||||
import io.legado.app.data.entities.BookGroup
|
import io.legado.app.data.entities.BookGroup
|
||||||
@ -17,7 +18,7 @@ interface BookGroupDao {
|
|||||||
@Query("SELECT * FROM book_groups ORDER BY `order`")
|
@Query("SELECT * FROM book_groups ORDER BY `order`")
|
||||||
fun flowAll(): Flow<List<BookGroup>>
|
fun flowAll(): Flow<List<BookGroup>>
|
||||||
|
|
||||||
@Query(
|
@get:Query(
|
||||||
"""
|
"""
|
||||||
SELECT * FROM book_groups where (groupId >= 0 and show > 0)
|
SELECT * FROM book_groups where (groupId >= 0 and show > 0)
|
||||||
or (groupId = -4 and show > 0 and (select count(bookUrl) from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0) > 0)
|
or (groupId = -4 and show > 0 and (select count(bookUrl) from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0) > 0)
|
||||||
@ -26,7 +27,7 @@ interface BookGroupDao {
|
|||||||
or (groupId = -1 and show > 0)
|
or (groupId = -1 and show > 0)
|
||||||
ORDER BY `order`"""
|
ORDER BY `order`"""
|
||||||
)
|
)
|
||||||
fun flowShow(): Flow<List<BookGroup>>
|
val show: LiveData<List<BookGroup>>
|
||||||
|
|
||||||
@Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`")
|
@Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`")
|
||||||
fun flowSelect(): Flow<List<BookGroup>>
|
fun flowSelect(): Flow<List<BookGroup>>
|
||||||
|
@ -17,7 +17,6 @@ import io.legado.app.model.CacheBook
|
|||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.service.CacheBookService
|
import io.legado.app.service.CacheBookService
|
||||||
import io.legado.app.utils.postEvent
|
import io.legado.app.utils.postEvent
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.CopyOnWriteArraySet
|
import java.util.concurrent.CopyOnWriteArraySet
|
||||||
|
@ -5,11 +5,14 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseFragment
|
import io.legado.app.base.VMBaseFragment
|
||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.PreferKey
|
import io.legado.app.constant.PreferKey
|
||||||
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
|
import io.legado.app.data.entities.BookGroup
|
||||||
import io.legado.app.databinding.DialogBookshelfConfigBinding
|
import io.legado.app.databinding.DialogBookshelfConfigBinding
|
||||||
import io.legado.app.databinding.DialogEditTextBinding
|
import io.legado.app.databinding.DialogEditTextBinding
|
||||||
import io.legado.app.help.AppConfig
|
import io.legado.app.help.AppConfig
|
||||||
@ -60,6 +63,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
|||||||
}
|
}
|
||||||
abstract val groupId: Long
|
abstract val groupId: Long
|
||||||
abstract val books: List<Book>
|
abstract val books: List<Book>
|
||||||
|
private var groupsLiveData: LiveData<List<BookGroup>>? = null
|
||||||
|
|
||||||
abstract fun gotoTop()
|
abstract fun gotoTop()
|
||||||
|
|
||||||
@ -93,6 +97,17 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun initBookGroupData() {
|
||||||
|
groupsLiveData?.removeObservers(viewLifecycleOwner)
|
||||||
|
groupsLiveData = appDb.bookGroupDao.show.apply {
|
||||||
|
observe(viewLifecycleOwner) {
|
||||||
|
upGroup(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun upGroup(data: List<BookGroup>)
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun addBookByUrl() {
|
fun addBookByUrl() {
|
||||||
alert(titleResource = R.string.add_book_url) {
|
alert(titleResource = R.string.add_book_url) {
|
||||||
|
@ -27,9 +27,6 @@ import io.legado.app.utils.putPrefInt
|
|||||||
import io.legado.app.utils.setEdgeEffectColor
|
import io.legado.app.utils.setEdgeEffectColor
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.collect
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 书架界面
|
* 书架界面
|
||||||
@ -45,7 +42,6 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
|||||||
}
|
}
|
||||||
private val bookGroups = mutableListOf<BookGroup>()
|
private val bookGroups = mutableListOf<BookGroup>()
|
||||||
private val fragmentMap = hashMapOf<Long, BooksFragment>()
|
private val fragmentMap = hashMapOf<Long, BooksFragment>()
|
||||||
private var groupsFlowJob: Job? = null
|
|
||||||
override val groupId: Long get() = selectedGroup?.groupId ?: 0
|
override val groupId: Long get() = selectedGroup?.groupId ?: 0
|
||||||
|
|
||||||
override val books: List<Book>
|
override val books: List<Book>
|
||||||
@ -73,15 +69,6 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
|||||||
binding.viewPagerBookshelf.adapter = adapter
|
binding.viewPagerBookshelf.adapter = adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initBookGroupData() {
|
|
||||||
groupsFlowJob?.cancel()
|
|
||||||
groupsFlowJob = launch {
|
|
||||||
appDb.bookGroupDao.flowShow().collect {
|
|
||||||
upGroup(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
SearchActivity.start(requireContext(), query)
|
SearchActivity.start(requireContext(), query)
|
||||||
return false
|
return false
|
||||||
@ -92,7 +79,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun upGroup(data: List<BookGroup>) {
|
override fun upGroup(data: List<BookGroup>) {
|
||||||
if (data.isEmpty()) {
|
if (data.isEmpty()) {
|
||||||
appDb.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
|
appDb.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,7 +52,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private var bookGroups: List<BookGroup> = emptyList()
|
private var bookGroups: List<BookGroup> = emptyList()
|
||||||
private var groupsFlowJob: Job? = null
|
|
||||||
private var booksFlowJob: Job? = null
|
private var booksFlowJob: Job? = null
|
||||||
override var groupId = AppConst.bookGroupNoneId
|
override var groupId = AppConst.bookGroupNoneId
|
||||||
override var books: List<Book> = emptyList()
|
override var books: List<Book> = emptyList()
|
||||||
@ -60,7 +59,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
|||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
setSupportToolbar(binding.titleBar.toolbar)
|
setSupportToolbar(binding.titleBar.toolbar)
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
initGroupData()
|
initBookGroupData()
|
||||||
initBooksData()
|
initBooksData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,18 +96,13 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun initGroupData() {
|
override fun upGroup(data: List<BookGroup>) {
|
||||||
groupsFlowJob?.cancel()
|
if (data != bookGroups) {
|
||||||
groupsFlowJob = launch {
|
bookGroups = data
|
||||||
appDb.bookGroupDao.flowShow().collect {
|
|
||||||
if (it != bookGroups) {
|
|
||||||
bookGroups = it
|
|
||||||
booksAdapter.notifyDataSetChanged()
|
booksAdapter.notifyDataSetChanged()
|
||||||
binding.tvEmptyMsg.isGone = getItemCount() > 0
|
binding.tvEmptyMsg.isGone = getItemCount() > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun initBooksData() {
|
private fun initBooksData() {
|
||||||
|
Loading…
Reference in New Issue
Block a user