|
@@ -12,12 +12,14 @@ package com.compdfkit.tools.common.views.pdfpageedit;
|
|
|
import static com.compdfkit.core.document.CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword;
|
|
|
import static com.compdfkit.core.document.CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess;
|
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.util.SparseIntArray;
|
|
|
+import android.view.KeyEvent;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
@@ -64,6 +66,9 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
private final int MAX_SPLIT_FILE_NAME = 3;
|
|
|
|
|
|
private boolean hasEdit = false;
|
|
|
+
|
|
|
+ private boolean enterEdit = false;
|
|
|
+
|
|
|
private ActivityResultLauncher<Intent> replaceSelectDocumentLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
|
|
if (result.getData() != null && result.getData().getData() != null) {
|
|
|
Uri selectUri = result.getData().getData();
|
|
@@ -95,6 +100,10 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
this.pdfView = pdfView;
|
|
|
}
|
|
|
|
|
|
+ public void setEnterEdit(boolean enterEdit) {
|
|
|
+ this.enterEdit = enterEdit;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
@@ -106,6 +115,8 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
super.onStart();
|
|
|
if (!CViewUtils.isLandScape(getContext())){
|
|
|
CDialogFragmentUtil.setDimAmount(getDialog(), 0F);
|
|
|
+ }else {
|
|
|
+ CDialogFragmentUtil.setDimAmount(getDialog(), 0.2F);
|
|
|
}
|
|
|
BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
|
|
|
behavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
|
@@ -118,6 +129,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
onBackLisener.onBack();
|
|
|
}
|
|
|
break;
|
|
|
+ default:break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -133,8 +145,14 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
@Override
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
View rootView = inflater.inflate(R.layout.tools_page_edit_dialog_fragment, container, false);
|
|
|
+ toolBar = rootView.findViewById(R.id.tool_bar);
|
|
|
+ editToolBar = rootView.findViewById(R.id.tool_page_edit_bar);
|
|
|
this.editThumbnailFragment = (CPDFEditThumbnailFragment) getChildFragmentManager().findFragmentById(R.id.id_edit_thumbnail_fragment);
|
|
|
- editThumbnailFragment.setCPDFPageEditDialogFragment(this);
|
|
|
+ if (this.editThumbnailFragment != null) {
|
|
|
+ editThumbnailFragment.setCPDFPageEditDialogFragment(this);
|
|
|
+ editThumbnailFragment.setEdit(enterEdit);
|
|
|
+ }
|
|
|
+
|
|
|
editThumbnailFragment.setPDFDisplayPageIndexListener(pageIndex -> {
|
|
|
if (pdfView != null) {
|
|
|
pdfView.currentPageIndex = pageIndex;
|
|
@@ -142,8 +160,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
}
|
|
|
});
|
|
|
editThumbnailFragment.initWithPDFView(pdfView);
|
|
|
- toolBar = rootView.findViewById(R.id.tool_bar);
|
|
|
- editToolBar = rootView.findViewById(R.id.tool_page_edit_bar);
|
|
|
+
|
|
|
editToolBar.initWithPDFView(pdfView);
|
|
|
toolBar.setBackBtnClickListener(v -> {
|
|
|
if (editThumbnailFragment.isEdit()) {
|
|
@@ -151,6 +168,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
toolBar.showEditButton(true);
|
|
|
toolBar.showSelectButton(false);
|
|
|
toolBar.showDoneButton(false);
|
|
|
+ editToolBar.setVisibility(View.GONE);
|
|
|
} else {
|
|
|
dismiss();
|
|
|
}
|
|
@@ -161,6 +179,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
toolBar.showEditButton(true);
|
|
|
toolBar.showSelectButton(false);
|
|
|
toolBar.showDoneButton(false);
|
|
|
+ editToolBar.setVisibility(View.GONE);
|
|
|
}
|
|
|
});
|
|
|
toolBar.setOnEnableEditPageCallback((enable) -> {
|
|
@@ -172,6 +191,9 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
toolBar.setOnSelectAllCallback((select) -> {
|
|
|
editThumbnailFragment.setSelectAll(select);
|
|
|
});
|
|
|
+ if (enterEdit) {
|
|
|
+ toolBar.enterEditMode();
|
|
|
+ }
|
|
|
editToolBar.setInsertPageListener(v -> {
|
|
|
insertPage();
|
|
|
});
|
|
@@ -233,9 +255,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
|
} else {
|
|
|
- CThreadPoolUtils.getInstance().execute(() -> {
|
|
|
- rotatePage();
|
|
|
- });
|
|
|
+ CThreadPoolUtils.getInstance().execute(this::rotatePage);
|
|
|
}
|
|
|
});
|
|
|
editToolBar.setDeletePageListener(view -> {
|
|
@@ -266,6 +286,14 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ getDialog().setOnKeyListener((dialog, keyCode, event) -> {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK){
|
|
|
+ dismiss();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ });
|
|
|
return rootView;
|
|
|
}
|
|
|
|