From 2eed8653182c7d514fa12c5b41fd0770a2fa1dee Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sat, 28 Mar 2015 09:36:04 +0800 Subject: [PATCH] fixed wrong swipe to dismiss item and caused quick search bar to crash --- .../support/QuickSearchBarActivity.java | 44 ++++--------------- .../mariotaku/twidere/util/StringUtils.java | 1 + 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java index 76621362b..3eab77844 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java @@ -105,7 +105,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On @Override public boolean canDismiss(int position) { - return position < getHistorySize(mSearchQuery.getText()); + return mUsersSearchAdapter.canDismiss(position); } @Override @@ -285,41 +285,9 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On } - static class HeaderItem implements SuggestionItem { - - static final int ITEM_VIEW_TYPE = 1; - - @Override - public void bindView(SuggestionsAdapter adapter, View view, int position) { - - } - - @Override - public int getItemViewType() { - return ITEM_VIEW_TYPE; - } - - @Override - public boolean isEnabled() { - return false; - } - - @Override - public void onItemClick(QuickSearchBarActivity activity, int position) { - - } - - @Override - public int getItemLayoutResource() { - return 0; - } - - - } - static class SearchHistoryItem extends BaseClickableItem { - static final int ITEM_VIEW_TYPE = 1; + static final int ITEM_VIEW_TYPE = 0; private final long mCursorId; private final String mQuery; @@ -369,7 +337,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On static class SavedSearchItem extends BaseClickableItem { - static final int ITEM_VIEW_TYPE = 2; + static final int ITEM_VIEW_TYPE = 1; private final String mQuery; public SavedSearchItem(String query) { @@ -405,7 +373,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On static class UserSuggestionItem extends BaseClickableItem { - static final int ITEM_VIEW_TYPE = 3; + static final int ITEM_VIEW_TYPE = 2; private final ParcelableUser mUser; public UserSuggestionItem(Cursor c, CachedIndices i, long accountId) { @@ -503,6 +471,10 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On mImageLoader = TwidereApplication.getInstance(context).getImageLoaderWrapper(); } + public boolean canDismiss(int position) { + return getItemViewType(position) == SearchHistoryItem.ITEM_VIEW_TYPE; + } + public Context getContext() { return mContext; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StringUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/StringUtils.java index ebbf2cfee..0443ea317 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StringUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StringUtils.java @@ -38,6 +38,7 @@ public class StringUtils { public static boolean startsWithIgnoreCase(@NonNull String string, @NonNull String prefix, int start) { + if (prefix.length() > string.length()) return false; return regionMatchesIgnoreCase(string, start, prefix, 0, prefix.length()); } }