Forráskód Böngészése

PDFTool(Android) - 优化相机权限流程

liuxiaolong 9 hónapja
szülő
commit
0daed3cd9d

+ 13 - 9
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfpic/CImageStyleFragment.java

@@ -58,17 +58,21 @@ public class CImageStyleFragment extends CBasicPropertiesFragment {
             imageLauncher.launch(CImageResultContracts.RequestType.PHOTO_ALBUM);
         });
         clFromCamera.setOnClickListener(v -> {
-            permissionResultLauncher.launch(Manifest.permission.CAMERA, granted -> {
-                if (granted){
-                    imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
-                } else {
-                    if (getActivity() != null) {
-                        if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.CAMERA)) {
-                            CPermissionUtil.showPermissionsRequiredDialog(getChildFragmentManager(), getActivity());
+            if (!CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.CAMERA)){
+                imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
+            }else {
+                permissionResultLauncher.launch(Manifest.permission.CAMERA, granted -> {
+                    if (granted){
+                        imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
+                    } else {
+                        if (getActivity() != null) {
+                            if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.CAMERA)) {
+                                CPermissionUtil.showPermissionsRequiredDialog(getChildFragmentManager(), getActivity());
+                            }
                         }
                     }
-                }
-            });
+                });
+            }
         });
         return rootView;
     }

+ 7 - 32
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/pdf/CPDFDocumentFragment.java

@@ -278,7 +278,7 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
             }
         });
         pdfView.setOnTapMainDocAreaCallback(() -> {
-            if (pdfSearchToolBarView.getVisibility() == VISIBLE){
+            if (pdfSearchToolBarView.getVisibility() == VISIBLE) {
                 pdfSearchToolBarView.showSearchReplaceContextMenu();
                 return;
             }
@@ -655,12 +655,12 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
             File file = new File(dir, CFileUtils.getFileNameNoExtension(document.getFileName()) + getString(R.string.tools_flattened_suffix));
             file = CFileUtils.renameNameSuffix(file);
             File finalFile = file;
-            CThreadPoolUtils.getInstance().executeIO(() ->{
+            CThreadPoolUtils.getInstance().executeIO(() -> {
                 boolean result = document.flattenAllPages(CPDFPage.PDFFlattenOption.FLAT_NORMALDISPLAY);
                 if (result) {
                     try {
                         boolean saveResult = document.saveAs(finalFile.getAbsolutePath(), false);
-                        CThreadPoolUtils.getInstance().executeMain(()->{
+                        CThreadPoolUtils.getInstance().executeMain(() -> {
                             dismissLoadingDialog();
                             if (saveResult) {
                                 CToastUtil.showLongToast(getContext(), R.string.tools_save_success);
@@ -678,7 +678,7 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
-                }else {
+                } else {
                     dismissLoadingDialog();
                 }
             });
@@ -743,34 +743,9 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
     }
 
     private void onDoNext() {
-        if (CPermissionUtil.hasStoragePermissions(getContext())) {
-            return;
-        }
-        if (Build.VERSION.SDK_INT >= CPermissionUtil.VERSION_TIRAMISU) {
-            if (CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.MANAGE_EXTERNAL_STORAGE)){
-                requestManageStoragePermission.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
-            }
-        } else if (Build.VERSION.SDK_INT >= CPermissionUtil.VERSION_R) {
-            multiplePermissionResultLauncher.launch(STORAGE_PERMISSIONS, result -> {
-                if (CPermissionUtil.hasStoragePermissions(getContext())) {
-                    initDocument(null);
-                } else {
-                    if (!Environment.isExternalStorageManager() && CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.MANAGE_EXTERNAL_STORAGE)) {
-                        requestManageStoragePermission.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
-                    }
-                }
-            });
-        } else {
-            multiplePermissionResultLauncher.launch(STORAGE_PERMISSIONS, result -> {
-                if (CPermissionUtil.hasStoragePermissions(getContext())) {
-                    initDocument(null);
-                } else {
-                    if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
-                        showPermissionsRequiredDialog();
-                    }
-                }
-            });
-        }
+        multiplePermissionResultLauncher.launch(STORAGE_PERMISSIONS, result -> {
+
+        });
     }
 
     private void showSettingEncryptionDialog() {

+ 13 - 9
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/utils/dialog/CImportImageDialogFragment.java

@@ -74,17 +74,21 @@ public class CImportImageDialogFragment extends CBasicBottomSheetDialogFragment
             imageLauncher.launch(CImageResultContracts.RequestType.PHOTO_ALBUM);
         });
         clFromCamera.setOnClickListener(v -> {
-            permissionResultLauncher.launch(Manifest.permission.CAMERA, granted -> {
-                if (granted) {
-                    imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
-                } else {
-                    if (getActivity() != null) {
-                        if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.CAMERA)) {
-                            CPermissionUtil.showPermissionsRequiredDialog(getChildFragmentManager(), getActivity());
+            if (!CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.CAMERA)){
+                imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
+            }else {
+                permissionResultLauncher.launch(Manifest.permission.CAMERA, granted -> {
+                    if (granted) {
+                        imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
+                    } else {
+                        if (getActivity() != null) {
+                            if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.CAMERA)) {
+                                CPermissionUtil.showPermissionsRequiredDialog(getChildFragmentManager(), getActivity());
+                            }
                         }
                     }
-                }
-            });
+                });
+            }
         });
     }
 

+ 13 - 9
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/security/watermark/pdfproperties/CWatermarkImageStyleFragment.java

@@ -172,17 +172,21 @@ public class CWatermarkImageStyleFragment extends CBasicPropertiesFragment imple
         } else if (v.getId() == R.id.iv_from_album) {
              imageLauncher.launch(CImageResultContracts.RequestType.PHOTO_ALBUM);
          } else if (v.getId() == R.id.iv_from_camera) {
-             permissionResultLauncher.launch(Manifest.permission.CAMERA, granted -> {
-                 if (granted){
-                     imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
-                 } else {
-                     if (getActivity() != null) {
-                         if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.CAMERA)) {
-                             CPermissionUtil.showPermissionsRequiredDialog(getChildFragmentManager(), getActivity());
+             if (!CPermissionUtil.checkManifestPermission(getContext(), Manifest.permission.CAMERA)){
+                 imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
+             }else {
+                 permissionResultLauncher.launch(Manifest.permission.CAMERA, granted -> {
+                     if (granted) {
+                         imageLauncher.launch(CImageResultContracts.RequestType.CAMERA);
+                     } else {
+                         if (getActivity() != null) {
+                             if (!CPermissionUtil.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.CAMERA)) {
+                                 CPermissionUtil.showPermissionsRequiredDialog(getChildFragmentManager(), getActivity());
+                             }
                          }
                      }
-                 }
-             });
+                 });
+             }
          }
     }
 }