|
@@ -17,6 +17,10 @@ import com.compdfkit.core.edit.CPDFEditFindSelection;
|
|
|
import com.compdfkit.core.edit.CPDFEditManager;
|
|
|
import com.compdfkit.tools.R;
|
|
|
import com.compdfkit.tools.common.basic.fragment.CBasicBottomSheetDialogFragment;
|
|
|
+import com.compdfkit.tools.common.utils.dialog.CCommonInputDialog;
|
|
|
+import com.compdfkit.tools.common.utils.dialog.CEditDialog;
|
|
|
+import com.compdfkit.tools.common.utils.dialog.CLoadingDialog;
|
|
|
+import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
|
|
|
import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
|
import com.compdfkit.tools.common.views.CToolBar;
|
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
|
|
@@ -37,6 +41,8 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
|
|
|
private ConstraintLayout clSearchResultEmpty;
|
|
|
|
|
|
+ private AppCompatTextView tvReplaceAll;
|
|
|
+
|
|
|
private List<CSearchTextInfo> searchTextInfos = null;
|
|
|
|
|
|
private CSearchPDFTextRecyclerviewAdapter searchTextAdapter;
|
|
@@ -46,9 +52,11 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
Context context;
|
|
|
|
|
|
ReplaceListener replaceListener = null;
|
|
|
- public void setReplaceListener(ReplaceListener listener) {
|
|
|
+
|
|
|
+ public void setReplaceListener(ReplaceListener listener) {
|
|
|
replaceListener = listener;
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
protected float dimAmount() {
|
|
|
return CViewUtils.isLandScape(getContext()) ? 0.2F : 0F;
|
|
@@ -84,53 +92,44 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
}
|
|
|
|
|
|
void createDialog() {
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(pdfView.getContext());
|
|
|
- EditText editText = new EditText(pdfView.getContext());
|
|
|
- builder.setMessage("全部替换为");
|
|
|
- editText.setHint("pdf");
|
|
|
- builder.setView(editText);
|
|
|
-
|
|
|
- builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+ CEditDialog editDialog = CEditDialog.newInstance(getString(R.string.tools_replace_all_with), "");
|
|
|
+ editDialog.setHint(R.string.tools_replace_hint);
|
|
|
+ editDialog.setEditListener(content -> {
|
|
|
+ editDialog.dismiss();
|
|
|
+ CLoadingDialog loadingDialog = CLoadingDialog.newInstance(R.string.tools_progressing);
|
|
|
+ loadingDialog.show(getChildFragmentManager(), "loading");
|
|
|
+ CThreadPoolUtils.getInstance().executeIO(() -> {
|
|
|
if (searchTextInfos != null && searchTextInfos.size() > 1) {
|
|
|
CSearchTextInfo info = searchTextInfos.get(1);
|
|
|
- if (info == null) return;
|
|
|
+ if (info == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
CPDFReaderView readerView = pdfView.getCPdfReaderView();
|
|
|
- if (readerView == null) return;
|
|
|
+ if (readerView == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
CPDFEditTextSearchReplace searchReplace = readerView.getEditTextSearchReplace();
|
|
|
- if (searchReplace == null) return;
|
|
|
+ if (searchReplace == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
searchReplace.setSearchConfig(info.keyword, 0);
|
|
|
CPDFEditManager editManager = readerView.getEditManager();
|
|
|
- if (editManager == null) return;
|
|
|
- // editManager.beginEdit(3);
|
|
|
- searchReplace.findSelections();
|
|
|
- searchReplace.replaceAll(editText.getText().toString());
|
|
|
-
|
|
|
-// for (int i = 0; i < searchTextInfos.size(); i++) {
|
|
|
-// CSearchTextInfo info = searchTextInfos.get(i);
|
|
|
-// if (info == null) continue;
|
|
|
-// if (info.isHeader) {
|
|
|
-// searchReplace.findEditString(i);
|
|
|
-// searchReplace.replaceAll("ABCD");
|
|
|
-// }
|
|
|
-// }
|
|
|
- // editManager.endEdit();
|
|
|
- dismiss();
|
|
|
- if (replaceListener != null) {
|
|
|
- replaceListener.onReplaceEnd();
|
|
|
+ if (editManager == null) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ searchReplace.findSelections();
|
|
|
+ searchReplace.replaceAll(content);
|
|
|
+ CThreadPoolUtils.getInstance().executeMain(() -> {
|
|
|
+ loadingDialog.dismiss();
|
|
|
+ dismiss();
|
|
|
+ if (replaceListener != null) {
|
|
|
+ replaceListener.onReplaceEnd();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
- dismiss();
|
|
|
- }
|
|
|
+ });
|
|
|
});
|
|
|
- AlertDialog dialog = builder.create();
|
|
|
- dialog.show();
|
|
|
+ editDialog.show(getChildFragmentManager(), "inputDialog");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -139,7 +138,10 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
recyclerView = mContentView.findViewById(R.id.id_reader_search_recyclerView);
|
|
|
clSearchResultEmpty = mContentView.findViewById(R.id.cl_search_result_empty_view);
|
|
|
AppCompatTextView tvResultInfo = mContentView.findViewById(R.id.tv_search_result);
|
|
|
- toolBar.initWithPDFView(pdfView);
|
|
|
+ tvReplaceAll = mContentView.findViewById(R.id.tv_tool_bar_replace);
|
|
|
+ if (pdfView != null && pdfView.getCPdfReaderView().getViewMode() == CPDFReaderView.ViewMode.PDFEDIT) {
|
|
|
+ tvReplaceAll.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
if (searchTextInfos != null) {
|
|
|
tvResultInfo.setText(getContext().getString(R.string.tools_search_result_found, searchTextInfos.size()));
|
|
|
}
|
|
@@ -151,33 +153,16 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
searchTextAdapter.clearList();
|
|
|
searchTextAdapter.addList(searchTextInfos);
|
|
|
searchTextAdapter.notifyDataSetChanged();
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
clSearchResultEmpty.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
toolBar.setBackBtnClickListener(view -> {
|
|
|
dismiss();
|
|
|
});
|
|
|
- toolBar.setReplaceClickListener(view -> {
|
|
|
+ tvReplaceAll.setOnClickListener(v -> {
|
|
|
if (searchTextInfos != null) {
|
|
|
-// Log.e("ss","ttttttt1");
|
|
|
-// CPDFReaderView readerView = pdfView.getCPdfReaderView();
|
|
|
-// if (readerView == null) return;
|
|
|
-// CPDFEditTextSearchReplace searchReplace = readerView.getEditTextSearchReplace();
|
|
|
-// searchReplace.setSearchConfig("pdf", 0);
|
|
|
-// if (searchReplace == null) return;
|
|
|
-// CPDFEditManager editManager = readerView.getEditManager();
|
|
|
-// if (editManager == null) return;
|
|
|
-// // editManager.beginEdit(3);
|
|
|
-// Log.e("ss","ttttttt2");
|
|
|
-// SparseArray<ArrayList<CPDFEditFindSelection>> ss = searchReplace.findSelections();
|
|
|
-// Log.e("ss","ttttttt3");
|
|
|
-// Log.e("ssss","bbbbbb find:ss="+(ss==null?"null":"not null"));
|
|
|
-// Log.e("ss","bbbbb:n="+ss.size());
|
|
|
-// searchReplace.replaceAll("ABCD");
|
|
|
- // editManager.endEdit();
|
|
|
createDialog();
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
searchTextAdapter.setOnClickSearchItemListener(onClickSearchItemListener);
|
|
|
}
|