diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
index 3f8340b14..784fcdd22 100644
--- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
+++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
@@ -78,6 +78,8 @@ public class SearchBar extends CardView implements View.OnClickListener,
private SimpleImageView mActionButton;
private SearchEditText mEditText;
private ListView mList;
+ private View mListHeader;
+ private boolean mHeaderAttached = false;
private ViewTransition mViewTransition;
@@ -108,12 +110,14 @@ public class SearchBar extends CardView implements View.OnClickListener,
private void init(Context context) {
mSearchDatabase = SearchDatabase.getInstance(getContext());
- LayoutInflater.from(context).inflate(R.layout.widget_search_bar, this);
+ LayoutInflater inflater = LayoutInflater.from(context);
+ inflater.inflate(R.layout.widget_search_bar, this);
mMenuButton = (SimpleImageView) findViewById(R.id.search_menu);
mTitleTextView = (TextView) findViewById(R.id.search_title);
mActionButton = (SimpleImageView) findViewById(R.id.search_action);
mEditText = (SearchEditText) findViewById(R.id.search_edit_text);
mList = (ListView) findViewById(R.id.search_bar_list);
+ mListHeader = inflater.inflate(R.layout.header_suggestion_list, mList, false);
mViewTransition = new ViewTransition(mTitleTextView, mEditText);
@@ -136,18 +140,38 @@ public class SearchBar extends CardView implements View.OnClickListener,
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- String suggestion = mSuggestionList.get(position);
+ String suggestion = mSuggestionList.get(MathUtils.clamp(
+ position - mList.getHeaderViewsCount(), 0, mSuggestionList.size() - 1));
mEditText.setText(suggestion);
mEditText.setSelection(suggestion.length());
}
});
}
+ private void addListHeader() {
+ if (!mHeaderAttached) {
+ mHeaderAttached = true;
+ mList.addHeaderView(mListHeader, null, false);
+ }
+ }
+
+ private void removeListHeader() {
+ if (mHeaderAttached) {
+ mHeaderAttached = false;
+ mList.removeHeaderView(mListHeader);
+ }
+ }
+
private void updateSuggestions() {
String prefix = mEditText.getText().toString();
String[] suggestions = mSearchDatabase.getSuggestions(prefix);
mSuggestionList.clear();
Collections.addAll(mSuggestionList, suggestions);
+ if (mSuggestionList.size() == 0) {
+ removeListHeader();
+ } else {
+ addListHeader();
+ }
mSuggestionAdapter.notifyDataSetChanged();
}
diff --git a/app/src/main/res/layout/header_suggestion_list.xml b/app/src/main/res/layout/header_suggestion_list.xml
new file mode 100644
index 000000000..073875a2d
--- /dev/null
+++ b/app/src/main/res/layout/header_suggestion_list.xml
@@ -0,0 +1,22 @@
+
+
+
+
diff --git a/app/src/main/res/layout/widget_search_bar.xml b/app/src/main/res/layout/widget_search_bar.xml
index d9760f88a..f78ef57f2 100644
--- a/app/src/main/res/layout/widget_search_bar.xml
+++ b/app/src/main/res/layout/widget_search_bar.xml
@@ -72,7 +72,10 @@
android:id="@+id/search_bar_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:visibility="gone"/>
+ android:visibility="gone"
+ android:divider="@color/divider"
+ android:dividerHeight="1dp"
+ android:headerDividersEnabled="false"/>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index d87196d6d..8afe1cf2d 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -85,4 +85,7 @@
#fff06292
@android:color/black
+
+ #20000000
+