Commit 339ae744 authored by Robert Hitt's avatar Robert Hitt
Browse files

Solved the mystery of the disappearing button

parent 4a47c878
Pipeline #880 passed with stages
in 5 minutes and 8 seconds
...@@ -6,6 +6,7 @@ import android.content.Intent; ...@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceManager;
...@@ -36,6 +37,7 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -36,6 +37,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
ViewPager mViewPager; ViewPager mViewPager;
private MainPresenter mPresenter; private MainPresenter mPresenter;
private Menu mMenu;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -76,8 +78,9 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -76,8 +78,9 @@ public class MainActivity extends AppCompatActivity implements MainView {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu); getMenuInflater().inflate(R.menu.menu_main, menu);
mMenu = menu;
configureSearchView(menu); configureSearchView();
return true; return true;
} }
...@@ -129,15 +132,15 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -129,15 +132,15 @@ public class MainActivity extends AppCompatActivity implements MainView {
} }
} }
private void configureSearchView(Menu menu) { private void configureSearchView() {
// I think this is for doing the search asynchronously // I think this is for doing the search asynchronously
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final MenuItem searchItem = menu.findItem(R.id.action_search); final MenuItem searchItem = mMenu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView(); SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
// Set QueryTextListener // Set Listener to filter data when queries are entered in SearchView
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
...@@ -162,7 +165,7 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -162,7 +165,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
} }
}); });
// Set QueryTextFocusChangeListener // Reset list view when Search is closed
searchView.setOnFocusChangeListener(new View.OnFocusChangeListener() { searchView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override @Override
public void onFocusChange(View view, boolean queryTextFocused) { public void onFocusChange(View view, boolean queryTextFocused) {
......
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
<item <item
android:id="@+id/action_search" android:id="@+id/action_search"
android:icon="@drawable/ic_search_white_24dp" android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="collapseActionView|ifRoom" app:showAsAction="collapseActionView|always"
app:actionViewClass="android.support.v7.widget.SearchView" app:actionViewClass="android.support.v7.widget.SearchView"
android:title="Search"/> android:title="Search"/>
<group
android:id="@+id/menu_main_group">
<item <item
android:id="@+id/action_refresh" android:id="@+id/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp" android:icon="@drawable/ic_refresh_white_24dp"
...@@ -23,4 +26,7 @@ ...@@ -23,4 +26,7 @@
android:id="@+id/action_about" android:id="@+id/action_about"
app:showAsAction="never" app:showAsAction="never"
android:title="About"/> android:title="About"/>
</group>
</menu> </menu>
\ 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