From 89e16e4ec56b3a42e7a2c029ac8846a445d18407 Mon Sep 17 00:00:00 2001 From: seven332 Date: Wed, 27 Jan 2016 23:00:08 +0800 Subject: [PATCH] Improve GalleryListScene --- app/build.gradle | 4 +- .../ehviewer/client/data/ListUrlBuilder.java | 16 +- .../ehviewer/ui/scene/GalleryListScene.java | 144 ++++++--- .../ehviewer/widget/FitPaddingLayout.java | 273 ++++++++++++++++++ .../ehviewer/widget/SearchBarLayout.java | 103 ------- .../java/com/hippo/widget/LoadImageView.java | 2 +- .../main/res/layout/scene_gallery_list.xml | 14 +- app/src/main/res/values/attrs.xml | 10 +- app/src/main/res/values/strings.xml | 2 + conaco | 2 +- yorozuya | 2 +- 11 files changed, 413 insertions(+), 159 deletions(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/widget/FitPaddingLayout.java delete mode 100644 app/src/main/java/com/hippo/ehviewer/widget/SearchBarLayout.java diff --git a/app/build.gradle b/app/build.gradle index a3a2b2fd2..ad3da0b2b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,8 +51,8 @@ android { } clean { - delete file('src/main/obj').absolutePath - delete file('src/main/libs').absolutePath + //delete file('src/main/obj').absolutePath + //delete file('src/main/libs').absolutePath } dependencies { diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java b/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java index 7122a82f2..6fcf18494 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java @@ -133,15 +133,15 @@ public class ListUrlBuilder implements Cloneable, Parcelable { /** * Make them the same - * @param glub The template + * @param lub The template */ - public void set(ListUrlBuilder glub) { - mMode = glub.mMode; - mPageIndex = glub.mPageIndex; - mCategory = glub.mCategory; - mKeyword = glub.mKeyword; - mAdvanceSearch = glub.mAdvanceSearch; - mMinRating = glub.mMinRating; + public void set(ListUrlBuilder lub) { + mMode = lub.mMode; + mPageIndex = lub.mPageIndex; + mCategory = lub.mCategory; + mKeyword = lub.mKeyword; + mAdvanceSearch = lub.mAdvanceSearch; + mMinRating = lub.mMinRating; } /* 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 00f5a6700..5e59b2498 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 @@ -37,7 +37,6 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.style.ImageSpan; import android.transition.TransitionInflater; -import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -61,8 +60,8 @@ import com.hippo.ehviewer.client.EhUtils; import com.hippo.ehviewer.client.data.GalleryInfo; import com.hippo.ehviewer.client.data.ListUrlBuilder; import com.hippo.ehviewer.client.parser.GalleryListParser; +import com.hippo.ehviewer.widget.FitPaddingLayout; import com.hippo.ehviewer.widget.SearchBar; -import com.hippo.ehviewer.widget.SearchBarLayout; import com.hippo.ehviewer.widget.SearchLayout; import com.hippo.ehviewer.widget.SimpleRatingView; import com.hippo.rippleold.RippleSalon; @@ -78,8 +77,6 @@ import com.hippo.yorozuya.MathUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -// TODO store list data to temp file in onSaveInstanceState and save file path -// TODO new view fill recreate onResume, so remember to save, restore and free memory public final class GalleryListScene extends BaseScene implements EasyRecyclerView.OnItemClickListener, SearchBar.Helper, SearchBar.OnStateChangeListener, FastScroller.OnDragHandlerListener, @@ -97,6 +94,8 @@ public final class GalleryListScene extends BaseScene public final static String ACTION_SEARCH = "action_search"; public final static String KEY_LIST_URL_BUILDER = "list_url_builder"; + public final static String KEY_HAS_FIRST_REFRESH = "has_first_refresh"; + public final static String KEY_STATE = "state"; private final static int STATE_NORMAL = 0; private final static int STATE_SIMPLE_SEARCH = 1; @@ -107,8 +106,7 @@ public final class GalleryListScene extends BaseScene private EhClient mClient; - private SearchBarLayout mSearchBarLayout; - private ContentLayout mContentLayout; + private FitPaddingLayout mFitPaddingLayout; private EasyRecyclerView mRecyclerView; private SearchLayout mSearchLayout; private SearchBar mSearchBar; @@ -131,8 +129,12 @@ public final class GalleryListScene extends BaseScene // Double click back exit private long mPressBackTime = 0; + private EhRequest mRequest; + private Animator.AnimatorListener mFabAnimatorListener = null; + private boolean mHasFirstRefresh = false; + @Override public int getLaunchMode() { return LAUNCH_MODE_SINGLE_TOP; @@ -170,10 +172,6 @@ public final class GalleryListScene extends BaseScene @Override public void onCreate(@Nullable Bundle savedInstanceState) { - - Log.d("TAG", "GalleryListScene onCreate"); - - super.onCreate(savedInstanceState); mClient = EhApplication.getEhClient(getContext()); @@ -237,30 +235,39 @@ public final class GalleryListScene extends BaseScene setNavCheckedItem(checkedItemId); } + private void restoreState(@Nullable Bundle savedInstanceState) { + if (savedInstanceState == null) { + return; + } + + mHasFirstRefresh = savedInstanceState.getBoolean(KEY_HAS_FIRST_REFRESH); + mUrlBuilder = savedInstanceState.getParcelable(KEY_LIST_URL_BUILDER); + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - - Log.d("TAG", "GalleryListScene onCreateView"); + // Restore url builder + restoreState(savedInstanceState); View view = inflater.inflate(R.layout.scene_gallery_list, container, false); Resources resources = getContext().getResources(); - mSearchBarLayout = (SearchBarLayout) view.findViewById(R.id.search_bar_layout); - mContentLayout = (ContentLayout) mSearchBarLayout.findViewById(R.id.content_layout); - mRecyclerView = mContentLayout.getRecyclerView(); - mSearchLayout = (SearchLayout) mSearchBarLayout.findViewById(R.id.search_layout); - mSearchBar = (SearchBar) mSearchBarLayout.findViewById(R.id.search_bar); - mFab = (FloatingActionButton) mSearchBarLayout.findViewById(R.id.fab); + mFitPaddingLayout = (FitPaddingLayout) view.findViewById(R.id.search_bar_layout); + ContentLayout contentLayout = (ContentLayout) mFitPaddingLayout.findViewById(R.id.content_layout); + mRecyclerView = contentLayout.getRecyclerView(); + mSearchLayout = (SearchLayout) mFitPaddingLayout.findViewById(R.id.search_layout); + mSearchBar = (SearchBar) mFitPaddingLayout.findViewById(R.id.search_bar); + mFab = (FloatingActionButton) mFitPaddingLayout.findViewById(R.id.fab); - mViewTransition = new ViewTransition(mContentLayout, mSearchLayout); + mViewTransition = new ViewTransition(contentLayout, mSearchLayout); mHelper = new GalleryListHelper(); mHelper.setEmptyString(resources.getString(R.string.gallery_list_empty_hit)); - mContentLayout.setHelper(mHelper); - mContentLayout.getFastScroller().setOnDragHandlerListener(this); + contentLayout.setHelper(mHelper); + contentLayout.getFastScroller().setOnDragHandlerListener(this); mAdapter = new GalleryListAdapter(); mRecyclerView.setAdapter(mAdapter); @@ -294,23 +301,63 @@ public final class GalleryListScene extends BaseScene mRecyclerView.addOnScrollListener(mSearchBarMoveHelper); mSearchLayout.addOnScrollListener(mSearchBarMoveHelper); - // Refresh + // Update list url builder onUpdateUrlBuilder(); - mHelper.firstRefresh(); + + // Only refresh for the first time + if (!mHasFirstRefresh) { + mHasFirstRefresh = true; + mHelper.firstRefresh(); + } else { + // Restore state + int newState = mState; + mState = STATE_NORMAL; + setState(newState, false); + } return view; } @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putParcelable(KEY_LIST_URL_BUILDER, mUrlBuilder); + public void onDestroyView() { + super.onDestroyView(); + + // End animation + mSearchBarMoveHelper.cancelAnimation(); + + // Cancel request + if (mRequest != null) { + mRequest.cancel(); + } + + mFitPaddingLayout = null; + mRecyclerView = null; + mSearchLayout = null; + mSearchBar = null; + mFab = null; + mViewTransition = null; + mAdapter = null; + mHelper = null; + mLeftDrawable = null; + mRightDrawable = null; + mSearchBarMoveHelper = null; + mFabAnimatorListener = null; + mRequest = null; } @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(KEY_HAS_FIRST_REFRESH, mHasFirstRefresh); + outState.putParcelable(KEY_LIST_URL_BUILDER, mUrlBuilder); + outState.putInt(KEY_STATE, mState); + } + + @Override + @SuppressWarnings("WrongConstant") protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); - mUrlBuilder = savedInstanceState.getParcelable(KEY_LIST_URL_BUILDER); + setState(savedInstanceState.getInt(KEY_STATE), false); } @Override @@ -410,7 +457,7 @@ public final class GalleryListScene extends BaseScene mFabAnimatorListener = new SimpleAnimatorListener() { @Override public void onAnimationEnd(Animator animation) { - mFab.setVisibility(View.GONE); + mFab.setVisibility(View.INVISIBLE); } }; } @@ -574,9 +621,9 @@ public final class GalleryListScene extends BaseScene @Override public void onStateChange(SearchBar searchBar, int newState, int oldState, boolean animation) { if (newState == SearchBar.STATE_NORMAL) { - mSearchBarLayout.setEnableUpdatePaddingTop(true); + mFitPaddingLayout.setEnableUpdatePaddingTop(true); } else { - mSearchBarLayout.setEnableUpdatePaddingTop(false); + mFitPaddingLayout.setEnableUpdatePaddingTop(false); } switch (oldState) { @@ -609,6 +656,12 @@ public final class GalleryListScene extends BaseScene private ValueAnimator mSearchBarMoveAnimator; + public void cancelAnimation() { + if (mSearchBarMoveAnimator != null) { + mSearchBarMoveAnimator.cancel(); + } + } + @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState){ if (newState == RecyclerView.SCROLL_STATE_IDLE && isVaildView(recyclerView)) { @@ -653,6 +706,11 @@ public final class GalleryListScene extends BaseScene } private void returnSearchBarPosition() { + if (mSearchBar.getHeight() == 0) { + // Layout not called + return; + } + boolean show; if (mState == STATE_SIMPLE_SEARCH || mState == STATE_SEARCH_SHOW_LIST) { show = true; @@ -689,6 +747,9 @@ public final class GalleryListScene extends BaseScene boolean hasRequestLayout; @Override public void onAnimationUpdate(ValueAnimator animation) { + if (mSearchBar == null) { + return; + } int value = (Integer) animation.getAnimatedValue(); int offsetStep = value - lastValue; lastValue = value; @@ -714,7 +775,8 @@ public final class GalleryListScene extends BaseScene } private void showSearchBar(boolean animation) { - if (mSearchBar.isLayoutRequested()) { + if (mSearchBar.getHeight() == 0) { + // Layout not called return; } @@ -842,6 +904,7 @@ public final class GalleryListScene extends BaseScene String url = mUrlBuilder.build(); EhRequest request = new EhRequest(); + mRequest = request; request.setMethod(EhClient.METHOD_GET_GALLERY_LIST); request.setCallback(new GetGalleryListListener(taskId)); request.setArgs(url); @@ -879,19 +942,28 @@ public final class GalleryListScene extends BaseScene @Override public void onSuccess(GalleryListParser.Result result) { - mHelper.setPages(mTaskId, result.pages); - mHelper.onGetPageData(mTaskId, result.galleryInfos); - mSearchBarMoveHelper.returnSearchBarPosition(); + if (mHelper != null && mHelper.isCurrentTask(mTaskId)) { + mRequest = null; + mHelper.setPages(mTaskId, result.pages); + mHelper.onGetPageData(mTaskId, result.galleryInfos); + mSearchBarMoveHelper.returnSearchBarPosition(); + } } @Override public void onFailure(Exception e) { - mHelper.onGetExpection(mTaskId, e); - mSearchBarMoveHelper.returnSearchBarPosition(); + if (mHelper != null && mHelper.isCurrentTask(mTaskId)) { + mRequest = null; + mHelper.onGetExpection(mTaskId, e); + mSearchBarMoveHelper.returnSearchBarPosition(); + } } @Override public void onCancel() { + if (mHelper != null && mHelper.isCurrentTask(mTaskId)) { + mRequest = null; + } } } } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/FitPaddingLayout.java b/app/src/main/java/com/hippo/ehviewer/widget/FitPaddingLayout.java new file mode 100644 index 000000000..8596e1b9e --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/widget/FitPaddingLayout.java @@ -0,0 +1,273 @@ +/* + * Copyright 2016 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * 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.ehviewer.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.os.Bundle; +import android.os.Parcelable; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.View; + +import com.hippo.ehviewer.R; +import com.hippo.widget.OffsetLayout; +import com.hippo.yorozuya.IntList; +import com.hippo.yorozuya.SimpleHandler; + +import java.util.ArrayList; +import java.util.List; + +public class FitPaddingLayout extends OffsetLayout { + + private static final String KEY_SUPER = "super"; + private static final String KEY_PADDING_TOP_1 = "padding_top_1"; + private static final String KEY_PADDING_TOP_2 = "padding_top_2"; + private static final String KEY_PADDING_TOP_3 = "padding_top_3"; + private static final String KEY_PADDING_BOTTOM_1 = "padding_bottom_1"; + private static final String KEY_PADDING_BOTTOM_2 = "padding_bottom_2"; + private static final String KEY_PADDING_BOTTOM_3 = "padding_bottom_3"; + + private int mFitTop1; + private int mFitTop2; + private int mFitTop3; + private int mContentId1; + private int mContentId2; + private int mContentId3; + private int mFitBottom1; + private int mFitBottom2; + private int mFitBottom3; + + private boolean mOnce; + + private int mOriginalPaddingTop1 = -1; + private int mOriginalPaddingTop2 = -1; + private int mOriginalPaddingTop3 = -1; + private int mOriginalPaddingBottom1 = -1; + private int mOriginalPaddingBottom2 = -1; + private int mOriginalPaddingBottom3 = -1; + + private boolean mEnableUpdatePaddingTop = true; + + private boolean mUpdated = false; + + private List mContentList = new ArrayList<>(); + private IntList mPaddingTopList = new IntList(); + private IntList mPaddingBottomList = new IntList(); + + private Runnable mUpdatePaddingTask = new Runnable() { + @Override + public void run() { + for (int i = 0, size = mContentList.size(); i < size; i++) { + View content = mContentList.get(i); + int paddingTop = mPaddingTopList.get(i); + int paddingBottom = mPaddingBottomList.get(i); + content.setPadding(content.getPaddingLeft(), + paddingTop == -1 ? content.getPaddingTop() : paddingTop, + content.getPaddingRight(), + paddingBottom == -1 ? content.getPaddingBottom() : paddingBottom); + } + } + }; + + public FitPaddingLayout(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs); + } + + public FitPaddingLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FitPaddingLayout); + mFitTop1 = a.getResourceId(R.styleable.FitPaddingLayout_fitTop1, 0); + mFitTop2 = a.getResourceId(R.styleable.FitPaddingLayout_fitTop2, 0); + mFitTop3 = a.getResourceId(R.styleable.FitPaddingLayout_fitTop3, 0); + mContentId1 = a.getResourceId(R.styleable.FitPaddingLayout_content1, 0); + mContentId2 = a.getResourceId(R.styleable.FitPaddingLayout_content2, 0); + mContentId3 = a.getResourceId(R.styleable.FitPaddingLayout_content3, 0); + mFitBottom1 = a.getResourceId(R.styleable.FitPaddingLayout_fitBottom1, 0); + mFitBottom2 = a.getResourceId(R.styleable.FitPaddingLayout_fitBottom2, 0); + mFitBottom3 = a.getResourceId(R.styleable.FitPaddingLayout_fitBottom3, 0); + mOnce = a.getBoolean(R.styleable.FitPaddingLayout_once, true); + a.recycle(); + } + + public void setEnableUpdatePaddingTop(boolean enableUpdatePaddingTop) { + mEnableUpdatePaddingTop = enableUpdatePaddingTop; + } + + @Nullable + private View findViewByIdEx(int id) { + return id == 0 ? null : findViewById(id); + } + + private boolean updatePadding(View content, View fitTop, View fitBottom, + int originalPaddingTop, int originalPaddingBottom, int[] paddings, int[] newPaddins) { + if (content == null || (fitTop == null && fitBottom == null)) { + return false; + } + if (originalPaddingTop == -1) { + originalPaddingTop = content.getPaddingTop(); + } + if (originalPaddingBottom == -1) { + originalPaddingBottom = content.getPaddingBottom(); + } + paddings[0] = originalPaddingTop; + paddings[1] = originalPaddingBottom; + + int newPaddingTop = -1; + int newPaddingBottom = -1; + if (fitTop != null) { + newPaddingTop = fitTop.getBottom() - ((LayoutParams) fitTop.getLayoutParams()).offsetY; + } + if (fitBottom != null) { + newPaddingBottom = getHeight() - fitBottom.getTop() - ((LayoutParams) fitBottom.getLayoutParams()).offsetY; + } + newPaddins[0] = newPaddingTop; + newPaddins[1] = newPaddingBottom; + + return true; + } + + private boolean isNeedUpdatePadding(View content, int paddingTop, int paddingBottom) { + return (paddingTop != -1 || paddingTop != content.getPaddingTop()) || + (paddingBottom != -1 || paddingBottom != content.getPaddingBottom()); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + + if (!mEnableUpdatePaddingTop || (mOnce && mUpdated)) { + return; + } + + View fitTop1 = findViewById(mFitTop1); + View fitTop2 = findViewById(mFitTop2); + View fitTop3 = findViewById(mFitTop3); + View content1 = findViewById(mContentId1); + View content2 = findViewById(mContentId2); + View content3 = findViewById(mContentId3); + View fitBottom1 = findViewById(mFitBottom1); + View fitBottom2 = findViewById(mFitBottom2); + View fitBottom3 = findViewById(mFitBottom3); + + mContentList.clear(); + mPaddingTopList.clear(); + mPaddingBottomList.clear(); + + int[] paddings = new int[2]; + int[] newPaddings = new int[2]; + if (updatePadding(content1, fitTop1, fitBottom1, mOriginalPaddingTop1, + mOriginalPaddingBottom1, paddings, newPaddings)) { + mOriginalPaddingTop1 = paddings[0]; + mOriginalPaddingBottom1 = paddings[1]; + if (isNeedUpdatePadding(content1, newPaddings[0], newPaddings[1])) { + mContentList.add(content1); + mPaddingTopList.add(newPaddings[0]); + mPaddingBottomList.add(newPaddings[1]); + } + } + if (updatePadding(content2, fitTop2, fitBottom2, mOriginalPaddingTop2, + mOriginalPaddingBottom2, paddings, newPaddings)) { + mOriginalPaddingTop2 = paddings[0]; + mOriginalPaddingBottom2 = paddings[1]; + if (isNeedUpdatePadding(content2, newPaddings[0], newPaddings[1])) { + mContentList.add(content2); + mPaddingTopList.add(newPaddings[0]); + mPaddingBottomList.add(newPaddings[1]); + } + } + if (updatePadding(content3, fitTop3, fitBottom3, mOriginalPaddingTop3, + mOriginalPaddingBottom3, paddings, newPaddings)) { + mOriginalPaddingTop3 = paddings[0]; + mOriginalPaddingBottom3 = paddings[1]; + if (isNeedUpdatePadding(content3, newPaddings[0], newPaddings[1])) { + mContentList.add(content3); + mPaddingTopList.add(newPaddings[0]); + mPaddingBottomList.add(newPaddings[1]); + } + } + + if (mContentList.size() > 0) { + SimpleHandler.getInstance().post(mUpdatePaddingTask); + } + + mUpdated = true; + } + + private void saveContentPadding(Bundle state, int id, String topKey, String bottomKey) { + View content = findViewByIdEx(id); + if (content != null) { + state.putInt(topKey, content.getPaddingTop()); + state.putInt(bottomKey, content.getPaddingBottom()); + } else { + state.putInt(topKey, -1); + state.putInt(bottomKey, -1); + } + } + + @Override + protected Parcelable onSaveInstanceState() { + final Bundle state = new Bundle(); + state.putParcelable(KEY_SUPER, super.onSaveInstanceState()); + saveContentPadding(state, mContentId1, KEY_PADDING_TOP_1, KEY_PADDING_BOTTOM_1); + saveContentPadding(state, mContentId2, KEY_PADDING_TOP_2, KEY_PADDING_BOTTOM_2); + saveContentPadding(state, mContentId3, KEY_PADDING_TOP_3, KEY_PADDING_BOTTOM_3); + return state; + } + + private void restoreContentPadding(Bundle state, int id, String topKey, String bottomKey, int[] paddings) { + View content = findViewByIdEx(id); + if (content != null) { + paddings[0] = content.getPaddingTop(); + paddings[1] = content.getPaddingBottom(); + int paddingTop = state.getInt(topKey); + int paddingBottom = state.getInt(bottomKey); + if (paddingTop != -1 || paddingBottom != -1) { + content.setPadding(content.getPaddingLeft(), + paddingTop == -1 ? content.getPaddingTop() : paddingTop, + content.getPaddingRight(), + paddingBottom == -1 ? content.getPaddingBottom() : paddingBottom); + } + } else { + paddings[0] = -1; + paddings[1] = -1; + } + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state instanceof Bundle) { + final Bundle savedState = (Bundle) state; + super.onRestoreInstanceState(savedState.getParcelable(KEY_SUPER)); + int[] ints = new int[2]; + restoreContentPadding(savedState, mContentId1, KEY_PADDING_TOP_1, KEY_PADDING_BOTTOM_1, ints); + mOriginalPaddingTop1 = ints[0]; + mOriginalPaddingBottom1 = ints[1]; + restoreContentPadding(savedState, mContentId2, KEY_PADDING_TOP_2, KEY_PADDING_BOTTOM_2, ints); + mOriginalPaddingTop2 = ints[0]; + mOriginalPaddingBottom2 = ints[1]; + restoreContentPadding(savedState, mContentId3, KEY_PADDING_TOP_3, KEY_PADDING_BOTTOM_3, ints); + mOriginalPaddingTop3 = ints[0]; + mOriginalPaddingBottom3 = ints[1]; + } + } +} diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBarLayout.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBarLayout.java deleted file mode 100644 index cc01e8007..000000000 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBarLayout.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2016 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 - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.ehviewer.widget; - -import android.content.Context; -import android.content.res.TypedArray; -import android.support.annotation.Nullable; -import android.util.AttributeSet; -import android.view.View; -import com.hippo.ehviewer.R; -import com.hippo.widget.OffsetLayout; - -public class SearchBarLayout extends OffsetLayout { - - private int mSearchBarId; - private int mContentId1; - private int mContentId2; - private int mContentId3; - - private int mContentOriginalPaddingTop1 = -1; - private int mContentOriginalPaddingTop2 = -1; - private int mContentOriginalPaddingTop3 = -1; - - private boolean mEnableUpdatePaddingTop = true; - - public SearchBarLayout(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs); - } - - public SearchBarLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context, attrs); - } - - private void init(Context context, AttributeSet attrs) { - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchBarLayout); - mSearchBarId = a.getResourceId(R.styleable.SearchBarLayout_search_bar, 0); - mContentId1 = a.getResourceId(R.styleable.SearchBarLayout_content1, 0); - mContentId2 = a.getResourceId(R.styleable.SearchBarLayout_content2, 0); - mContentId3 = a.getResourceId(R.styleable.SearchBarLayout_content3, 0); - a.recycle(); - } - - public void setEnableUpdatePaddingTop(boolean enableUpdatePaddingTop) { - mEnableUpdatePaddingTop = enableUpdatePaddingTop; - } - - private void updateContentPadding(@Nullable View content, int newPaddingTop) { - if (content != null && newPaddingTop != content.getPaddingTop()) { - content.setPadding(content.getPaddingLeft(), newPaddingTop, - content.getPaddingRight(), content.getPaddingBottom()); - } - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - - if (!mEnableUpdatePaddingTop) { - return; - } - - if (mSearchBarId != 0 && (mContentId1 != 0 || mContentId2 != 0 || mContentId3 != 0)) { - View searchBar = findViewById(mSearchBarId); - View content1 = findViewById(mContentId1); - View content2 = findViewById(mContentId2); - View content3 = findViewById(mContentId3); - if (searchBar != null && (content1 != null || content2 != null || content3 != null)) { - // Get content original padding top - if (mContentOriginalPaddingTop1 == -1 && content1 != null) { - mContentOriginalPaddingTop1 = content1.getPaddingTop(); - } - if (mContentOriginalPaddingTop2 == -1 && content2 != null) { - mContentOriginalPaddingTop2 = content2.getPaddingTop(); - } - if (mContentOriginalPaddingTop3 == -1 && content3 != null) { - mContentOriginalPaddingTop3 = content3.getPaddingTop(); - } - - int paddingTopOffset = searchBar.getBottom() - - ((LayoutParams) searchBar.getLayoutParams()).offsetY; - updateContentPadding(content1, paddingTopOffset + mContentOriginalPaddingTop1); - updateContentPadding(content2, paddingTopOffset + mContentOriginalPaddingTop2); - updateContentPadding(content3, paddingTopOffset + mContentOriginalPaddingTop3); - } - } - } -} diff --git a/app/src/main/java/com/hippo/widget/LoadImageView.java b/app/src/main/java/com/hippo/widget/LoadImageView.java index 6e6798107..b39c35432 100644 --- a/app/src/main/java/com/hippo/widget/LoadImageView.java +++ b/app/src/main/java/com/hippo/widget/LoadImageView.java @@ -39,7 +39,7 @@ import com.hippo.ehviewer.R; public class LoadImageView extends FixedAspectImageView implements Unikery, View.OnClickListener, View.OnLongClickListener { - private int mTaskId = Unikery.INVAILD_ID; + private int mTaskId = Unikery.INVALID_ID; private Conaco mConaco; diff --git a/app/src/main/res/layout/scene_gallery_list.xml b/app/src/main/res/layout/scene_gallery_list.xml index f36cf0bb0..ace2af9f5 100644 --- a/app/src/main/res/layout/scene_gallery_list.xml +++ b/app/src/main/res/layout/scene_gallery_list.xml @@ -15,16 +15,20 @@ ~ limitations under the License. --> - + app:fitTop2="@+id/search_bar" + app:content3="@+id/search_layout" + app:fitTop3="@+id/search_bar" + app:fitBottom3="@+id/fab" + app:once="true"> + android:visibility="invisible"/> - + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 9241cbf1e..77c443c08 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -40,11 +40,17 @@ - - + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c67723b5..36e5aacc2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,6 +90,8 @@ Press twice to exit + Click to retry + Search ExHentai.org The World is Big and Pandas sit alone diff --git a/conaco b/conaco index a6a291f16..a6d0f5a7a 160000 --- a/conaco +++ b/conaco @@ -1 +1 @@ -Subproject commit a6a291f16e547709b25155d08d5d1852edd08e5a +Subproject commit a6d0f5a7a6232941af33cccd0ec1a2107140fd1d diff --git a/yorozuya b/yorozuya index 8a8ca50a3..8d2a07ead 160000 --- a/yorozuya +++ b/yorozuya @@ -1 +1 @@ -Subproject commit 8a8ca50a367ddad56de07eeb3a34d77293c12f8f +Subproject commit 8d2a07ead62485d09223ded67176e924779af2da