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

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

parent 6698b57f
...@@ -13,6 +13,7 @@ import com.base.pdfviewerscannerwhite.utils.getMediaFile ...@@ -13,6 +13,7 @@ import com.base.pdfviewerscannerwhite.utils.getMediaFile
import com.base.pdfviewerscannerwhite.utils.upDateDemoStore import com.base.pdfviewerscannerwhite.utils.upDateDemoStore
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
class DocumentPresenter( class DocumentPresenter(
...@@ -37,19 +38,23 @@ class DocumentPresenter( ...@@ -37,19 +38,23 @@ class DocumentPresenter(
if (type == DocumentBean.TYPE_PDF) { if (type == DocumentBean.TYPE_PDF) {
selectionArgs = arrayOf(ConstObject.MIME_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) { if (type == DocumentBean.TYPE_WORD) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_DOC, ConstObject.MIME_TYPE_DOCX) 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) { if (type == DocumentBean.TYPE_EXCEL) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_XLS, ConstObject.MIME_TYPE_XLSX) 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) { if (type == DocumentBean.TYPE_PPT) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PPT, ConstObject.MIME_TYPE_PPTX) 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 demoDocumentBean.type = type
...@@ -57,7 +62,12 @@ class DocumentPresenter( ...@@ -57,7 +62,12 @@ class DocumentPresenter(
val list = context.getMediaFile(selectionArgs = selectionArgs) val list = context.getMediaFile(selectionArgs = selectionArgs)
val documentList = list.map { 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() val new = documentList.toMutableList()
if (File(demoDocumentBean.path).exists()) { if (File(demoDocumentBean.path).exists()) {
...@@ -68,31 +78,45 @@ class DocumentPresenter( ...@@ -68,31 +78,45 @@ class DocumentPresenter(
fun initData() = lifecycleScope.launch(Dispatchers.IO) { fun initData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList() val documentList = getDocumentBeanList()
val realList = documentList.filter {
launch(Dispatchers.Main) { val file = File(it.path)
documentView.refreshDocumentRv(documentList) 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) { fun initUnLockData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList() 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) it.state = PdfBoxUtils.checkPdfEncryption(it.path)
} }
val list = documentList.filter { it.state == 0 } val list = realList.filter { it.state == 0 }
launch(Dispatchers.Main) { withContext(Dispatchers.Main) {
documentView.refreshDocumentRv(list) documentView.refreshDocumentRv(list)
} }
} }
fun initLoadData() = lifecycleScope.launch(Dispatchers.IO) { fun initLoadData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList() 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) it.state = PdfBoxUtils.checkPdfEncryption(it.path)
} }
val list = documentList.filter { it.state == 1 } val list = realList.filter { it.state == 1 }
launch(Dispatchers.Main) { withContext(Dispatchers.Main) {
documentView.refreshDocumentRv(list) 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