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

View file

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