|
@@ -16,7 +16,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 bookFileNames = arrayListOf<String>()
|
|
|
|
|
|
|
+ private val bookNamesOnBookShelf = 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 +41,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
llBrief.gone()
|
|
llBrief.gone()
|
|
|
cbSelect.isChecked = false
|
|
cbSelect.isChecked = false
|
|
|
} else {
|
|
} else {
|
|
|
- if (bookFileNames.contains(item.name)) {
|
|
|
|
|
|
|
+ if (bookNamesOnBookShelf.contains(item.name)) {
|
|
|
ivIcon.setImageResource(R.drawable.ic_book_has)
|
|
ivIcon.setImageResource(R.drawable.ic_book_has)
|
|
|
ivIcon.visible()
|
|
ivIcon.visible()
|
|
|
cbSelect.invisible()
|
|
cbSelect.invisible()
|
|
@@ -67,7 +67,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 (!bookFileNames.contains(it.name)) {
|
|
|
|
|
|
|
+ } else if (!bookNamesOnBookShelf.contains(it.name)) {
|
|
|
if (!selectedUris.contains(it.toString())) {
|
|
if (!selectedUris.contains(it.toString())) {
|
|
|
selectedUris.add(it.toString())
|
|
selectedUris.add(it.toString())
|
|
|
} else {
|
|
} else {
|
|
@@ -75,6 +75,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
}
|
|
}
|
|
|
notifyItemChanged(holder.layoutPosition, true)
|
|
notifyItemChanged(holder.layoutPosition, true)
|
|
|
callBack.upCountView()
|
|
callBack.upCountView()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ /* 点击开始阅读 */
|
|
|
|
|
+ callBack.startRead(it.toString())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -82,10 +85,10 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
fun upBookHas(bookUrls: List<String>) {
|
|
fun upBookHas(bookUrls: List<String>) {
|
|
|
- bookFileNames.clear()
|
|
|
|
|
|
|
+ bookNamesOnBookShelf.clear()
|
|
|
bookUrls.forEach {
|
|
bookUrls.forEach {
|
|
|
val path = Uri.decode(it)
|
|
val path = Uri.decode(it)
|
|
|
- bookFileNames.add(FileUtils.getName(path))
|
|
|
|
|
|
|
+ bookNamesOnBookShelf.add(FileUtils.getName(path))
|
|
|
}
|
|
}
|
|
|
notifyDataSetChanged()
|
|
notifyDataSetChanged()
|
|
|
upCheckableCount()
|
|
upCheckableCount()
|
|
@@ -94,7 +97,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 && !bookFileNames.contains(it.name)) {
|
|
|
|
|
|
|
+ if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
|
|
checkableCount++
|
|
checkableCount++
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -105,7 +108,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 && !bookFileNames.contains(it.name)) {
|
|
|
|
|
|
|
+ if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
|
|
selectedUris.add(it.toString())
|
|
selectedUris.add(it.toString())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -118,7 +121,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
|
|
|
|
|
|
|
fun revertSelection() {
|
|
fun revertSelection() {
|
|
|
getItems().forEach {
|
|
getItems().forEach {
|
|
|
- if (!it.isDir && !bookFileNames.contains(it.name)) {
|
|
|
|
|
|
|
+ if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
|
|
if (selectedUris.contains(it.toString())) {
|
|
if (selectedUris.contains(it.toString())) {
|
|
|
selectedUris.remove(it.toString())
|
|
selectedUris.remove(it.toString())
|
|
|
} else {
|
|
} else {
|
|
@@ -141,6 +144,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)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|