通过数据库判断压缩文件是否在书架上
This commit is contained in:
@@ -44,9 +44,6 @@ interface BookDao {
|
|||||||
)
|
)
|
||||||
fun flowLocalNoGroup(): Flow<List<Book>>
|
fun flowLocalNoGroup(): Flow<List<Book>>
|
||||||
|
|
||||||
@Query("SELECT bookUrl FROM books WHERE type & ${BookType.local} > 0")
|
|
||||||
fun flowLocalUri(): Flow<List<String>>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
|
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
|
||||||
fun flowByGroup(group: Long): Flow<List<Book>>
|
fun flowByGroup(group: Long): Flow<List<Book>>
|
||||||
|
|
||||||
@@ -104,7 +101,7 @@ interface BookDao {
|
|||||||
@Query("select 1 from books where bookUrl = :bookUrl")
|
@Query("select 1 from books where bookUrl = :bookUrl")
|
||||||
fun has(bookUrl: String): Boolean?
|
fun has(bookUrl: String): Boolean?
|
||||||
|
|
||||||
@Query("select 1 from books where originName = :fileName")
|
@Query("select 1 from books where originName = :fileName or origin like ${BookType.localTag} || '::' || :fileName")
|
||||||
fun hasFile(fileName: String): Boolean?
|
fun hasFile(fileName: String): Boolean?
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
|||||||
@@ -131,11 +131,6 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
|
|||||||
viewModel.dataFlowStart = {
|
viewModel.dataFlowStart = {
|
||||||
initRootDoc()
|
initRootDoc()
|
||||||
}
|
}
|
||||||
launch {
|
|
||||||
appDb.bookDao.flowLocal().conflate().collect {
|
|
||||||
adapter.upBookHas(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
launch {
|
launch {
|
||||||
viewModel.dataFlow.conflate().collect { docs ->
|
viewModel.dataFlow.conflate().collect { docs ->
|
||||||
adapter.setItems(docs)
|
adapter.setItems(docs)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import io.legado.app.data.entities.Book
|
|||||||
import io.legado.app.databinding.ItemImportBookBinding
|
import io.legado.app.databinding.ItemImportBookBinding
|
||||||
import io.legado.app.help.book.archiveName
|
import io.legado.app.help.book.archiveName
|
||||||
import io.legado.app.help.book.isArchive
|
import io.legado.app.help.book.isArchive
|
||||||
|
import io.legado.app.model.localBook.LocalBook
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +20,6 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|||||||
RecyclerAdapter<FileDoc, ItemImportBookBinding>(context) {
|
RecyclerAdapter<FileDoc, ItemImportBookBinding>(context) {
|
||||||
val selectedUris = hashSetOf<String>()
|
val selectedUris = hashSetOf<String>()
|
||||||
var checkableCount = 0
|
var checkableCount = 0
|
||||||
private val bookOrArchiveNamesOnBookShelf = arrayListOf<String>()
|
|
||||||
|
|
||||||
override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
|
override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
|
||||||
return ItemImportBookBinding.inflate(inflater, parent, false)
|
return ItemImportBookBinding.inflate(inflater, parent, false)
|
||||||
@@ -87,26 +87,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isOnBookShelf(fileDoc: FileDoc): Boolean {
|
private fun isOnBookShelf(fileDoc: FileDoc): Boolean {
|
||||||
return bookOrArchiveNamesOnBookShelf.contains(fileDoc.name)
|
return LocalBook.isOnBookShelf(fileDoc.name)
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
|
||||||
fun upBookHas(books: List<Book>) {
|
|
||||||
bookOrArchiveNamesOnBookShelf.clear()
|
|
||||||
books.forEach {
|
|
||||||
if (it.isArchive) {
|
|
||||||
bookOrArchiveNamesOnBookShelf.add(
|
|
||||||
it.archiveName!!
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val path = Uri.decode(it.bookUrl)
|
|
||||||
bookOrArchiveNamesOnBookShelf.add(
|
|
||||||
FileUtils.getName(path)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notifyDataSetChanged()
|
|
||||||
upCheckableCount()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun upCheckableCount() {
|
private fun upCheckableCount() {
|
||||||
|
|||||||
Reference in New Issue
Block a user