Commit 6b41d825 authored by 周文华's avatar 周文华

【修复】1.修复空文件路径导致的崩溃。2.修复0不能作为除数的错误。3.修复没有权限导致的查询问题。

parent ef3aea2e
...@@ -213,7 +213,7 @@ object NotificationUiUtil { ...@@ -213,7 +213,7 @@ object NotificationUiUtil {
NOTIFICATION_ACTION_APP_PROCESS -> { NOTIFICATION_ACTION_APP_PROCESS -> {
val pair = MyApplication.context.ramPair() val pair = MyApplication.context.ramPair()
val percent = (pair.first * 100 / pair.second).toInt() val percent =if(pair.second>0) (pair.first * 100 / pair.second).toInt() else 0
val desc = "Memory is $percent% used" val desc = "Memory is $percent% used"
val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_memory_small_1) val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_memory_small_1)
......
...@@ -109,7 +109,10 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView { ...@@ -109,7 +109,10 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView {
binding.tvPdfName.text = file.name binding.tvPdfName.text = file.name
pdfPresenter = PdfPresenter(this) pdfPresenter = PdfPresenter(this)
if (!file.exists() && uri == null) {
finish()
return
}
initAdapter() initAdapter()
changeNormalUI() changeNormalUI()
......
...@@ -13,6 +13,7 @@ import com.base.pdfviewerscannerwhite.utils.XmlEx.inflate ...@@ -13,6 +13,7 @@ import com.base.pdfviewerscannerwhite.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter import com.chad.library.adapter4.BaseQuickAdapter
import com.tom_roush.pdfbox.pdmodel.PDDocument import com.tom_roush.pdfbox.pdmodel.PDDocument
import com.tom_roush.pdfbox.rendering.PDFRenderer import com.tom_roush.pdfbox.rendering.PDFRenderer
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
...@@ -55,7 +56,7 @@ class PdfPagerAdapter( ...@@ -55,7 +56,7 @@ class PdfPagerAdapter(
private val refreshPayLoad = 1 private val refreshPayLoad = 1
init { init {
scope.launch(SupervisorJob() + Dispatchers.IO) { scope.launch(CoroutineExceptionHandler { _, _ -> } + Dispatchers.IO) {
pdfDocument = PdfBoxUtils.getPdfDocument(pdfPath, mPassword, uri) pdfDocument = PdfBoxUtils.getPdfDocument(pdfPath, mPassword, uri)
pdfRender = PDFRenderer(pdfDocument) pdfRender = PDFRenderer(pdfDocument)
val dataList = mutableListOf<PdfPageBean>() val dataList = mutableListOf<PdfPageBean>()
......
...@@ -8,6 +8,7 @@ import com.base.pdfviewerscannerwhite.databinding.ActivityPdfSplitBinding ...@@ -8,6 +8,7 @@ import com.base.pdfviewerscannerwhite.databinding.ActivityPdfSplitBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.helper.MyApplication import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog
import java.io.File
class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView { class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView {
...@@ -70,6 +71,11 @@ class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView { ...@@ -70,6 +71,11 @@ class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView {
} }
private fun initAdapter() { private fun initAdapter() {
val file = File(path)
if (!file.exists()) {
finish()
return
}
pdfPagerAdapter = PdfPagerAdapter(path, null, R.layout.item_pdf_pager_split, 1.5f, mPassword = pwd) pdfPagerAdapter = PdfPagerAdapter(path, null, R.layout.item_pdf_pager_split, 1.5f, mPassword = pwd)
pdfPagerAdapter.selectAction = { enable, allSelect -> pdfPagerAdapter.selectAction = { enable, allSelect ->
binding.tvBtnSplit.isEnabled = enable binding.tvBtnSplit.isEnabled = enable
......
...@@ -415,7 +415,11 @@ fun CoroutineScope.queryFiles(context: Context, fileSuffix: String, flow: Mutabl ...@@ -415,7 +415,11 @@ fun CoroutineScope.queryFiles(context: Context, fileSuffix: String, flow: Mutabl
} else { } else {
MediaStore.Files.getContentUri("external") MediaStore.Files.getContentUri("external")
} }
val cursor = context.contentResolver.query(queryUri, projection, selection, null, sortOrder) val cursor =try {
context.contentResolver.query(queryUri, projection, selection, null, sortOrder)
} catch (e:SecurityException){
null
}
if (cursor != null) { if (cursor != null) {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
delay(150) delay(150)
......
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