Dbrant has uploaded a new change for review.
https://gerrit.wikimedia.org/r/168979
Change subject: A few Search refinements.
......................................................................
A few Search refinements.
- "Select all" search text upon invoking the search fragment.
- Scroll to top of list when search term changes.
- Only save recent search term if the user clicked on a search result
based on it.
Change-Id: Id5af1450c7c97ab07848417eb71d61e59e6a783c
---
M wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
M wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
M wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
3 files changed, 48 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/79/168979/1
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
index bad1e87..b62b109 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
@@ -195,6 +195,17 @@
getWikidataDescriptions(lastResults.getResults());
getPageThumbnails(lastResults.getResults());
}
+
+ if (continueOffset == 0) {
+ // scroll to top, but post it to the message queue,
because it should be done
+ // after the data set is updated.
+ searchResultsList.post(new Runnable() {
+ @Override
+ public void run() {
+ searchResultsList.setSelectionAfterHeaderView();
+ }
+ });
+ }
}
@Override
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
index 527f794..03fddc1 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
@@ -25,6 +25,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
+import android.widget.EditText;
import android.widget.TextView;
public class SearchArticlesFragment extends Fragment {
@@ -306,7 +307,6 @@
// hide ourselves
searchContainerView.setVisibility(View.GONE);
Utils.hideSoftKeyboard(getActivity());
- addRecentSearch(lastSearchedText);
}
/**
@@ -349,8 +349,35 @@
// automatically trigger the showing of the corresponding search
results.
if (isValidQuery(lastSearchedText)) {
searchView.setQuery(lastSearchedText, false);
+
+ // automatically select all text in the search field, so that
typing a new character
+ // will clear it by default
+ EditText editText = getSearchViewEditText(searchView);
+ if (editText != null) {
+ editText.selectAll();
+ }
}
MenuItemCompat.setActionView(searchAction, searchView);
+ }
+
+ /**
+ * Retrieve the EditText component from inside a SearchView widget, so
that operations
+ * may be performed on the EditText, such as selecting text.
+ * @param parent SearchView from which to retrieve the EditText view.
+ * @return EditText view, or null if not found.
+ */
+ private EditText getSearchViewEditText(ViewGroup parent) {
+ for (int i = 0; i < parent.getChildCount(); i++) {
+ if (parent.getChildAt(i) instanceof EditText) {
+ return (EditText)parent.getChildAt(i);
+ } else if (parent.getChildAt(i) instanceof ViewGroup) {
+ EditText et =
getSearchViewEditText((ViewGroup)parent.getChildAt(i));
+ if (et != null) {
+ return et;
+ }
+ }
+ }
+ return null;
}
/*
@@ -400,6 +427,7 @@
HistoryEntry historyEntry = new HistoryEntry(title,
HistoryEntry.SOURCE_SEARCH);
Utils.hideSoftKeyboard(getActivity());
closeSearch();
+ addRecentSearch(lastSearchedText);
app.getBus().post(new NewWikiPageNavigationEvent(title, historyEntry));
}
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
index 5bf54a5..1327af0 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
@@ -278,6 +278,14 @@
if (result.size() == 0 && onNoResultsListener != null) {
onNoResultsListener.onNoResults();
}
+ // scroll to top, but post it to the message queue,
because it should be done
+ // after the data set is updated.
+ searchResultsList.post(new Runnable() {
+ @Override
+ public void run() {
+ searchResultsList.setSelectionAfterHeaderView();
+ }
+ });
}
@Override
--
To view, visit https://gerrit.wikimedia.org/r/168979
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5af1450c7c97ab07848417eb71d61e59e6a783c
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits