Only focus search once when starting the app

Fixes #654
This commit is contained in:
Jakob Nixdorf 2021-05-04 07:45:12 +02:00
parent cd2310f110
commit cd16928a41
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 19 additions and 6 deletions

View file

@ -21,7 +21,7 @@
android:name=".Activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize">
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View file

@ -102,6 +102,7 @@ public class MainActivity extends BaseActivity
private EntriesCardAdapter adapter;
private SpeedDialView speedDial;
private MenuItem sortMenu;
private MenuItem searchMenu;
private SimpleItemTouchHelperCallback touchHelperCallback;
private EncryptionType encryptionType = EncryptionType.KEYSTORE;
@ -109,6 +110,7 @@ public class MainActivity extends BaseActivity
private boolean recreateActivity = false;
private boolean cacheEncKey = false;
private boolean focusSearchOnCreate = false;
private Handler handler;
private Runnable handlerTask;
@ -366,6 +368,9 @@ public class MainActivity extends BaseActivity
if (savedInstanceState != null) {
setFilterString(savedInstanceState.getString("filterString", ""));
}
if (settings.isFocusSearchOnStartEnabled())
focusSearchMenu();
}
private void checkIntent() {
@ -617,8 +622,8 @@ public class MainActivity extends BaseActivity
}
}
MenuItem searchItem = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) searchItem.getActionView();
searchMenu = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) searchMenu.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
@ -632,7 +637,7 @@ public class MainActivity extends BaseActivity
}
});
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
searchMenu.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
speedDial.setVisibility(View.GONE);
@ -656,13 +661,21 @@ public class MainActivity extends BaseActivity
}
});
if (settings.isFocusSearchOnStartEnabled()) {
searchItem.expandActionView();
if (focusSearchOnCreate) {
searchMenu.expandActionView();
focusSearchOnCreate = false;
}
return true;
}
private void focusSearchMenu() {
if (searchMenu != null)
searchMenu.expandActionView();
else
focusSearchOnCreate = true;
}
private void setFilterString(String newText) {
if (newText.isEmpty())
adapter.filterByTags(tagsDrawerAdapter.getActiveTags());