|
@@ -6,7 +6,9 @@ import static com.compdfkit.core.document.CPDFDocument.PDFDocumentError.PDFDocum
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.text.Editable;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
@@ -25,7 +27,7 @@ import com.compdfkit.core.document.CPDFDocument;
|
|
|
import com.compdfkit.tools.R;
|
|
|
import com.compdfkit.tools.common.utils.CFileUtils;
|
|
|
import com.compdfkit.tools.common.utils.CToastUtil;
|
|
|
-import com.compdfkit.tools.common.utils.UriUtil;
|
|
|
+import com.compdfkit.tools.common.utils.CUriUtil;
|
|
|
import com.compdfkit.tools.common.utils.dialog.CDialogFragmentUtil;
|
|
|
import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
|
|
|
import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
@@ -58,9 +60,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
private AppCompatEditText etToInputPageIndex;
|
|
|
|
|
|
private CPageEditBar.OnEditDoneCallback onEditDoneCallback;
|
|
|
- private Uri selectUri = null;
|
|
|
private CPDFDocument selectDocument = null;
|
|
|
-
|
|
|
private int[] insertPages = null;
|
|
|
private final String selectPageRegex = "^(\\d+)(-\\d+)?([,,](\\d+)(-\\d+)?)*$";
|
|
|
private ActivityResultLauncher<Intent> selectDocumentLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
|
@@ -71,21 +71,19 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
CPDFDocument tempDocument = new CPDFDocument(getContext());
|
|
|
CPDFDocument.PDFDocumentError pdfDocumentError = tempDocument.open(fileUri);
|
|
|
if (pdfDocumentError == PDFDocumentErrorSuccess) {
|
|
|
- String name = UriUtil.getUriFileName(getContext(), fileUri);
|
|
|
+ String name = CUriUtil.getUriFileName(getContext(), fileUri);
|
|
|
if (!TextUtils.isEmpty(name)) {
|
|
|
tvFilename.setText(name);
|
|
|
}
|
|
|
- selectUri = fileUri;
|
|
|
selectDocument = tempDocument;
|
|
|
} else if (pdfDocumentError == PDFDocumentErrorPassword) {
|
|
|
CVerifyPasswordDialogFragment verifyPasswordDialogFragment;
|
|
|
verifyPasswordDialogFragment = CVerifyPasswordDialogFragment.newInstance(tempDocument, fileUri);
|
|
|
verifyPasswordDialogFragment.setVerifyCompleteListener(document -> {
|
|
|
- String name = UriUtil.getUriFileName(getContext(), fileUri);
|
|
|
+ String name = CUriUtil.getUriFileName(getContext(), fileUri);
|
|
|
if (!TextUtils.isEmpty(name)) {
|
|
|
tvFilename.setText(name);
|
|
|
}
|
|
|
- selectUri = fileUri;
|
|
|
selectDocument = document;
|
|
|
});
|
|
|
verifyPasswordDialogFragment.show(getChildFragmentManager(), "verifyPwdDialog");
|
|
@@ -93,11 +91,15 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- public static CInsertPdfPageDialogFragment newInstance(){
|
|
|
+ public static CInsertPdfPageDialogFragment newInstance() {
|
|
|
return new CInsertPdfPageDialogFragment();
|
|
|
}
|
|
|
|
|
|
- public void initWithPDFView(CPDFViewCtrl pdfView){
|
|
|
+ public void setInsertDocument(CPDFDocument selectDocument) {
|
|
|
+ this.selectDocument = selectDocument;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initWithPDFView(CPDFViewCtrl pdfView) {
|
|
|
this.pdfView = pdfView;
|
|
|
}
|
|
|
|
|
@@ -110,7 +112,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
@Override
|
|
|
public void onStart() {
|
|
|
super.onStart();
|
|
|
- if (!CViewUtils.isLandScape(getContext())){
|
|
|
+ if (!CViewUtils.isLandScape(getContext())) {
|
|
|
CDialogFragmentUtil.setDimAmount(getDialog(), 0F);
|
|
|
}
|
|
|
BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
|
|
@@ -157,6 +159,22 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
CViewUtils.hideKeyboard(etFromInputPageIndex);
|
|
|
}
|
|
|
});
|
|
|
+ etFromInputPageIndex.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+ updateDoneBtnStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
etToInputPageIndex.setOnFocusChangeListener((view, b) -> {
|
|
|
if (b) {
|
|
@@ -168,10 +186,26 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
CViewUtils.hideKeyboard(etToInputPageIndex);
|
|
|
}
|
|
|
});
|
|
|
+ etToInputPageIndex.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+ updateDoneBtnStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
toolBar.setBackBtnClickListener(v -> dismiss());
|
|
|
toolBar.setOnDoneClickCallback(() -> {
|
|
|
- if (selectUri == null) {
|
|
|
+ if (selectDocument == null) {
|
|
|
Toast.makeText(getContext(), R.string.tools_page_edit_select_file_tips, Toast.LENGTH_LONG).show();
|
|
|
} else {
|
|
|
boolean format = true;
|
|
@@ -195,14 +229,38 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
toolBar.showSelectButton(false);
|
|
|
toolBar.showDoneButton(true);
|
|
|
ivFileNameRight.setOnClickListener(this);
|
|
|
+
|
|
|
+ if (selectDocument != null) {
|
|
|
+ if (selectDocument.getUri() != null) {
|
|
|
+ tvFilename.setText(CUriUtil.getUriFileName(getContext(), selectDocument.getUri()));
|
|
|
+ } else if (selectDocument.getAbsolutePath() != null) {
|
|
|
+ String[] arr = selectDocument.getAbsolutePath().split("/");
|
|
|
+ if (arr != null && arr.length > 0) {
|
|
|
+ tvFilename.setText(arr[arr.length - 1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return rootView;
|
|
|
}
|
|
|
|
|
|
+ private void updateDoneBtnStatus() {
|
|
|
+ boolean enable = true;
|
|
|
+ if (rbFromPageLocationSpecify.isChecked()) {
|
|
|
+ enable = !TextUtils.isEmpty(etFromInputPageIndex.getText()) && !TextUtils.isEmpty(etFromInputPageIndex.getText().toString().trim());
|
|
|
+ }
|
|
|
+ if (rbToPageLocationAfter.isChecked() || rbToPageLocationBefore.isChecked()) {
|
|
|
+ enable = !TextUtils.isEmpty(etToInputPageIndex.getText()) && !TextUtils.isEmpty(etToInputPageIndex.getText().toString().trim());
|
|
|
+ }
|
|
|
+ toolBar.enableDone(enable);
|
|
|
+ }
|
|
|
+
|
|
|
private int[] getPageArr(String pageStr) {
|
|
|
if (TextUtils.isEmpty(pageStr)) {
|
|
|
return null;
|
|
|
}
|
|
|
- List<Integer> pageList= new ArrayList<>();
|
|
|
+ List<Integer> pageList = new ArrayList<>();
|
|
|
int[] pageNum = null;
|
|
|
String[] dotSplit = pageStr.split(",|,");
|
|
|
if (dotSplit != null && dotSplit.length > 0) {
|
|
@@ -212,7 +270,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
if (lineSplit == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (lineSplit.length == 1 ) {
|
|
|
+ if (lineSplit.length == 1) {
|
|
|
int page = -1;
|
|
|
try {
|
|
|
page = Integer.parseInt(lineSplit[0]);
|
|
@@ -278,7 +336,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
pageNums = getPageArr(etFromInputPageIndex.getText().toString());
|
|
|
}
|
|
|
for (int pageNum : pageNums) {
|
|
|
- if (pageNum >= selectDocument.getPageCount()){
|
|
|
+ if (pageNum >= selectDocument.getPageCount()) {
|
|
|
CToastUtil.showLongToast(getContext(), R.string.tools_page_choose_skip_input_error);
|
|
|
return;
|
|
|
}
|
|
@@ -301,7 +359,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
}
|
|
|
}
|
|
|
int pageCount = document.getPageCount();
|
|
|
- if (insertPos > pageCount || insertPos <0){
|
|
|
+ if (insertPos > pageCount || insertPos < 0) {
|
|
|
CToastUtil.showLongToast(getContext(), R.string.tools_page_choose_skip_input_error);
|
|
|
return;
|
|
|
}
|
|
@@ -358,6 +416,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
|
|
|
CViewUtils.showKeyboard(etToInputPageIndex);
|
|
|
}
|
|
|
}
|
|
|
+ updateDoneBtnStatus();
|
|
|
}
|
|
|
|
|
|
public void setOnEditDoneCallback(CPageEditBar.OnEditDoneCallback callback) {
|