From 18fd3a23849b3c76d450542480bb07d4a9a2b6d4 Mon Sep 17 00:00:00 2001 From: Don Kimberlin Date: Thu, 18 Jun 2020 23:32:26 -0700 Subject: [PATCH] Making Selecting a search suggestion fill search field (#169) --- .../peertube/activity/VideoListActivity.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index 8a68ce6..54abbc7 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.database.Cursor; import android.preference.PreferenceManager; import android.provider.SearchRecentSuggestions; @@ -166,7 +167,27 @@ public class VideoListActivity extends CommonActivity { Log.d(TAG, "onDismiss: "); loadVideos(0, count, sort, filter); }); + searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { + @Override + public boolean onSuggestionClick(int position) { + String suggestion = getSuggestion(position); + searchView.setQuery(suggestion, true); + return true; + } + private String getSuggestion(int position) { + Cursor cursor = (Cursor) searchView.getSuggestionsAdapter().getItem( + position); + return cursor.getString(cursor + .getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1)); + } + + @Override + public boolean onSuggestionSelect(int position) { + /* Required to implement */ + return true; + } + }); return true; }