Improve GalleryListScene
This commit is contained in:
1 parent
fd60291d7b
commit
89e16e4ec5
11 files changed
+413
-159
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<View> 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import com.hippo.ehviewer.R;
|
||||
public class LoadImageView extends FixedAspectImageView implements Unikery<ImageWrapper>,
|
||||
View.OnClickListener, View.OnLongClickListener {
|
||||
|
||||
private int mTaskId = Unikery.INVAILD_ID;
|
||||
private int mTaskId = Unikery.INVALID_ID;
|
||||
|
||||
private Conaco<ImageWrapper> mConaco;
|
||||
|
||||
|
||||
Reference in new issue
Block a user