mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-23 21:36:07 +03:00
#550 In-note-search doesn't jump to occurrence of searchstring
- Refactoring
This commit is contained in:
parent
519d31b9dc
commit
63553fb6fc
1 changed files with 14 additions and 6 deletions
|
@ -3,6 +3,7 @@ package it.niedermann.owncloud.notes.android.fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -20,11 +21,13 @@ import it.niedermann.owncloud.notes.R;
|
||||||
|
|
||||||
public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
|
|
||||||
|
private static final String TAG = SearchableBaseNoteFragment.class.getCanonicalName();
|
||||||
|
private static final String saved_instance_key_searchQuery = "searchQuery";
|
||||||
|
private static final String saved_instance_key_currentOccurrence = "currentOccurrence";
|
||||||
|
|
||||||
private int currentOccurrence = 1;
|
private int currentOccurrence = 1;
|
||||||
private int occurrenceCount = 0;
|
private int occurrenceCount = 0;
|
||||||
|
|
||||||
private SearchView searchView;
|
private SearchView searchView;
|
||||||
|
|
||||||
private String searchQuery = null;
|
private String searchQuery = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,8 +35,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
searchQuery = savedInstanceState.getString("searchQuery", "");
|
searchQuery = savedInstanceState.getString(saved_instance_key_searchQuery, "");
|
||||||
currentOccurrence = savedInstanceState.getInt("currentOccurrence", 1);
|
currentOccurrence = savedInstanceState.getInt(saved_instance_key_currentOccurrence, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +131,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
if (searchView != null && !TextUtils.isEmpty(searchView.getQuery().toString())) {
|
if (searchView != null && !TextUtils.isEmpty(searchView.getQuery().toString())) {
|
||||||
outState.putString("searchQuery", searchView.getQuery().toString());
|
outState.putString(saved_instance_key_searchQuery, searchView.getQuery().toString());
|
||||||
outState.putInt("currentOccurrence", currentOccurrence);
|
outState.putInt(saved_instance_key_currentOccurrence, currentOccurrence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +169,12 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void jumpToOccurrence() {
|
private void jumpToOccurrence() {
|
||||||
|
if (getLayout() == null) {
|
||||||
|
Log.w(TAG, "getLayout() is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (getContent() == null || getContent().isEmpty()) {
|
if (getContent() == null || getContent().isEmpty()) {
|
||||||
|
Log.w(TAG, "getContent() returned " + getContent());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (searchQuery == null || searchQuery.isEmpty()) {
|
if (searchQuery == null || searchQuery.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue