From fbeffe53f6ff47738c1f65c646bc7b63e64b66ce Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 25 Apr 2015 14:36:13 +0800 Subject: [PATCH] Update search in gallery list --- .../ehviewer/ui/scene/GalleryListScene.java | 70 ++++++-- .../com/hippo/ehviewer/widget/SearchBar.java | 155 ++++++++++++------ .../hippo/ehviewer/widget/SearchDatabase.java | 2 +- .../hippo/ehviewer/widget/SearchEditText.java | 24 ++- .../hippo/ehviewer/widget/SearchLayout.java | 25 ++- app/src/main/java/com/hippo/scene/Scene.java | 22 +-- .../com/hippo/widget/FloatLabelEditText.java | 6 - .../java/com/hippo/widget/Hotspotable.java | 2 +- .../com/hippo/widget/SimpleImageView.java | 10 +- .../widget/recyclerview/MonoRecyclerView.java | 53 ++++++ .../main/res/layout/scene_gallery_list.xml | 1 - app/src/main/res/layout/search_category.xml | 4 +- app/src/main/res/layout/widget_search_bar.xml | 2 +- .../main/res/layout/widget_search_layout.xml | 10 +- app/src/main/res/values/attrs.xml | 8 +- app/src/main/res/values/dimens.xml | 8 +- 16 files changed, 286 insertions(+), 116 deletions(-) create mode 100644 app/src/main/java/com/hippo/widget/recyclerview/MonoRecyclerView.java diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 5abe7b76a..b0fb232c2 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -19,7 +19,6 @@ import android.content.res.Resources; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.ViewGroup; -import android.view.ViewTreeObserver; import com.hippo.effect.ViewTransition; import com.hippo.ehviewer.R; @@ -33,12 +32,12 @@ import com.hippo.util.Log; import com.hippo.util.ViewUtils; public -class GalleryListScene extends Scene implements SearchBar.Helper, - ViewTreeObserver.OnGlobalLayoutListener { +class GalleryListScene extends Scene implements SearchBar.Helper { - private final static int PAGE_INDEX_SEARCH = 0; - private final static int PAGE_INDEX_LIST = 1; - private final static int PAGE_NUMBER = 2; + private final static int STATE_NORMAL = 0; + private final static int STATE_SIMPLE_SEARCH = 1; + private final static int STATE_SEARCH = 2; + private final static int STATE_SEARCH_SHOW_LIST = 3; private ContentActivity mActivity; private Resources mResources; @@ -50,6 +49,8 @@ class GalleryListScene extends Scene implements SearchBar.Helper, private ViewTransition mViewTransition; + private int mState = STATE_NORMAL; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -72,8 +73,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper, // Search Layout mSearchLayout.setFitPaddingTop(mSearchBar.getMeasuredHeight() + - (int) (2 * mResources.getDimension(R.dimen.search_bar_padding_vertical))); - + mResources.getDimensionPixelOffset(R.dimen.search_bar_padding_vertical)); // TEST mContentLayout.showText("四姑拉斯基"); @@ -81,12 +81,37 @@ class GalleryListScene extends Scene implements SearchBar.Helper, @Override protected void onGetFitPaddingBottom(int b) { - // TODO + mSearchLayout.setFitPaddingBottom(b); } @Override - public void onGlobalLayout() { + public void onBackPressed() { + switch (mState) { + case STATE_NORMAL: + super.onBackPressed(); + break; + case STATE_SIMPLE_SEARCH: + mSearchBar.setInNormalMode(); + mState = STATE_NORMAL; + break; + case STATE_SEARCH: + mViewTransition.showFirstView(); + mSearchBar.setInNormalMode(); + mState = STATE_NORMAL; + break; + case STATE_SEARCH_SHOW_LIST: + mSearchBar.hideImeAndSuggestionsList(); + mState = STATE_SEARCH; + break; + } + } + @Override + public void onClickTitle() { + if (mState == STATE_NORMAL) { + mState = STATE_SIMPLE_SEARCH; + mSearchBar.setInEditMode(true); + } } @Override @@ -95,14 +120,35 @@ class GalleryListScene extends Scene implements SearchBar.Helper, } @Override - public void onClickAction() { - mViewTransition.showSecondView(); + public void onClickArrow() { + onBackPressed(); + } + + @Override + public void onClickAdvanceSearch() { + if (mState == STATE_NORMAL) { + mViewTransition.showSecondView(); + mSearchLayout.scrollSearchContainerToTop(); + mSearchBar.setInEditMode(false); + mState = STATE_SEARCH; + } + } + + @Override + public void onSearchEditTextClick() { + if (mState == STATE_SEARCH) { + mSearchBar.showImeAndSuggestionsList(); + mState = STATE_SEARCH_SHOW_LIST; + } } @Override public void onApplySearch(String query) { Log.d("onApplySearch " + query); mSearchDatabase.addQuery(query); + + mViewTransition.showFirstView(); mSearchBar.setInNormalMode(); + mState = STATE_NORMAL; } } 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 cf8856946..62475bd2c 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java @@ -47,10 +47,12 @@ import com.hippo.util.ViewUtils; import com.hippo.widget.SimpleImageView; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class SearchBar extends CardView implements View.OnClickListener, - TextView.OnEditorActionListener, TextWatcher { + TextView.OnEditorActionListener, TextWatcher, + SearchEditText.SearchEditTextListener { private static final long ANIMATION_TIME = 300; @@ -100,7 +102,6 @@ public class SearchBar extends CardView implements View.OnClickListener, setRadius(UiUtils.dp2pix(context, 2)); setCardElevation(UiUtils.dp2pix(context, 2)); setCardBackgroundColor(Color.WHITE); - setOnClickListener(this); LayoutInflater.from(context).inflate(R.layout.widget_search_bar, this); mMenuButton = (SimpleImageView) findViewById(R.id.search_menu); @@ -112,11 +113,12 @@ public class SearchBar extends CardView implements View.OnClickListener, mDrawerArrowDrawable = new DrawerArrowDrawable(getContext()); mAddDeleteDrawable = new AddDeleteDrawable(getContext()); + mTitleTextView.setOnClickListener(this); mMenuButton.setDrawable(mDrawerArrowDrawable); mMenuButton.setOnClickListener(this); mActionButton.setDrawable(mAddDeleteDrawable); mActionButton.setOnClickListener(this); - mEditText.setSearchBar(this); + mEditText.setSearchEditTextListener(this); mEditText.setOnEditorActionListener(this); mEditText.addTextChangedListener(this); @@ -130,9 +132,7 @@ public class SearchBar extends CardView implements View.OnClickListener, String prefix = mEditText.getText().toString(); String[] suggestions = mSearchDatabase.getSuggestions(prefix); mSuggestionList.clear(); - for (String suggestion : suggestions) { - mSuggestionList.add(suggestion); - } + Collections.addAll(mSuggestionList, suggestions); mSuggestionAdapter.notifyDataSetChanged(); } @@ -142,11 +142,11 @@ public class SearchBar extends CardView implements View.OnClickListener, @Override public void onClick(View v) { - if (v == this) { - setInEditMode(); + if (v == mTitleTextView) { + mHelper.onClickTitle(); } else if (v == mMenuButton) { if (mInEditMode) { - setInNormalMode(); + mHelper.onClickArrow(); } else { mHelper.onClickMenu(); } @@ -154,7 +154,7 @@ public class SearchBar extends CardView implements View.OnClickListener, if (mInEditMode) { mEditText.setText(""); } else { - mHelper.onClickAction(); + mHelper.onClickAdvanceSearch(); } } } @@ -173,26 +173,77 @@ public class SearchBar extends CardView implements View.OnClickListener, return false; } - public void setInEditMode() { + public void setInEditMode(boolean showList) { if (!mInEditMode) { mInEditMode = true; setClickable(false); ViewUtils.setVisibility(mTitleTextView, View.GONE); ViewUtils.setVisibility(mEditText, View.VISIBLE); mEditText.requestFocus(); - // show ime - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - // update suggestion - updateSuggestions(); // start animator - ObjectAnimator oa1 = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 0f, 1f); - oa1.setDuration(ANIMATION_TIME); - ObjectAnimator oa2 = ObjectAnimator.ofFloat(mAddDeleteDrawable, "progress", 0f, 1f); - oa2.setDuration(ANIMATION_TIME); - ObjectAnimator oa3 = ObjectAnimator.ofFloat(this, "progress", 0f, 1f); - oa3.setDuration(ANIMATION_TIME); - oa3.addListener(new SimpleAnimatorListener() { + if (mDrawerArrowDrawable.getProgress() != 1f) { + ObjectAnimator oa1 = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 0f, 1f); + oa1.setDuration(ANIMATION_TIME); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + oa1.setAutoCancel(true); + } + oa1.start(); + } + if (mAddDeleteDrawable.getProgress() != 1f) { + ObjectAnimator oa2 = ObjectAnimator.ofFloat(mAddDeleteDrawable, "progress", 0f, 1f); + oa2.setDuration(ANIMATION_TIME); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + oa2.setAutoCancel(true); + } + oa2.start(); + } + // Show list if needed + if (showList) { + showImeAndSuggestionsList(); + } + } + } + + public void setInNormalMode() { + if (mInEditMode) { + mInEditMode = false; + setOnClickListener(this); + ViewUtils.setVisibility(mTitleTextView, View.VISIBLE); + ViewUtils.setVisibility(mEditText, View.GONE); + // start animator + if (mDrawerArrowDrawable.getProgress() != 0f) { + ObjectAnimator oa1 = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 1f, 0f); + oa1.setDuration(ANIMATION_TIME); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + oa1.setAutoCancel(true); + } + oa1.start(); + } + if (mAddDeleteDrawable.getProgress() != 0f) { + ObjectAnimator oa2 = ObjectAnimator.ofFloat(mAddDeleteDrawable, "progress", 1f, 0f); + oa2.setDuration(ANIMATION_TIME); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + oa2.setAutoCancel(true); + } + oa2.start(); + } + // Hide ime and suggestions list + hideImeAndSuggestionsList(); + } + } + + public void showImeAndSuggestionsList() { + // Show ime + mEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mEditText, 0); + // update suggestion for show suggestions list + updateSuggestions(); + // Show suggestions list + if (mProgress != 1f) { + ObjectAnimator oa = ObjectAnimator.ofFloat(this, "progress", 0f, 1f); + oa.setDuration(ANIMATION_TIME); + oa.addListener(new SimpleAnimatorListener() { @Override public void onAnimationStart(Animator animation) { ViewUtils.setVisibility(mList, View.VISIBLE); @@ -205,33 +256,21 @@ public class SearchBar extends CardView implements View.OnClickListener, } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - oa1.setAutoCancel(true); - oa2.setAutoCancel(true); - oa3.setAutoCancel(true); + oa.setAutoCancel(true); } - oa1.start(); - oa2.start(); - oa3.start(); + oa.start(); } } - public void setInNormalMode() { - if (mInEditMode) { - mInEditMode = false; - setOnClickListener(this); - ViewUtils.setVisibility(mTitleTextView, View.VISIBLE); - ViewUtils.setVisibility(mEditText, View.GONE); - // hide ime - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(this.getWindowToken(), 0); - // start animator - ObjectAnimator oa1 = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 1f, 0f); - oa1.setDuration(ANIMATION_TIME); - ObjectAnimator oa2 = ObjectAnimator.ofFloat(mAddDeleteDrawable, "progress", 1f, 0f); - oa2.setDuration(ANIMATION_TIME); - ObjectAnimator oa3 = ObjectAnimator.ofFloat(this, "progress", 1f, 0f); - oa3.setDuration(ANIMATION_TIME); - oa3.addListener(new SimpleAnimatorListener() { + public void hideImeAndSuggestionsList() { + // Hide ime + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(this.getWindowToken(), 0); + // Hide suggestions list + if (mProgress != 0f) { + ObjectAnimator oa = ObjectAnimator.ofFloat(this, "progress", 1f, 0f); + oa.setDuration(ANIMATION_TIME); + oa.addListener(new SimpleAnimatorListener() { @Override public void onAnimationStart(Animator animation) { mInAnimation = true; @@ -244,13 +283,9 @@ public class SearchBar extends CardView implements View.OnClickListener, } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - oa1.setAutoCancel(true); - oa2.setAutoCancel(true); - oa3.setAutoCancel(true); + oa.setAutoCancel(true); } - oa1.start(); - oa2.start(); - oa3.start(); + oa.start(); } } @@ -312,9 +347,23 @@ public class SearchBar extends CardView implements View.OnClickListener, updateSuggestions(); } + @Override + public void onClick() { + mHelper.onSearchEditTextClick(); + } + + @Override + public void onBackPressed() { + mHelper.onBackPressed(); + } + public interface Helper { + void onClickTitle(); void onClickMenu(); - void onClickAction(); + void onClickArrow(); + void onClickAdvanceSearch(); + void onSearchEditTextClick(); void onApplySearch(String query); + void onBackPressed(); } } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java index 5db8c05ea..dc5d14176 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java @@ -97,7 +97,7 @@ public class SearchDatabase { } public void deleteQuery(final String query) { - mDatabase.delete(TABLE_SUGGESTIONS, COLUMN_DATE + "=?", new String[]{query}); + mDatabase.delete(TABLE_SUGGESTIONS, COLUMN_QUERY + "=?", new String[]{query}); } public void clearQuery() { diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchEditText.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchEditText.java index a5f3687b1..fe9cfd46a 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchEditText.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchEditText.java @@ -19,11 +19,12 @@ import android.content.Context; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.KeyEvent; +import android.view.MotionEvent; import android.widget.EditText; public class SearchEditText extends EditText { - private SearchBar mSearchBar; + private SearchEditTextListener mListener; public SearchEditText(Context context) { super(context); @@ -37,8 +38,8 @@ public class SearchEditText extends EditText { super(context, attrs, defStyleAttr); } - public void setSearchBar(SearchBar searchBar) { - mSearchBar = searchBar; + public void setSearchEditTextListener(SearchEditTextListener listener) { + mListener = listener; } @Override @@ -58,8 +59,8 @@ public class SearchEditText extends EditText { state.handleUpEvent(event); } if (event.isTracking() && !event.isCanceled()) { - if (mSearchBar != null) { - mSearchBar.setInNormalMode(); + if (mListener != null) { + mListener.onBackPressed(); return true; } } @@ -67,4 +68,17 @@ public class SearchEditText extends EditText { } return super.onKeyPreIme(keyCode, event); } + + @Override + public boolean onTouchEvent(@NonNull MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_UP && mListener != null) { + mListener.onClick(); + } + return super.onTouchEvent(event); + } + + public interface SearchEditTextListener { + void onClick(); + void onBackPressed(); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java index 5a9a82cb1..00c24134e 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java @@ -147,8 +147,15 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke mFab.setOnClickListener(this); mFabMarginBottomOrigin = mResources.getDimensionPixelSize(R.dimen.content_fab_margin_bottom); - mSearchPaddingTopOrigin = 0; - mSearchPaddingBottomOrigin = mResources.getDimensionPixelSize(R.dimen.content_padding_bottom); + + // Search Container + mSearchPaddingTopOrigin = mSearchContainer.getPaddingTop(); + mSearchPaddingBottomOrigin = mSearchContainer.getPaddingBottom() + + mResources.getDimensionPixelSize(R.dimen.content_padding_bottom); + mSearchContainer.setPadding( mSearchContainer.getPaddingLeft(), + mSearchContainer.getPaddingTop(), + mSearchContainer.getPaddingRight(), + mSearchPaddingBottomOrigin); } public void setFitPaddingTop(int fitPaddingTop) { @@ -160,16 +167,16 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke ); } - public void setFitPaddingBottom(int paddingBottom) { + public void setFitPaddingBottom(int fitPaddingBottom) { mSearchContainer.setPadding( mSearchContainer.getPaddingLeft(), mSearchContainer.getPaddingTop(), mSearchContainer.getPaddingRight(), - mSearchPaddingBottomOrigin + paddingBottom + mSearchPaddingBottomOrigin + fitPaddingBottom ); LayoutParams lp = (LayoutParams) mFab.getLayoutParams(); - lp.bottomMargin = mFabMarginBottomOrigin + paddingBottom; + lp.bottomMargin = mFabMarginBottomOrigin + fitPaddingBottom; mFab.setLayoutParams(lp); } @@ -177,6 +184,10 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke mHelper = helper; } + public void scrollSearchContainerToTop() { + mLayoutManager.scrollToPositionWithOffset(0, 0); + } + @Override protected void dispatchSaveInstanceState(@NonNull SparseArray container) { super.dispatchSaveInstanceState(container); @@ -494,8 +505,8 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke } public interface SearhLayoutHelper { - public void onRequestSelectImage(); + void onRequestSelectImage(); - public void onRequestSearch(ListUrlBuilder lub); + void onRequestSearch(ListUrlBuilder lub); } } diff --git a/app/src/main/java/com/hippo/scene/Scene.java b/app/src/main/java/com/hippo/scene/Scene.java index fb351a1f0..e1b8b777d 100644 --- a/app/src/main/java/com/hippo/scene/Scene.java +++ b/app/src/main/java/com/hippo/scene/Scene.java @@ -20,7 +20,6 @@ import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.FragmentManager; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; @@ -49,6 +48,7 @@ public abstract class Scene { private @Nullable Curtain mCurtain; + @SuppressWarnings("deprecation") private @Nullable AbsoluteLayout mSceneView; private int mBackgroundColor = 0xffeeeeee; // TODO Need a better to set background color @@ -116,6 +116,7 @@ public abstract class Scene { onCreate(savedInstanceState); if (mSceneView == null) { + //noinspection deprecation mSceneView = new AbsoluteLayout(getStageActivity()); initBackground(mSceneView); } @@ -189,6 +190,7 @@ public abstract class Scene { protected void setContentView(int resId) { StageActivity sa = getStageActivity(); + //noinspection deprecation mSceneView = new AbsoluteLayout(sa); initBackground(mSceneView); mSceneView.setBackgroundColor(mBackgroundColor); @@ -197,6 +199,7 @@ public abstract class Scene { protected void setContentView(View view) { StageActivity sa = getStageActivity(); + //noinspection deprecation mSceneView = new AbsoluteLayout(sa); initBackground(mSceneView); mSceneView.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); @@ -228,14 +231,13 @@ public abstract class Scene { protected void onOut() { } + /** + * It will be called if nav bar is transparent. + * @param b the nav bar's height + */ protected void onGetFitPaddingBottom(int b) { } - - public View onCreateStageBar() { - return null; - } - /** * Finds a view that was identified by the id attribute from the XML that * was processed in {@link #onCreate}. @@ -373,14 +375,6 @@ public abstract class Scene { getStageActivity().startActivityForResult(intent, listener); } - /** - * Return the FragmentManager for interacting with fragments associated - * with StageActivity. - */ - public FragmentManager getSupportFragmentManager() { - return getStageActivity().getSupportFragmentManager(); - } - public interface ActivityResultListener { void onGetResult(int resultCode, Intent data); } diff --git a/app/src/main/java/com/hippo/widget/FloatLabelEditText.java b/app/src/main/java/com/hippo/widget/FloatLabelEditText.java index 6660d2a6a..8cb4f3bda 100644 --- a/app/src/main/java/com/hippo/widget/FloatLabelEditText.java +++ b/app/src/main/java/com/hippo/widget/FloatLabelEditText.java @@ -68,12 +68,6 @@ public class FloatLabelEditText extends FrameLayout { init(context, attrs); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public FloatLabelEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(context, attrs); - } - private void init(Context context, AttributeSet attrs) { mLabel = new TextView(context); addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); diff --git a/app/src/main/java/com/hippo/widget/Hotspotable.java b/app/src/main/java/com/hippo/widget/Hotspotable.java index 9bb6f9a38..5791d8ec4 100644 --- a/app/src/main/java/com/hippo/widget/Hotspotable.java +++ b/app/src/main/java/com/hippo/widget/Hotspotable.java @@ -17,5 +17,5 @@ package com.hippo.widget; public interface Hotspotable { - public void setHotspot(float x, float y); + void setHotspot(float x, float y); } diff --git a/app/src/main/java/com/hippo/widget/SimpleImageView.java b/app/src/main/java/com/hippo/widget/SimpleImageView.java index 8f30d753f..0a9f061d1 100644 --- a/app/src/main/java/com/hippo/widget/SimpleImageView.java +++ b/app/src/main/java/com/hippo/widget/SimpleImageView.java @@ -82,12 +82,16 @@ public class SimpleImageView extends View implements Drawable.Callback { super.onLayout(changed, left, top, right, bottom); int width = right - left; int height = bottom - top; - mDrawable.setBounds(getPaddingLeft(), getPaddingTop(), - width - getPaddingRight(), height - getPaddingBottom()); + if (mDrawable != null) { + mDrawable.setBounds(getPaddingLeft(), getPaddingTop(), + width - getPaddingRight(), height - getPaddingBottom()); + } } @Override protected void onDraw(Canvas canvas) { - mDrawable.draw(canvas); + if (mDrawable != null) { + mDrawable.draw(canvas); + } } } diff --git a/app/src/main/java/com/hippo/widget/recyclerview/MonoRecyclerView.java b/app/src/main/java/com/hippo/widget/recyclerview/MonoRecyclerView.java new file mode 100644 index 000000000..31da5c0d8 --- /dev/null +++ b/app/src/main/java/com/hippo/widget/recyclerview/MonoRecyclerView.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.widget.recyclerview; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; + +import com.hippo.ehviewer.R; + +public class MonoRecyclerView extends EasyRecyclerView { + + public MonoRecyclerView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs); + } + + public MonoRecyclerView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + final TypedArray a = context + .obtainStyledAttributes(attrs, R.styleable.MonoRecyclerView); + int space = a.getDimensionPixelOffset(R.styleable.MonoRecyclerView_space, 0); + int spaceLeft = a.getDimensionPixelOffset(R.styleable.MonoRecyclerView_spaceLeft, space); + int spaceRight = a.getDimensionPixelOffset(R.styleable.MonoRecyclerView_spaceRight, space); + int spaceTop = a.getDimensionPixelOffset(R.styleable.MonoRecyclerView_spaceTop, space); + int spaceBottom = a.getDimensionPixelOffset(R.styleable.MonoRecyclerView_spaceBottom, space); + a.recycle(); + + int halfSpace = space / 2; + MarginItemDecoration itemDecoration = new MarginItemDecoration(halfSpace); + addItemDecoration(itemDecoration); + setPadding(spaceLeft - halfSpace, spaceTop - halfSpace, + spaceRight - halfSpace, spaceBottom - space); + setClipChildren(false); + } +} diff --git a/app/src/main/res/layout/scene_gallery_list.xml b/app/src/main/res/layout/scene_gallery_list.xml index b9c4aebd6..d7adb9a59 100644 --- a/app/src/main/res/layout/scene_gallery_list.xml +++ b/app/src/main/res/layout/scene_gallery_list.xml @@ -37,7 +37,6 @@ android:layout_marginLeft="@dimen/search_bar_padding_horizontal" android:layout_marginRight="@dimen/search_bar_padding_horizontal" android:layout_marginTop="@dimen/search_bar_padding_vertical" - android:layout_marginBottom="@dimen/search_bar_padding_vertical" auto:forceNoElevation="true"/> diff --git a/app/src/main/res/layout/search_category.xml b/app/src/main/res/layout/search_category.xml index e1f208f39..aa448bfcd 100644 --- a/app/src/main/res/layout/search_category.xml +++ b/app/src/main/res/layout/search_category.xml @@ -18,13 +18,11 @@ xmlns:auto="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/search_category_interval" - auto:cardElevation="@dimen/default_elevation"> + auto:forceNoElevation="true"> + android:textColor="@color/secondary_text_light"/> - - - + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 500048989..cc9c74418 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -16,8 +16,12 @@ - 16dp - 16dp + 8dp + 8dp + + + 8dp + 8dp 0dp