|
@@ -1,19 +1,31 @@
|
|
|
package com.compdfkit.tools.viewer.pdfsearch;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.util.Log;
|
|
|
+import android.util.SparseArray;
|
|
|
import android.view.View;
|
|
|
+import android.widget.EditText;
|
|
|
|
|
|
+import androidx.appcompat.app.AlertDialog;
|
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
+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.viewutils.CViewUtils;
|
|
|
import com.compdfkit.tools.common.views.CToolBar;
|
|
|
+import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
|
|
|
import com.compdfkit.tools.viewer.pdfsearch.adapter.CSearchPDFTextRecyclerviewAdapter;
|
|
|
import com.compdfkit.tools.viewer.pdfsearch.bean.CSearchTextInfo;
|
|
|
+import com.compdfkit.ui.edit.CPDFEditTextSearchReplace;
|
|
|
+import com.compdfkit.ui.reader.CPDFReaderView;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment {
|
|
@@ -30,7 +42,13 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
private CSearchPDFTextRecyclerviewAdapter searchTextAdapter;
|
|
|
|
|
|
private CSearchPDFTextRecyclerviewAdapter.OnClickSearchItemListener onClickSearchItemListener;
|
|
|
+ CPDFViewCtrl pdfView;
|
|
|
+ Context context;
|
|
|
|
|
|
+ ReplaceListener replaceListener = null;
|
|
|
+ public void setReplaceListener(ReplaceListener listener) {
|
|
|
+ replaceListener = listener;
|
|
|
+ }
|
|
|
@Override
|
|
|
protected float dimAmount() {
|
|
|
return CViewUtils.isLandScape(getContext()) ? 0.2F : 0F;
|
|
@@ -61,11 +79,67 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
+ public void initWithPDFView(CPDFViewCtrl pdfView) {
|
|
|
+ this.pdfView = pdfView;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ if (searchTextInfos != null && searchTextInfos.size() > 1) {
|
|
|
+ CSearchTextInfo info = searchTextInfos.get(1);
|
|
|
+ if (info == null) return;
|
|
|
+ CPDFReaderView readerView = pdfView.getCPdfReaderView();
|
|
|
+ if (readerView == null) return;
|
|
|
+ CPDFEditTextSearchReplace searchReplace = readerView.getEditTextSearchReplace();
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+ dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ AlertDialog dialog = builder.create();
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void initView() {
|
|
|
toolBar = mContentView.findViewById(R.id.id_search_head);
|
|
|
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);
|
|
|
if (searchTextInfos != null) {
|
|
|
tvResultInfo.setText(getContext().getString(R.string.tools_search_result_found, searchTextInfos.size()));
|
|
|
}
|
|
@@ -83,6 +157,28 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
toolBar.setBackBtnClickListener(view -> {
|
|
|
dismiss();
|
|
|
});
|
|
|
+ toolBar.setReplaceClickListener(view -> {
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
@@ -101,4 +197,8 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
|
|
|
searchTextAdapter.setOnClickSearchItemListener(listener);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public interface ReplaceListener {
|
|
|
+ public void onReplaceEnd();
|
|
|
+ }
|
|
|
}
|