Browse Source

PDFTool(Android) - 内容编辑替换bug修复

liuxiaolong 1 năm trước cách đây
mục cha
commit
cffea43b32

+ 8 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/viewer/pdfsearch/CSearchResultDialogFragment.java

@@ -31,6 +31,7 @@ import com.compdfkit.ui.reader.CPDFReaderView;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.function.Predicate;
 
 public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment {
     private View mContentView;
@@ -144,7 +145,13 @@ public class CSearchResultDialogFragment extends CBasicBottomSheetDialogFragment
             tvReplaceAll.setVisibility(View.VISIBLE);
         }
         if (searchTextInfos != null) {
-            tvResultInfo.setText(getContext().getString(R.string.tools_search_result_found, searchTextInfos.size()));
+            int resultCount = 0;
+            for (CSearchTextInfo searchTextInfo : searchTextInfos) {
+                if (!searchTextInfo.isHeader) {
+                    resultCount +=1;
+                }
+            }
+            tvResultInfo.setText(getContext().getString(R.string.tools_search_result_found, resultCount));
         }
         LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView.getContext());
         recyclerView.setLayoutManager(layoutManager);

+ 42 - 17
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/viewer/pdfsearch/CSearchToolbar.java

@@ -2,7 +2,9 @@ package com.compdfkit.tools.viewer.pdfsearch;
 
 import android.content.Context;
 import android.os.AsyncTask;
+import android.text.Editable;
 import android.text.TextUtils;
+import android.text.TextWatcher;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.inputmethod.EditorInfo;
@@ -44,6 +46,8 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
 
     private boolean enableSearchResultList = true;
     OnSearchListener onSearchListener = null;
+    private ImageView ivNext;
+    private ImageView ivPrevious;
 
     public void setOnExitSearchListener(OnSearchListener listener) {
         onSearchListener = listener;
@@ -68,8 +72,8 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
         CViewUtils.applyViewBackground(this);
         AppCompatImageView tvComplete = findViewById(R.id.iv_search_back);
         etSearchKeywords = findViewById(R.id.et_search_keywords);
-        ImageView ivNext = findViewById(R.id.iv_search_next);
-        ImageView ivPrevious = findViewById(R.id.iv_search_previous);
+        ivNext = findViewById(R.id.iv_search_next);
+        ivPrevious = findViewById(R.id.iv_search_previous);
         ivSearchResultList = findViewById(R.id.iv_search_list);
         tvComplete.setOnClickListener(this);
         ivNext.setOnClickListener(this);
@@ -77,21 +81,17 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
         ivSearchResultList.setOnClickListener(this);
 
         etSearchKeywords.setOnEditorActionListener((v, actionId, event) -> {
-            if (actionId == EditorInfo.IME_ACTION_SEARCH){
-                startSearch(etSearchKeywords.getText().toString(), 1,false, list -> {
+            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
+                startSearch(etSearchKeywords.getText().toString(), 1, false, list -> {
                     searchTextInfos = list;
                     boolean hasResult = list.size() > 0;
-                    ivPrevious.setVisibility(hasResult ? VISIBLE : INVISIBLE);
-                    ivNext.setVisibility(hasResult ? VISIBLE : INVISIBLE);
-                    if (enableSearchResultList){
-                        ivSearchResultList.setVisibility(hasResult ? VISIBLE : INVISIBLE);
-                    }
+                    showActions(hasResult);
                     if (hasResult) {
                         CSearchTextInfo searchTextInfo = searchTextInfos.get(0);
                         pdfView.getCPdfReaderView().getTextSearcher().searchBegin(searchTextInfo.page, searchTextInfo.textRangeIndex);
-                    }else {
+                    } else {
                         resetSearch();
-                        CToastUtil.showLongToast(context,R.string.tools_sorry_no_contents);
+                        CToastUtil.showLongToast(context, R.string.tools_sorry_no_contents);
                     }
                 });
                 etSearchKeywords.clearFocus();
@@ -100,6 +100,22 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
             }
             return false;
         });
+        etSearchKeywords.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) {
+                showActions(false);
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+
+            }
+        });
     }
 
     private void cancelTask() {
@@ -116,7 +132,15 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
         }
     }
 
-    private void startSearch(String keywords, int searchCount,boolean showLoading, OnSearchResultListener searchResultListener) {
+    private void showActions(boolean show) {
+        ivPrevious.setVisibility(show ? VISIBLE : INVISIBLE);
+        ivNext.setVisibility(show ? VISIBLE : INVISIBLE);
+        if (enableSearchResultList) {
+            ivSearchResultList.setVisibility(show ? VISIBLE : INVISIBLE);
+        }
+    }
+
+    private void startSearch(String keywords, int searchCount, boolean showLoading, OnSearchResultListener searchResultListener) {
         if (TextUtils.isEmpty(keywords)) {
             resetSearch();
             cancelTask();
@@ -196,7 +220,7 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
             previous();
         } else if (id == R.id.iv_search_list) {
             hideKeyboard();
-            startSearch(etSearchKeywords.getText().toString(), Integer.MAX_VALUE,true, list -> {
+            startSearch(etSearchKeywords.getText().toString(), Integer.MAX_VALUE, true, list -> {
                 if (null == list || list.size() <= 0) {
                     Toast.makeText(getContext(), getContext().getString(R.string.tools_sorry_no_contents), Toast.LENGTH_SHORT).show();
                     return;
@@ -218,18 +242,18 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
         }
     }
 
-    public void enableSearchResultList(boolean enable){
+    public void enableSearchResultList(boolean enable) {
         enableSearchResultList = enable;
     }
 
-    public void showKeyboard(){
+    public void showKeyboard() {
         if (etSearchKeywords != null) {
             CViewUtils.showKeyboard(etSearchKeywords);
         }
     }
 
-    public void hideKeyboard(){
-        if (etSearchKeywords != null){
+    public void hideKeyboard() {
+        if (etSearchKeywords != null) {
             CViewUtils.hideKeyboard(etSearchKeywords);
         }
     }
@@ -252,6 +276,7 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
 
     public interface OnSearchListener {
         void onStartSearch(boolean showLoading);
+
         void onEndSearch();
     }
 }

+ 1 - 1
ComPDFKit_Tools/src/main/res/layout/tools_search_keywords_list_item.xml

@@ -14,7 +14,7 @@
         android:layout_marginVertical="14dp"
         android:layout_marginStart="16dp"
         android:layout_marginEnd="16dp"
-        android:maxLines="3"
+        android:maxLines="5"
         android:textColor="@color/tools_text_color_secondary"
         android:textSize="14sp"
         app:layout_constrainedWidth="true"

+ 0 - 2
PDFViewer/src/main/java/com/compdfkit/pdfviewer/CSampleScreenManager.java

@@ -28,7 +28,6 @@ public class CSampleScreenManager {
         fillScreenManager.bindRightToolViewList(binding.pdfView.slideBar);
         fillScreenManager.bindBottomToolViewList(binding.pdfView.indicatorView);
         fillScreenManager.bindBottomToolViewList(binding.flBottomToolBar);
-        fillScreenManager.bindBottomToolViewList(binding.signatureToolBar);
     }
 
 
@@ -102,7 +101,6 @@ public class CSampleScreenManager {
             //enter full screen
             constraintSetUtils.hideFromTop(constraintSet, binding.flTool);
             constraintSetUtils.hideFromBottom(constraintSet, binding.flBottomToolBar);
-            constraintSetUtils.hideFromBottom(constraintSet, binding.signatureToolBar);
             isFillScreen = true;
         } else {
             //enter normal state