Browse Source

PDFTool(Android) - p1 bug修复

liuxiaolong 11 months ago
parent
commit
44d849e676

BIN
ComPDFKit_Repo/compdfkit-ui/ComPDFKit-UI.aar


BIN
ComPDFKit_Repo/compdfkit/ComPDFKit.aar


BIN
ComPDFKit_Tools/libs/ComPDFKit-UI.aar


BIN
ComPDFKit_Tools/libs/ComPDFKit.aar


+ 16 - 19
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationbar/CAnnotationToolbar.java

@@ -93,9 +93,6 @@ public class CAnnotationToolbar extends FrameLayout {
         toolListAdapter = new CPDFAnnotationToolListAdapter();
         rvAnnotationList.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
         rvAnnotationList.setAdapter(toolListAdapter);
-        if (isInEditMode()) {
-            setTools(Arrays.asList(AnnotationsConfig.AnnotationTools.Setting, AnnotationsConfig.AnnotationTools.Undo, AnnotationsConfig.AnnotationTools.Redo));
-        }
         initListener();
     }
 
@@ -120,7 +117,7 @@ public class CAnnotationToolbar extends FrameLayout {
                 }
             }
         });
-        redoUndoManager();
+//        redoUndoManager();
     }
 
     public void setFragmentManager(FragmentManager fragmentManager) {
@@ -219,6 +216,7 @@ public class CAnnotationToolbar extends FrameLayout {
     private Handler handler = new Handler(Looper.getMainLooper());
 
     private void redoUndoManager() {
+        pdfView.getCPdfReaderView().getUndoManager().enable(true);
         CPDFUndoManager undoManager = pdfView.getCPdfReaderView().getUndoManager();
         if (ivRedo != null) {
             ivRedo.setEnabled(undoManager.canRedo());
@@ -226,25 +224,23 @@ public class CAnnotationToolbar extends FrameLayout {
         if (ivUndo != null) {
             ivUndo.setEnabled(undoManager.canRedo());
         }
-        pdfView.getCPdfReaderView().getUndoManager().enable(true);
         pdfView.getCPdfReaderView().getUndoManager().addOnUndoHistoryChangeListener((cpdfUndoManager, operation, type) -> {
             boolean canUndo = cpdfUndoManager.canUndo();
             boolean canRedo = cpdfUndoManager.canRedo();
-            handler.post(() -> {
-                if (ivUndo != null) {
-                    ivUndo.setEnabled(canUndo);
-                }
-                if (ivRedo != null) {
-                    ivRedo.setEnabled(canRedo);
-                }
-            });
+            if (ivUndo != null) {
+                ivUndo.setEnabled(canUndo);
+            }
+            if (ivRedo != null) {
+                ivRedo.setEnabled(canRedo);
+            }
         });
     }
 
     private void undo() {
         try {
-            if (pdfView != null) {
-                pdfView.getCPdfReaderView().getUndoManager().undo();
+            CPDFUndoManager undoManager = pdfView.getCPdfReaderView().getUndoManager();
+            if (undoManager.canUndo()) {
+                undoManager.undo();
             }
         } catch (Exception e) {
         }
@@ -252,8 +248,9 @@ public class CAnnotationToolbar extends FrameLayout {
 
     private void redo() {
         try {
-            if (pdfView != null) {
-                pdfView.getCPdfReaderView().getUndoManager().redo();
+            CPDFUndoManager undoManager = pdfView.getCPdfReaderView().getUndoManager();
+            if (undoManager.canRedo()) {
+                undoManager.redo();
             }
         } catch (Exception e) {
 
@@ -290,14 +287,14 @@ public class CAnnotationToolbar extends FrameLayout {
 
     public void setTools(List<AnnotationsConfig.AnnotationTools> tools) {
         llAnnotTools.setVisibility(tools != null && tools.size() > 0 ? VISIBLE : GONE);
-        if(tools != null && tools.size() > 0){
+        if (tools != null && tools.size() > 0) {
             tools = CListUtil.distinct(tools);
         }
         for (AnnotationsConfig.AnnotationTools tool : tools) {
             AppCompatImageView toolView = (AppCompatImageView) LayoutInflater.from(getContext())
                     .inflate(R.layout.tools_annot_tool_bar_tools_item, null);
             LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
-                    CDimensUtils.dp2px(getContext(), 30),CDimensUtils.dp2px(getContext(), 30)
+                    CDimensUtils.dp2px(getContext(), 30), CDimensUtils.dp2px(getContext(), 30)
             );
             layoutParams.setMarginStart(CDimensUtils.dp2px(getContext(), 12));
             toolView.setLayoutParams(layoutParams);

+ 7 - 12
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfnote/CPDFtextAnnotAttachHelper.java

@@ -23,23 +23,18 @@ public class CPDFtextAnnotAttachHelper extends CPDFTextAnnotAttachHelper {
     protected void onAddTextAnnot(CPDFTextAnnotImpl cpdfTextAnnot) {
         cpdfTextAnnot.setFocused(true);
         CNoteEditDialog editDialog = CNoteEditDialog.newInstance("");
-        editDialog.setDismissListener(new CNoteEditDialog.DialogDismiss() {
-            @Override
-            public void onDialogDismiss() {
-                String content = editDialog.getContent();
-                cpdfTextAnnot.onGetAnnotation().setContent(content);
-            }
+        editDialog.setDismissListener(() -> {
+            String content = editDialog.getContent();
+            cpdfTextAnnot.onGetAnnotation().setContent(content);
         });
         editDialog.setSaveListener(v -> {
-            readerView.setTouchMode(CPDFReaderView.TouchMode.BROWSE);
-            readerView.setCurrentFocusedType(CPDFAnnotation.Type.UNKNOWN);
-            pageView.setFocusAnnot(cpdfTextAnnot);
-
             String content = editDialog.getContent();
             cpdfTextAnnot.onGetAnnotation().setContent(content);
-            cpdfTextAnnot.onGetAnnotation().updateAp();
-            pageView.invalidate();
             editDialog.dismiss();
+
+            readerView.setCurrentFocusedType(CPDFAnnotation.Type.UNKNOWN);
+            readerView.setTouchMode(CPDFReaderView.TouchMode.BROWSE);
+            pageView.setFocusAnnot(cpdfTextAnnot);
         });
         editDialog.setDeleteListener(v -> {
             pageView.deleteAnnotation(cpdfTextAnnot);

+ 2 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfnote/CPDFtextAnnotImpl.java

@@ -29,7 +29,8 @@ public class CPDFtextAnnotImpl extends CPDFTextAnnotImpl {
         });
         editDialog.setDeleteListener(v -> {
             CPDFPageView cpdfPageView = (CPDFPageView) pageView;
-            cpdfPageView.deleteAnnotation(cpdfTextAnnotation);
+            cpdfPageView.deleteAnnotation(this);
+            cpdfTextAnnotation.removeFromPage();
             editDialog.dismiss();
         });
         if (readerView.getContext() instanceof FragmentActivity) {

+ 1 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/impl/CEditTextContextMenuView.java

@@ -163,7 +163,7 @@ public class CEditTextContextMenuView implements ContextMenuEditTextProvider {
                     helper.dismissContextMenu();
                 });
             }
-        } else if (type == 4) {
+        } else if (type == CPDFEditPage.LoadTextImage) {
             if (!TextUtils.isEmpty(text)) {
                 menuView.addItem(R.string.tools_context_menu_paste, 0, v -> {
                     pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight(), false);