修复bug,修改低版本手机的权限问题。

This commit is contained in:
ocean 2025-10-27 17:09:46 +08:00
parent 93d0bb3236
commit 88b1b82c86
3 changed files with 19 additions and 8 deletions

View File

@ -155,7 +155,7 @@ class PdfViewActivity : BaseActivity(), OnLoadCompleteListener, OnPageChangeList
viewModel.fileActionEvent.observeEvent<FileActionEvent.SetPageFling>(this) { event -> viewModel.fileActionEvent.observeEvent<FileActionEvent.SetPageFling>(this) { event ->
val file = File(pdfDocument.filePath) val file = File(pdfDocument.filePath)
loadPdfInternal(file, null) loadPdfInternal(file, currentPassword)
} }
viewModel.fileActionEvent.observeEvent<FileActionEvent.SetColorInversion>(this) { event -> viewModel.fileActionEvent.observeEvent<FileActionEvent.SetColorInversion>(this) { event ->
@ -340,7 +340,6 @@ class PdfViewActivity : BaseActivity(), OnLoadCompleteListener, OnPageChangeList
private fun showPasswordDialog(file: File) { private fun showPasswordDialog(file: File) {
PdfPasswordProtectionDialogFragment(file, onOkClick = { password -> PdfPasswordProtectionDialogFragment(file, onOkClick = { password ->
tryLoadPdfWithPassword(file, password) tryLoadPdfWithPassword(file, password)
currentPassword = password
}, onCancelClick = { }, onCancelClick = {
finish() finish()
}).show(supportFragmentManager, TAG) }).show(supportFragmentManager, TAG)
@ -348,6 +347,7 @@ class PdfViewActivity : BaseActivity(), OnLoadCompleteListener, OnPageChangeList
private fun tryLoadPdfWithPassword(file: File, password: String) { private fun tryLoadPdfWithPassword(file: File, password: String) {
loadPdfInternal(file, password) // 传入密码 loadPdfInternal(file, password) // 传入密码
currentPassword = password
} }
private fun loadPdfInternal(file: File, password: String?) { private fun loadPdfInternal(file: File, password: String?) {

View File

@ -27,13 +27,21 @@ object StoragePermissionHelper {
Manifest.permission.READ_MEDIA_VIDEO Manifest.permission.READ_MEDIA_VIDEO
) )
} }
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
// Android 11-12 // Android 11-12
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
} }
else -> { else -> {
// Android 10及以下 // Android 10及以下
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
} }
} }
} }
@ -47,7 +55,10 @@ object StoragePermissionHelper {
// Android 10及以下检查基本存储权限 // Android 10及以下检查基本存储权限
val permissions = getRequiredPermissions() val permissions = getRequiredPermissions()
permissions.all { permission -> permissions.all { permission ->
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED ContextCompat.checkSelfPermission(
context,
permission
) == PackageManager.PERMISSION_GRANTED
} }
} }
} }

View File

@ -44,7 +44,7 @@ class PdfViewModel : ViewModel() {
//触发修改文件名操作 //触发修改文件名操作
fun renamePdf(filePath: String, newName: String) { fun renamePdf(filePath: String, newName: String) {
viewModelScope.launch { viewModelScope.launch(Dispatchers.IO) {
val oldFile = File(filePath) val oldFile = File(filePath)
val renameResult = FileUtils.renameFile(oldFile, newName) val renameResult = FileUtils.renameFile(oldFile, newName)
Log.d( Log.d(
@ -77,7 +77,7 @@ class PdfViewModel : ViewModel() {
} }
fun deleteFile(filePath: String) { fun deleteFile(filePath: String) {
viewModelScope.launch { viewModelScope.launch(Dispatchers.IO) {
val file = File(filePath) val file = File(filePath)
val deleteResult = FileDeleteUtil.deleteFile(file) val deleteResult = FileDeleteUtil.deleteFile(file)
Log.d("ocean", "deleteFile->file: $file, deleteResult=$deleteResult") Log.d("ocean", "deleteFile->file: $file, deleteResult=$deleteResult")
@ -128,7 +128,7 @@ class PdfViewModel : ViewModel() {
} }
fun duplicateFile(context: Context, filePath: String) { fun duplicateFile(context: Context, filePath: String) {
viewModelScope.launch { viewModelScope.launch(Dispatchers.IO) {
val file = FileUtils.duplicateFile(File(filePath)) val file = FileUtils.duplicateFile(File(filePath))
Log.d("ocean", "duplicateFile->$file") Log.d("ocean", "duplicateFile->$file")
if (file != null) { if (file != null) {