From cd16928a41d4197d8c5ec7f4613a869a365cd711 Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Tue, 4 May 2021 07:45:12 +0200 Subject: [PATCH] Only focus search once when starting the app Fixes #654 --- app/src/main/AndroidManifest.xml | 2 +- .../andotp/Activities/MainActivity.java | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1006eb8a..245fb2fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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"> diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index 4c107ea3..8642ffeb 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -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());