Merge pull request #314 from DanielWeigl/master
ensure the filterstate is correctly applied after onCreate and onRestore
This commit is contained in:
commit
51030f0aa7
1 changed files with 26 additions and 5 deletions
|
@ -98,6 +98,7 @@ public class MainActivity extends BaseActivity
|
|||
private ListView tagsDrawerListView;
|
||||
private TagsAdapter tagsDrawerAdapter;
|
||||
private ActionBarDrawerToggle tagsToggle;
|
||||
private String filterString;
|
||||
|
||||
// QR code scanning
|
||||
private void scanQRCode(){
|
||||
|
@ -283,6 +284,10 @@ public class MainActivity extends BaseActivity
|
|||
ManualEntryDialog.show(MainActivity.this, settings, adapter);
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState != null){
|
||||
setFilterString(savedInstanceState.getString("filterString", ""));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,6 +324,11 @@ public class MainActivity extends BaseActivity
|
|||
}
|
||||
}
|
||||
|
||||
if (filterString != null) {
|
||||
// ensure the current filter string is applied after a resume
|
||||
setFilterString(this.filterString);
|
||||
}
|
||||
|
||||
startUpdater();
|
||||
}
|
||||
|
||||
|
@ -328,6 +338,12 @@ public class MainActivity extends BaseActivity
|
|||
stopUpdater();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString("filterString", filterString);
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if (key.equals(getString(R.string.settings_key_label_size)) ||
|
||||
key.equals(getString(R.string.settings_key_label_scroll)) ||
|
||||
|
@ -454,11 +470,7 @@ public class MainActivity extends BaseActivity
|
|||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (newText.isEmpty())
|
||||
adapter.filterByTags(tagsDrawerAdapter.getActiveTags());
|
||||
else
|
||||
adapter.getFilter().filter(newText);
|
||||
|
||||
setFilterString(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -490,6 +502,15 @@ public class MainActivity extends BaseActivity
|
|||
return true;
|
||||
}
|
||||
|
||||
private void setFilterString(String newText) {
|
||||
if (newText.isEmpty())
|
||||
adapter.filterByTags(tagsDrawerAdapter.getActiveTags());
|
||||
else
|
||||
adapter.getFilter().filter(newText);
|
||||
|
||||
this.filterString = newText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
|
Loading…
Reference in a new issue