Commit 89d879a3 authored by Robert Hitt's avatar Robert Hitt

Search now works

- Slight problem, the searches make no sense at all
and it doesn't reset on close. And you can accidentally
make the search button disappear. Slight problems.
parent 73521eec
......@@ -19,9 +19,16 @@
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"/>
<meta-data
android:name="android.app.default_searchable"
android:value=".ui.activities.MainActivity"/>
</activity>
<activity android:name=".views.activities.DetailActivity"
......
......@@ -133,7 +133,8 @@ public class MainActivity extends AppCompatActivity implements MainView {
// I think this is for doing the search asynchronously
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
final MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
// Set QueryTextListener
......@@ -145,8 +146,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
@Override
public boolean onQueryTextChange(String newText) {
// kinda hacky way to get the Fragment through the multitudinous layers of
// ViewPager spaghetti. I mean, not that hacky, but it looks gross
// hacky way of getting the Fragment. Blame Android, not me
Fragment fragment = getSupportFragmentManager()
.findFragmentByTag("android:switcher:" + R.id.view_pager + ":" +
mViewPager.getCurrentItem());
......@@ -161,6 +161,17 @@ public class MainActivity extends AppCompatActivity implements MainView {
return true;
}
});
// Set QueryTextFocusChangeListener
searchView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean queryTextFocused) {
if(!queryTextFocused) {
searchItem.collapseActionView();
searchView.setQuery("", false);
}
}
});
}
@Override
......
......@@ -6,13 +6,12 @@
android:id="@+id/action_search"
android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="Search"/>
<item
android:id="@+id/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="ifRoom"
android:title="Refresh"/>
<item
......
......@@ -2,6 +2,11 @@
<string name="app_name">What\'s Open</string>
<string name="toast_set_favorite">Added %s to Favorites</string>
<string name="toast_unset_favorite">Removed %s from Favorites</string>
<!-- Strings for MainActivity -->
<string name="search_hint">Search&#8230;</string>
<!-- Strings for NotificationDialog -->
<string name="remove_all_text">Remove All</string>
<!-- Strings for PreferenceFragment -->
......
<?xml version="1.0" encoding="utf-8"?>
<Searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint">
</Searchable>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment