diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-10-26 21:57:08 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-10-26 21:57:31 +0100 |
commit | e89dba8f245f59afd9e4e3da9c62f98befcb4d47 (patch) | |
tree | 034b17c5d6fbf478c3aede3eb2775aaa13f809f9 /OpenKeychain/src/main/java/org | |
parent | 67a51cdfe3f6fb7982b27eb2b6d4b1b5d49f69aa (diff) | |
download | open-keychain-e89dba8f245f59afd9e4e3da9c62f98befcb4d47.tar.gz open-keychain-e89dba8f245f59afd9e4e3da9c62f98befcb4d47.tar.bz2 open-keychain-e89dba8f245f59afd9e4e3da9c62f98befcb4d47.zip |
prevent crashes in EncryptKeyCompletionView (2)
Diffstat (limited to 'OpenKeychain/src/main/java/org')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index 7fec47533..01d51af48 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -29,6 +29,7 @@ import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -134,18 +135,19 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView<KeyItem> + KeyRings.IS_EXPIRED + " = 0 AND " + Tables.KEYS + "." + KeyRings.IS_REVOKED + " = 0"; - if (args != null && args.containsKey(ARG_QUERY)) { - String query = args.getString(ARG_QUERY); - mAdapter.setSearchQuery(query); + if (args == null || !args.containsKey(ARG_QUERY)) { + // mAdapter.setSearchQuery(null); + // return new CursorLoader(getContext(), baseUri, projection, where, null, null); + return null; + } - where += " AND " + KeyRings.USER_ID + " LIKE ?"; + String query = args.getString(ARG_QUERY); + mAdapter.setSearchQuery(query); - return new CursorLoader(getContext(), baseUri, projection, where, - new String[]{"%" + query + "%"}, null); - } + where += " AND " + KeyRings.USER_ID + " LIKE ?"; - mAdapter.setSearchQuery(null); - return new CursorLoader(getContext(), baseUri, projection, where, null, null); + return new CursorLoader(getContext(), baseUri, projection, where, + new String[]{"%" + query + "%"}, null); } @@ -167,6 +169,8 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView<KeyItem> super.showDropDown(); } + + @Override public void onFocusChanged(boolean hasFocus, int direction, Rect previous) { super.onFocusChanged(hasFocus, direction, previous); @@ -182,8 +186,13 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView<KeyItem> if (start < mPrefix.length()) { start = mPrefix.length(); } + String query = text.subSequence(start, end).toString(); + if (TextUtils.isEmpty(query) || query.length() < 2) { + mLoaderManager.destroyLoader(0); + return; + } Bundle args = new Bundle(); - args.putString(ARG_QUERY, text.subSequence(start, end).toString()); + args.putString(ARG_QUERY, query); mLoaderManager.restartLoader(0, args, this); } |