|
@@ -12,7 +12,6 @@ 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;
|
|
@@ -63,7 +62,6 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
private OnBackLisener onBackLisener = null;
|
|
|
|
|
|
private CPDFEditThumbnailFragment editThumbnailFragment;
|
|
|
- private final int MAX_SPLIT_FILE_NAME = 3;
|
|
|
|
|
|
private boolean hasEdit = false;
|
|
|
|
|
@@ -85,18 +83,18 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
verifyPasswordDialogFragment.setVerifyCompleteListener(document -> {
|
|
|
replacePage(selectDocument);
|
|
|
});
|
|
|
- if (getContext() instanceof FragmentActivity){
|
|
|
+ if (getContext() instanceof FragmentActivity) {
|
|
|
verifyPasswordDialogFragment.show(((FragmentActivity) getContext()).getSupportFragmentManager(), "verifyPwdDialog");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- public static CPDFPageEditDialogFragment newInstance(){
|
|
|
+ public static CPDFPageEditDialogFragment newInstance() {
|
|
|
return new CPDFPageEditDialogFragment();
|
|
|
}
|
|
|
|
|
|
- public void initWithPDFView(CPDFViewCtrl pdfView){
|
|
|
+ public void initWithPDFView(CPDFViewCtrl pdfView) {
|
|
|
this.pdfView = pdfView;
|
|
|
}
|
|
|
|
|
@@ -113,12 +111,13 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
@Override
|
|
|
public void onStart() {
|
|
|
super.onStart();
|
|
|
- if (!CViewUtils.isLandScape(getContext())){
|
|
|
+ if (!CViewUtils.isLandScape(getContext())) {
|
|
|
CDialogFragmentUtil.setDimAmount(getDialog(), 0F);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
CDialogFragmentUtil.setDimAmount(getDialog(), 0.2F);
|
|
|
}
|
|
|
BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
|
|
|
+ behavior.setDraggable(false);
|
|
|
behavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
|
|
@Override
|
|
|
public void onStateChanged(@NonNull View bottomSheet, int newState) {
|
|
@@ -129,7 +128,8 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
onBackLisener.onBack();
|
|
|
}
|
|
|
break;
|
|
|
- default:break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -189,7 +189,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
}
|
|
|
});
|
|
|
toolBar.setOnSelectAllCallback((select) -> {
|
|
|
- editThumbnailFragment.setSelectAll(select);
|
|
|
+ editThumbnailFragment.setSelectAll(select);
|
|
|
});
|
|
|
if (enterEdit) {
|
|
|
toolBar.enterEditMode();
|
|
@@ -202,7 +202,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
if (pages.size() == 0) {
|
|
|
CAlertDialog dialog = CAlertDialog.newInstance(getContext().getResources().getString(R.string.tools_page_edit_alert_title),
|
|
|
getContext().getResources().getString(R.string.tools_page_edit_alert_content_nopage));
|
|
|
- dialog.setConfirmClickListener((v)-> {
|
|
|
+ dialog.setConfirmClickListener((v) -> {
|
|
|
dialog.dismiss();
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
@@ -215,7 +215,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
if (pages.size() == 0) {
|
|
|
CAlertDialog dialog = CAlertDialog.newInstance(getContext().getResources().getString(R.string.tools_page_edit_alert_title),
|
|
|
getContext().getResources().getString(R.string.tools_page_edit_alert_content_nopage));
|
|
|
- dialog.setConfirmClickListener((v)-> {
|
|
|
+ dialog.setConfirmClickListener((v) -> {
|
|
|
dialog.dismiss();
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
@@ -225,7 +225,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
if (!TextUtils.isEmpty(path)) {
|
|
|
CFileUtils.shareFile(getContext(), getString(R.string.tools_share_to), "application/pdf", new File(path));
|
|
|
}
|
|
|
- String msg = TextUtils.isEmpty(path) ? getString(R.string.tools_page_edit_extract_fail) : (getString(R.string.tools_page_edit_extract_ok) + " : "+ path);
|
|
|
+ String msg = TextUtils.isEmpty(path) ? getString(R.string.tools_page_edit_extract_fail) : (getString(R.string.tools_page_edit_extract_ok) + " : " + path);
|
|
|
Toast.makeText(getContext(), msg, Toast.LENGTH_LONG).show();
|
|
|
});
|
|
|
}
|
|
@@ -235,7 +235,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
if (pages.size() == 0) {
|
|
|
CAlertDialog dialog = CAlertDialog.newInstance(getContext().getResources().getString(R.string.tools_page_edit_alert_title),
|
|
|
getContext().getResources().getString(R.string.tools_page_edit_alert_content_nopage));
|
|
|
- dialog.setConfirmClickListener((v)-> {
|
|
|
+ dialog.setConfirmClickListener((v) -> {
|
|
|
dialog.dismiss();
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
@@ -250,7 +250,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
if (pages.size() == 0) {
|
|
|
CAlertDialog dialog = CAlertDialog.newInstance(getContext().getResources().getString(R.string.tools_page_edit_alert_title),
|
|
|
getContext().getResources().getString(R.string.tools_page_edit_alert_content_nopage));
|
|
|
- dialog.setConfirmClickListener((v)-> {
|
|
|
+ dialog.setConfirmClickListener((v) -> {
|
|
|
dialog.dismiss();
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
@@ -263,7 +263,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
if (pages.size() == 0) {
|
|
|
CAlertDialog dialog = CAlertDialog.newInstance(getContext().getResources().getString(R.string.tools_page_edit_alert_title),
|
|
|
getContext().getResources().getString(R.string.tools_page_edit_alert_content_nopage));
|
|
|
- dialog.setConfirmClickListener((v)-> {
|
|
|
+ dialog.setConfirmClickListener((v) -> {
|
|
|
dialog.dismiss();
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
@@ -273,9 +273,9 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
}
|
|
|
CPDFDocument document = pdfView.getCPdfReaderView().getPDFDocument();
|
|
|
if (pages.size() == document.getPageCount()) {
|
|
|
- CAlertDialog dialog = CAlertDialog.newInstance(getContext().getResources().getString(R.string.tools_page_edit_alert_title),
|
|
|
+ CAlertDialog dialog = CAlertDialog.newInstance(getContext().getString(R.string.tools_warning),
|
|
|
getContext().getResources().getString(R.string.tools_page_edit_alert_content_allpage));
|
|
|
- dialog.setConfirmClickListener((v)-> {
|
|
|
+ dialog.setConfirmClickListener((v) -> {
|
|
|
dialog.dismiss();
|
|
|
});
|
|
|
dialog.show(getChildFragmentManager(), "dialog");
|
|
@@ -287,7 +287,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
}
|
|
|
});
|
|
|
getDialog().setOnKeyListener((dialog, keyCode, event) -> {
|
|
|
- if (keyCode == KeyEvent.KEYCODE_BACK){
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
dismiss();
|
|
|
return true;
|
|
|
}
|
|
@@ -343,7 +343,7 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
boolean res = false;
|
|
|
|
|
|
int[] insertPageNum = new int[selectDocument.getPageCount()];
|
|
|
- for (int i = 0; i < insertPageNum.length;i++) {
|
|
|
+ for (int i = 0; i < insertPageNum.length; i++) {
|
|
|
insertPageNum[i] = i;
|
|
|
}
|
|
|
|
|
@@ -420,12 +420,12 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
|
|
|
if (pageList.size() > 0) {
|
|
|
for (int i = pageList.size() - 1; i >= 0; i--) {
|
|
|
- document.addPage(pageList.get(i), pagesArr.keyAt(pagesArr.size() - 1)+1);
|
|
|
+ document.addPage(pageList.get(i), pagesArr.keyAt(pagesArr.size() - 1) + 1);
|
|
|
}
|
|
|
|
|
|
pdfView.getCPdfReaderView().reloadPages();
|
|
|
int[] updatePags = new int[pagesArr.size()];
|
|
|
- for (int i = 0; i < updatePags.length ;i++) {
|
|
|
+ for (int i = 0; i < updatePags.length; i++) {
|
|
|
updatePags[i] = i + pagesArr.keyAt(pagesArr.size() - 1) + 1;
|
|
|
}
|
|
|
editThumbnailFragment.setSelectPages(updatePags);
|
|
@@ -479,7 +479,6 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
}
|
|
|
boolean res = document.removePages(pageNum);
|
|
|
editThumbnailFragment.setSelectAll(false);
|
|
|
-
|
|
|
editThumbnailFragment.updatePagesArr(pageNum, CPDFEditThumbnailFragment.updateTypeDelete);
|
|
|
hasEdit = true;
|
|
|
return res;
|
|
@@ -495,23 +494,19 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private String getNewFileName(int[] export_page) {
|
|
|
+ private String getNewFileName(int[] exportPages) {
|
|
|
CPDFDocument document = pdfView.getCPdfReaderView().getPDFDocument();
|
|
|
String fileName = document.getFileName();
|
|
|
String newName = fileName.substring(0, fileName.indexOf(".pdf"));
|
|
|
- if (export_page.length <= MAX_SPLIT_FILE_NAME) {
|
|
|
- newName = newName + "_Page";
|
|
|
- for (int i = 0; i < export_page.length; i++) {
|
|
|
- if (i != 0) {
|
|
|
- newName = newName + "," + (export_page[i] + 1);
|
|
|
- } else {
|
|
|
- newName = newName + (export_page[i] + 1);
|
|
|
- }
|
|
|
+ newName = newName + "_Page";
|
|
|
+ for (int i = 0; i < exportPages.length; i++) {
|
|
|
+ if (i != 0) {
|
|
|
+ newName = newName + "," + (exportPages[i] + 1);
|
|
|
+ } else {
|
|
|
+ newName = newName + (exportPages[i] + 1);
|
|
|
}
|
|
|
- newName = newName + ".pdf";
|
|
|
- } else {
|
|
|
- newName = newName + "_Page" + (export_page[0]+1) + "," + (export_page[1]+1) + "," + (export_page[2]+1) + ",etc" + ".pdf";
|
|
|
}
|
|
|
+ newName = newName + ".pdf";
|
|
|
return newName;
|
|
|
}
|
|
|
|
|
@@ -526,24 +521,29 @@ public class CPDFPageEditDialogFragment extends BottomSheetDialogFragment {
|
|
|
|
|
|
@Override
|
|
|
public void dismiss() {
|
|
|
+ if (checkPdfView()) {
|
|
|
+ CPDFReaderView readerView = pdfView.getCPdfReaderView();
|
|
|
+ if (hasEdit) {
|
|
|
+ readerView.reloadPages();
|
|
|
+ readerView.setDisplayPageIndex(pdfView.currentPageIndex);
|
|
|
+ int pageCount = readerView.getPDFDocument().getPageCount();
|
|
|
+ pdfView.slideBar.setPageCount(pageCount);
|
|
|
+ pdfView.slideBar.requestLayout();
|
|
|
+ pdfView.indicatorView.setTotalPage(pageCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
super.dismiss();
|
|
|
if (onBackLisener != null) {
|
|
|
onBackLisener.onBack();
|
|
|
- if (checkPdfView()) {
|
|
|
- CPDFReaderView readerView = pdfView.getCPdfReaderView();
|
|
|
- if (hasEdit) {
|
|
|
- readerView.reloadPages();
|
|
|
- readerView.setDisplayPageIndex(pdfView.currentPageIndex);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void setHasEdit(boolean edit) {
|
|
|
hasEdit = edit;
|
|
|
}
|
|
|
- public void setOnBackLisener(OnBackLisener lisener) {
|
|
|
- this.onBackLisener = lisener;
|
|
|
+
|
|
|
+ public void setOnBackListener(OnBackLisener listener) {
|
|
|
+ this.onBackLisener = listener;
|
|
|
}
|
|
|
|
|
|
public interface OnBackLisener {
|