|
@@ -8,7 +8,10 @@ import io.legado.app.R
|
|
|
import io.legado.app.base.adapter.ItemViewHolder
|
|
import io.legado.app.base.adapter.ItemViewHolder
|
|
|
import io.legado.app.base.adapter.RecyclerAdapter
|
|
import io.legado.app.base.adapter.RecyclerAdapter
|
|
|
import io.legado.app.constant.AppConst
|
|
import io.legado.app.constant.AppConst
|
|
|
|
|
+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.isArchive
|
|
|
import io.legado.app.utils.*
|
|
import io.legado.app.utils.*
|
|
|
|
|
|
|
|
|
|
|
|
@@ -16,7 +19,7 @@ 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 bookNamesOnBookShelf = arrayListOf<String>()
|
|
|
|
|
|
|
+ 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)
|
|
@@ -41,7 +44,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
llBrief.gone()
|
|
llBrief.gone()
|
|
|
cbSelect.isChecked = false
|
|
cbSelect.isChecked = false
|
|
|
} else {
|
|
} else {
|
|
|
- if (bookNamesOnBookShelf.contains(item.name)) {
|
|
|
|
|
|
|
+ if (isOnBookShelf(item)) {
|
|
|
ivIcon.setImageResource(R.drawable.ic_book_has)
|
|
ivIcon.setImageResource(R.drawable.ic_book_has)
|
|
|
ivIcon.visible()
|
|
ivIcon.visible()
|
|
|
cbSelect.invisible()
|
|
cbSelect.invisible()
|
|
@@ -67,7 +70,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
getItem(holder.layoutPosition)?.let {
|
|
getItem(holder.layoutPosition)?.let {
|
|
|
if (it.isDir) {
|
|
if (it.isDir) {
|
|
|
callBack.nextDoc(it)
|
|
callBack.nextDoc(it)
|
|
|
- } else if (!bookNamesOnBookShelf.contains(it.name)) {
|
|
|
|
|
|
|
+ } else if (!isOnBookShelf(it)) {
|
|
|
if (!selectedUris.contains(it.toString())) {
|
|
if (!selectedUris.contains(it.toString())) {
|
|
|
selectedUris.add(it.toString())
|
|
selectedUris.add(it.toString())
|
|
|
} else {
|
|
} else {
|
|
@@ -77,18 +80,30 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
callBack.upCountView()
|
|
callBack.upCountView()
|
|
|
} else {
|
|
} else {
|
|
|
/* 点击开始阅读 */
|
|
/* 点击开始阅读 */
|
|
|
- callBack.startRead(it.toString())
|
|
|
|
|
|
|
+ callBack.startRead(it)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun isOnBookShelf(fileDoc: FileDoc): Boolean {
|
|
|
|
|
+ return bookOrArchiveNamesOnBookShelf.contains(fileDoc.name)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
- fun upBookHas(bookUrls: List<String>) {
|
|
|
|
|
- bookNamesOnBookShelf.clear()
|
|
|
|
|
- bookUrls.forEach {
|
|
|
|
|
- val path = Uri.decode(it)
|
|
|
|
|
- bookNamesOnBookShelf.add(FileUtils.getName(path))
|
|
|
|
|
|
|
+ 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()
|
|
notifyDataSetChanged()
|
|
|
upCheckableCount()
|
|
upCheckableCount()
|
|
@@ -97,7 +112,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
private fun upCheckableCount() {
|
|
private fun upCheckableCount() {
|
|
|
checkableCount = 0
|
|
checkableCount = 0
|
|
|
getItems().forEach {
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
|
|
|
|
|
|
+ if (!it.isDir && !isOnBookShelf(it)) {
|
|
|
checkableCount++
|
|
checkableCount++
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -108,7 +123,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
fun selectAll(selectAll: Boolean) {
|
|
fun selectAll(selectAll: Boolean) {
|
|
|
if (selectAll) {
|
|
if (selectAll) {
|
|
|
getItems().forEach {
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
|
|
|
|
|
|
+ if (!it.isDir && !isOnBookShelf(it)) {
|
|
|
selectedUris.add(it.toString())
|
|
selectedUris.add(it.toString())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -121,7 +136,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
|
|
|
|
|
fun revertSelection() {
|
|
fun revertSelection() {
|
|
|
getItems().forEach {
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
|
|
|
|
|
|
+ if (!it.isDir && !isOnBookShelf(it)) {
|
|
|
if (selectedUris.contains(it.toString())) {
|
|
if (selectedUris.contains(it.toString())) {
|
|
|
selectedUris.remove(it.toString())
|
|
selectedUris.remove(it.toString())
|
|
|
} else {
|
|
} else {
|
|
@@ -144,7 +159,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
interface CallBack {
|
|
interface CallBack {
|
|
|
fun nextDoc(fileDoc: FileDoc)
|
|
fun nextDoc(fileDoc: FileDoc)
|
|
|
fun upCountView()
|
|
fun upCountView()
|
|
|
- fun startRead(bookUrl: String)
|
|
|
|
|
|
|
+ fun startRead(fileDoc: FileDoc)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|