mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-27 09:46:50 +03:00
Add some comments for previous pr
This commit is contained in:
parent
e02bd35309
commit
313b13d5c4
1 changed files with 11 additions and 8 deletions
|
@ -33,7 +33,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
private int occurrenceCount = 0;
|
private int occurrenceCount = 0;
|
||||||
private SearchView searchView;
|
private SearchView searchView;
|
||||||
private String searchQuery = null;
|
private String searchQuery = null;
|
||||||
private final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.
|
private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||||
|
@ -114,7 +114,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
private Handler handler = new Handler();
|
private Handler handler = new Handler();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(@NonNull String query) {
|
||||||
currentOccurrence++;
|
currentOccurrence++;
|
||||||
jumpToOccurrence();
|
jumpToOccurrence();
|
||||||
colorWithText(query, currentOccurrence);
|
colorWithText(query, currentOccurrence);
|
||||||
|
@ -122,12 +122,12 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(@NonNull String newText) {
|
||||||
queryWithHandler(newText);
|
queryWithHandler(newText);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queryMatch(String newText) {
|
private void queryMatch(@NonNull String newText) {
|
||||||
searchQuery = newText;
|
searchQuery = newText;
|
||||||
occurrenceCount = countOccurrences(getContent(), searchQuery);
|
occurrenceCount = countOccurrences(getContent(), searchQuery);
|
||||||
if (occurrenceCount > 1) {
|
if (occurrenceCount > 1) {
|
||||||
|
@ -140,7 +140,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
colorWithText(searchQuery, currentOccurrence);
|
colorWithText(searchQuery, currentOccurrence);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queryWithHandler(String newText) {
|
private void queryWithHandler(@NonNull String newText) {
|
||||||
if (delayQueryTask != null) {
|
if (delayQueryTask != null) {
|
||||||
delayQueryTask.cancel();
|
delayQueryTask.cancel();
|
||||||
handler.removeCallbacksAndMessages(null);
|
handler.removeCallbacksAndMessages(null);
|
||||||
|
@ -151,11 +151,11 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DelayQueryRunnable implements Runnable {
|
class DelayQueryRunnable implements Runnable {
|
||||||
String mText;
|
private String text;
|
||||||
private boolean canceled = false;
|
private boolean canceled = false;
|
||||||
|
|
||||||
public DelayQueryRunnable(String text) {
|
public DelayQueryRunnable(String text) {
|
||||||
this.mText = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -163,7 +163,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
if (canceled) {
|
if (canceled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queryMatch(mText);
|
queryMatch(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
|
@ -261,6 +261,9 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
if (haystack == null || haystack.isEmpty() || needle == null || needle.isEmpty()) {
|
if (haystack == null || haystack.isEmpty() || needle == null || needle.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// Use regrex which is faster before.
|
||||||
|
// Such that the main thread will not stop for a long tilme
|
||||||
|
// And so there will not an ANR problem
|
||||||
Matcher m = Pattern.compile(needle, Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
|
Matcher m = Pattern.compile(needle, Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
|
||||||
.matcher(haystack);
|
.matcher(haystack);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue