Commit 66f0c395 authored by 周文华's avatar 周文华

【修复】修复分解、合并页面,加锁状态与空文件问题

parent 6698b57f
......@@ -13,6 +13,7 @@ import com.base.pdfviewerscannerwhite.utils.getMediaFile
import com.base.pdfviewerscannerwhite.utils.upDateDemoStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
class DocumentPresenter(
......@@ -37,19 +38,23 @@ class DocumentPresenter(
if (type == DocumentBean.TYPE_PDF) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".pdf") }?.absolutePath ?: ""
demoDocumentBean.path =
demoFile.listFiles()?.find { it.name.contains(".pdf") }?.absolutePath ?: ""
}
if (type == DocumentBean.TYPE_WORD) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_DOC, ConstObject.MIME_TYPE_DOCX)
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".docx") }?.absolutePath ?: ""
demoDocumentBean.path =
demoFile.listFiles()?.find { it.name.contains(".docx") }?.absolutePath ?: ""
}
if (type == DocumentBean.TYPE_EXCEL) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_XLS, ConstObject.MIME_TYPE_XLSX)
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".xlsx") }?.absolutePath ?: ""
demoDocumentBean.path =
demoFile.listFiles()?.find { it.name.contains(".xlsx") }?.absolutePath ?: ""
}
if (type == DocumentBean.TYPE_PPT) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PPT, ConstObject.MIME_TYPE_PPTX)
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".pptx") }?.absolutePath ?: ""
demoDocumentBean.path =
demoFile.listFiles()?.find { it.name.contains(".pptx") }?.absolutePath ?: ""
}
demoDocumentBean.type = type
......@@ -57,7 +62,12 @@ class DocumentPresenter(
val list = context.getMediaFile(selectionArgs = selectionArgs)
val documentList = list.map {
DocumentBean(it.path, uri = it.uri, type = type, isBookmarked = bookmarkList.contains(it.path))
DocumentBean(
it.path,
uri = it.uri,
type = type,
isBookmarked = bookmarkList.contains(it.path)
)
}
val new = documentList.toMutableList()
if (File(demoDocumentBean.path).exists()) {
......@@ -68,31 +78,45 @@ class DocumentPresenter(
fun initData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList()
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(documentList)
val realList = documentList.filter {
val file = File(it.path)
file.exists() && file.length() > 0
}
realList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path)
}
withContext(Dispatchers.Main) {
documentView.refreshDocumentRv(realList)
}
}
fun initUnLockData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList()
documentList.forEach {
val realList = documentList.filter {
val file = File(it.path)
file.exists() && file.length() > 0
}
realList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path)
}
val list = documentList.filter { it.state == 0 }
launch(Dispatchers.Main) {
val list = realList.filter { it.state == 0 }
withContext(Dispatchers.Main) {
documentView.refreshDocumentRv(list)
}
}
fun initLoadData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList()
documentList.forEach {
val realList= documentList.filter {
val file = File(it.path)
file.exists() && file.length() > 0
}
realList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path)
}
val list = documentList.filter { it.state == 1 }
launch(Dispatchers.Main) {
val list = realList.filter { it.state == 1 }
withContext(Dispatchers.Main) {
documentView.refreshDocumentRv(list)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment