|
|
@@ -9,12 +9,18 @@ import io.legado.app.base.adapter.RecyclerAdapter
|
|
|
import io.legado.app.constant.AppConst
|
|
|
import io.legado.app.databinding.ItemImportBookBinding
|
|
|
import io.legado.app.model.localBook.LocalBook
|
|
|
-import io.legado.app.utils.*
|
|
|
+import io.legado.app.utils.ConvertUtils
|
|
|
+import io.legado.app.utils.FileDoc
|
|
|
+import io.legado.app.utils.gone
|
|
|
+import io.legado.app.utils.invisible
|
|
|
+import io.legado.app.utils.visible
|
|
|
+import kotlinx.coroutines.CoroutineScope
|
|
|
+import kotlinx.coroutines.Job
|
|
|
|
|
|
|
|
|
class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
- RecyclerAdapter<FileDoc, ItemImportBookBinding>(context) {
|
|
|
- val selectedUris = hashSetOf<String>()
|
|
|
+ RecyclerAdapter<ImportBook, ItemImportBookBinding>(context) {
|
|
|
+ val selected = hashSetOf<ImportBook>()
|
|
|
var checkableCount = 0
|
|
|
|
|
|
override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
|
|
|
@@ -28,7 +34,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
override fun convert(
|
|
|
holder: ItemViewHolder,
|
|
|
binding: ItemImportBookBinding,
|
|
|
- item: FileDoc,
|
|
|
+ item: ImportBook,
|
|
|
payloads: MutableList<Any>
|
|
|
) {
|
|
|
binding.run {
|
|
|
@@ -40,7 +46,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
llBrief.gone()
|
|
|
cbSelect.isChecked = false
|
|
|
} else {
|
|
|
- if (isOnBookShelf(item)) {
|
|
|
+ if (item.isOnBookShelf) {
|
|
|
ivIcon.setImageResource(R.drawable.ic_book_has)
|
|
|
ivIcon.visible()
|
|
|
cbSelect.invisible()
|
|
|
@@ -52,11 +58,11 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
tvTag.text = item.name.substringAfterLast(".")
|
|
|
tvSize.text = ConvertUtils.formatFileSize(item.size)
|
|
|
tvDate.text = AppConst.dateFormat.format(item.lastModified)
|
|
|
- cbSelect.isChecked = selectedUris.contains(item.toString())
|
|
|
+ cbSelect.isChecked = selected.contains(item)
|
|
|
}
|
|
|
tvName.text = item.name
|
|
|
} else {
|
|
|
- cbSelect.isChecked = selectedUris.contains(item.toString())
|
|
|
+ cbSelect.isChecked = selected.contains(item)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -65,18 +71,18 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
holder.itemView.setOnClickListener {
|
|
|
getItem(holder.layoutPosition)?.let {
|
|
|
if (it.isDir) {
|
|
|
- callBack.nextDoc(it)
|
|
|
- } else if (!isOnBookShelf(it)) {
|
|
|
- if (!selectedUris.contains(it.toString())) {
|
|
|
- selectedUris.add(it.toString())
|
|
|
+ callBack.nextDoc(it.file)
|
|
|
+ } else if (!it.isOnBookShelf) {
|
|
|
+ if (!selected.contains(it)) {
|
|
|
+ selected.add(it)
|
|
|
} else {
|
|
|
- selectedUris.remove(it.toString())
|
|
|
+ selected.remove(it)
|
|
|
}
|
|
|
notifyItemChanged(holder.layoutPosition, true)
|
|
|
callBack.upCountView()
|
|
|
} else {
|
|
|
/* 点击开始阅读 */
|
|
|
- callBack.startRead(it)
|
|
|
+ callBack.startRead(it.file)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -89,7 +95,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
private fun upCheckableCount() {
|
|
|
checkableCount = 0
|
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !isOnBookShelf(it)) {
|
|
|
+ if (!it.isDir && !it.isOnBookShelf) {
|
|
|
checkableCount++
|
|
|
}
|
|
|
}
|
|
|
@@ -100,12 +106,12 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
fun selectAll(selectAll: Boolean) {
|
|
|
if (selectAll) {
|
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !isOnBookShelf(it)) {
|
|
|
- selectedUris.add(it.toString())
|
|
|
+ if (!it.isDir && !it.isOnBookShelf) {
|
|
|
+ selected.add(it)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- selectedUris.clear()
|
|
|
+ selected.clear()
|
|
|
}
|
|
|
notifyDataSetChanged()
|
|
|
callBack.upCountView()
|
|
|
@@ -113,11 +119,11 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
|
|
|
fun revertSelection() {
|
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !isOnBookShelf(it)) {
|
|
|
- if (selectedUris.contains(it.toString())) {
|
|
|
- selectedUris.remove(it.toString())
|
|
|
+ if (!it.isDir && !it.isOnBookShelf) {
|
|
|
+ if (selected.contains(it)) {
|
|
|
+ selected.remove(it)
|
|
|
} else {
|
|
|
- selectedUris.add(it.toString())
|
|
|
+ selected.add(it)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -127,7 +133,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
|
|
|
fun removeSelection() {
|
|
|
for (i in getItems().lastIndex downTo 0) {
|
|
|
- if (getItem(i)?.toString() in selectedUris) {
|
|
|
+ if (getItem(i) in selected) {
|
|
|
removeItem(i)
|
|
|
}
|
|
|
}
|