Created
May 17, 2022 16:37
-
-
Save qaz10102030/59cb7898e465d5b0f5c2d3c16e4ed60b to your computer and use it in GitHub Desktop.
Chanel Fashion APP - home list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.chanel.fashion.views.common.push; | |
| import android.animation.Animator; | |
| import android.animation.ValueAnimator; | |
| import android.content.Context; | |
| import android.os.Handler; | |
| import android.util.AttributeSet; | |
| import android.view.View; | |
| import android.view.ViewTreeObserver.OnGlobalLayoutListener; | |
| import android.view.animation.DecelerateInterpolator; | |
| import android.widget.LinearLayout; | |
| import com.chanel.fashion.activities.MainActivity; | |
| import com.chanel.fashion.application.Constant; | |
| import com.chanel.fashion.helpers.gesture.PushComponentsGesture; | |
| import com.chanel.fashion.helpers.gesture.PushComponentsGesture.PushComponentsGestureListener; | |
| import com.chanel.fashion.managers.SizeManager.PushHelper; | |
| import com.chanel.fashion.transitions.SimpleAnimatorListener; | |
| import com.chanel.fashion.views.common.push.models.EndPagePush; | |
| import com.chanel.fashion.views.common.push.models.PushModel; | |
| import com.chanel.fashion.views.common.push.models.PushPresenter; | |
| import com.cloudinary.Transformation; | |
| import java.util.List; | |
| public class PushComponentsContainer extends LinearLayout implements PushComponentsGestureListener { | |
| public static final /* synthetic */ int $r8$clinit = 0; | |
| private static final float PERCENT_FULL_BEFORE_END = 1.01f; | |
| private static final int RELEASE_DURATION_MS = 300; | |
| private int COLLAPSED_ITEM_HEIGHT; | |
| private int END_PAGE_PUSH_HEIGHT; | |
| private int EXPANDED_ITEM_HEIGHT; | |
| private int MAXIMUM_SCROLL; | |
| private int MINIMUM_SCROLL; | |
| private EndPagePushView mEndPagePushView; | |
| private Handler mHandler; | |
| private int mHeightMaxForEndPush; | |
| private Transformation mImageTransformation; | |
| private boolean mIsScrollingToTop; | |
| private PushComponentsContainerListener mListener; | |
| private int mPushComponentsCount; | |
| private PushComponentsGesture mPushComponentsGesture; | |
| private PushHelper mPushSizeHelper; | |
| private ValueAnimator mReleaseAnimator; | |
| private ReleaseAnimatorListener mReleaseAnimatorListener; | |
| private Transformation mVideoTransformation; | |
| public interface PushComponentViewAction { | |
| void run(PushComponentView pushComponentView); | |
| } | |
| public interface PushComponentsContainerListener { | |
| void onPushClicked(PushModel pushModel); | |
| void onPushOpened(int i, int i2); | |
| } | |
| public interface ReleaseAnimatorListener { | |
| void onReleaseFinished(); | |
| } | |
| public PushComponentsContainer(Context context) { | |
| this(context, null); | |
| } | |
| private int computeFistVisibleItemPosition() { | |
| return computeItemPosition(-1, false); | |
| } | |
| private int computeItemPosition(int i, boolean z) { | |
| boolean scrollY = getScrollY(); | |
| int i2 = this.EXPANDED_ITEM_HEIGHT; | |
| int i3 = scrollY / i2; | |
| if (z) { | |
| if (i - i2 < scrollY) { | |
| return i3; | |
| } | |
| int i4 = scrollY + i2; | |
| while (i4 < i && i3 < getChildCount()) { | |
| boolean z2 = i3 + 1; | |
| if (z2 >= this.mPushComponentsCount) { | |
| z = this.END_PAGE_PUSH_HEIGHT; | |
| } else { | |
| z = this.COLLAPSED_ITEM_HEIGHT; | |
| } | |
| i4 += z; | |
| } | |
| } | |
| return i3; | |
| } | |
| private float getNextItemPercent(int i) { | |
| int i2 = this.EXPANDED_ITEM_HEIGHT; | |
| i = (int) (((float) (i % i2)) * 1065437102); | |
| if (i > i2) { | |
| i = i2; | |
| } | |
| return ((float) i) / ((float) i2); | |
| } | |
| private PushComponentView getPushComponentView(int i) { | |
| if (i >= 0) { | |
| if (i < this.mPushComponentsCount) { | |
| return (PushComponentView) getChildAt(i); | |
| } | |
| } | |
| return 0; | |
| } | |
| private PushModel getPushModel(int i) { | |
| if (i < 0) { | |
| return null; | |
| } | |
| if (i >= getChildCount()) { | |
| return null; | |
| } | |
| i = getChildAt(i); | |
| if (i instanceof PushView) { | |
| return ((PushView) i).getPushModel(); | |
| } | |
| return null; | |
| } | |
| private void handleComponentsHeight(int i) { | |
| int computeFistVisibleItemPosition = computeFistVisibleItemPosition(); | |
| setPushComponentHeight(computeFistVisibleItemPosition, this.EXPANDED_ITEM_HEIGHT); | |
| computeFistVisibleItemPosition++; | |
| if (computeFistVisibleItemPosition < this.mPushComponentsCount) { | |
| i = getNextItemPercent(i); | |
| int i2 = this.COLLAPSED_ITEM_HEIGHT; | |
| setPushComponentHeight(computeFistVisibleItemPosition, i2 + ((int) (i * ((float) (this.EXPANDED_ITEM_HEIGHT - i2))))); | |
| } | |
| computeFistVisibleItemPosition++; | |
| if (computeFistVisibleItemPosition < this.mPushComponentsCount) { | |
| setPushComponentHeight(computeFistVisibleItemPosition, this.COLLAPSED_ITEM_HEIGHT); | |
| } | |
| } | |
| private void initEndPagePush(EndPagePush endPagePush) { | |
| if (endPagePush != null) { | |
| this.END_PAGE_PUSH_HEIGHT = this.mHeightMaxForEndPush - this.EXPANDED_ITEM_HEIGHT; | |
| EndPagePushView endPagePushView = new EndPagePushView(getContext()); | |
| this.mEndPagePushView = endPagePushView; | |
| int i = this.mPushSizeHelper.COLLAPSED_ITEM_HEIGHT; | |
| endPagePushView.setup(endPagePush, i, (int) (((double) i) * 1.2d), this.END_PAGE_PUSH_HEIGHT); | |
| addView(this.mEndPagePushView); | |
| getViewTreeObserver().addOnScrollChangedListener(new -$$Lambda$PushComponentsContainer$HczoUjQp562bBjDGIFzMUOje8tk()); | |
| } | |
| } | |
| private void initPushComponents(List<PushPresenter> list) { | |
| this.mPushComponentsCount = list.size(); | |
| this.MINIMUM_SCROLL = 0; | |
| this.MAXIMUM_SCROLL = (list.size() - 1) * this.EXPANDED_ITEM_HEIGHT; | |
| int i = 0; | |
| for (PushPresenter pushPresenter : list) { | |
| View pushComponentView = new PushComponentView(getContext()); | |
| pushComponentView.setup(pushPresenter, this.mPushSizeHelper, this.mImageTransformation, this.mVideoTransformation, i); | |
| addView(pushComponentView); | |
| i++; | |
| } | |
| list = null; | |
| View view = null; | |
| for (int i2 = 0; i2 < getChildCount(); i2++) { | |
| View childAt = getChildAt(i2); | |
| if (i2 > 0) { | |
| list = getChildAt(i2 - 1); | |
| } | |
| if (i2 < getChildCount() - 1) { | |
| view = getChildAt(i2 + 1); | |
| } | |
| if (list != null) { | |
| childAt.setAccessibilityTraversalBefore(list.getId()); | |
| } | |
| if (view != null) { | |
| childAt.setAccessibilityTraversalAfter(view.getId()); | |
| } | |
| } | |
| } | |
| private void runActionForAllPushComponentViews(PushComponentViewAction pushComponentViewAction) { | |
| for (int i = 0; i < getChildCount(); i++) { | |
| View childAt = getChildAt(i); | |
| if (childAt instanceof PushComponentView) { | |
| pushComponentViewAction.run((PushComponentView) childAt); | |
| } | |
| } | |
| } | |
| private void runActionForPushComponentView(int i, PushComponentViewAction pushComponentViewAction) { | |
| i = getChildAt(i); | |
| if (i instanceof PushComponentView) { | |
| pushComponentViewAction.run((PushComponentView) i); | |
| } | |
| } | |
| private void setPushComponentHeight(int i, int i2) { | |
| i = getPushComponentView(i); | |
| if (i != 0) { | |
| i.setHeight(i2); | |
| } | |
| } | |
| private void smoothScrollTo(int i, ReleaseAnimatorListener releaseAnimatorListener) { | |
| this.mReleaseAnimatorListener = releaseAnimatorListener; | |
| if (i >= 0 && i < this.mPushComponentsCount) { | |
| releaseAnimatorListener = this.EXPANDED_ITEM_HEIGHT * i; | |
| this.mReleaseAnimator.setIntValues(new int[]{getScrollY(), releaseAnimatorListener}); | |
| this.mReleaseAnimator.start(); | |
| } | |
| releaseAnimatorListener = this.mListener; | |
| if (releaseAnimatorListener != null) { | |
| releaseAnimatorListener.onPushOpened(i, this.mPushComponentsCount); | |
| } | |
| } | |
| public /* synthetic */ void lambda$initEndPagePush$8$PushComponentsContainer() { | |
| int top = this.mEndPagePushView.getTop() - getScrollY(); | |
| int i = this.mHeightMaxForEndPush; | |
| if (top < i) { | |
| this.mEndPagePushView.setData(((float) (i - top)) / ((float) this.END_PAGE_PUSH_HEIGHT), this.mIsScrollingToTop); | |
| } | |
| } | |
| public /* synthetic */ void lambda$new$3$PushComponentsContainer(ValueAnimator valueAnimator) { | |
| valueAnimator = ((Integer) valueAnimator.getAnimatedValue()).intValue(); | |
| scrollTo(0, valueAnimator); | |
| handleComponentsHeight(valueAnimator); | |
| } | |
| public /* synthetic */ void lambda$scrollToTop$7$PushComponentsContainer() { | |
| smoothScrollTo(0, new -$$Lambda$PushComponentsContainer$m8AxY7LDlmkSb3aEb8CBHrFPFG4(getPushComponentView(0))); | |
| } | |
| public void onDestroy() { | |
| runActionForAllPushComponentViews(-$$Lambda$wJPBtbchHcGh_ysPaA0r4MorbeE.INSTANCE); | |
| } | |
| public void onPause() { | |
| runActionForPushComponentView(computeFistVisibleItemPosition(), -$$Lambda$PushComponentsContainer$5ZrtWChLt4P3XjM2MI7bXcTY_tQ.INSTANCE); | |
| } | |
| public void onResume() { | |
| runActionForPushComponentView(computeFistVisibleItemPosition(), -$$Lambda$PushComponentsContainer$oBzw0oqSnhoSpyJaiTpa2-Ab0XQ.INSTANCE); | |
| } | |
| public void onTouchClick(int i, int i2) { | |
| boolean z = true; | |
| if (getContext() instanceof MainActivity) { | |
| ((MainActivity) getContext()).secureNav(true); | |
| } | |
| if (this.mListener != null) { | |
| int computeFistVisibleItemPosition = computeFistVisibleItemPosition(); | |
| int computeItemPosition = computeItemPosition((this.EXPANDED_ITEM_HEIGHT * computeFistVisibleItemPosition) + i2, true); | |
| PushModel pushModel = getPushModel(computeItemPosition); | |
| if (pushModel != null) { | |
| PushComponentView pushComponentView = getPushComponentView(computeItemPosition); | |
| if (pushComponentView != null) { | |
| pushModel.mClickOnText = pushComponentView.interceptTexts(i, i2); | |
| } | |
| i = computeItemPosition >= this.mPushComponentsCount ? 1 : 0; | |
| if (computeFistVisibleItemPosition == computeItemPosition) { | |
| z = false; | |
| } | |
| if (i == 0) { | |
| if (z) { | |
| smoothScrollTo(computeItemPosition, new -$$Lambda$PushComponentsContainer$gIy7sVz2oI_TP-dpnKeoOe64d9Q()); | |
| return; | |
| } | |
| } | |
| this.mListener.onPushClicked(pushModel); | |
| } | |
| } | |
| } | |
| public void onTouchRelease() { | |
| int computeFistVisibleItemPosition = computeFistVisibleItemPosition() + this.mIsScrollingToTop; | |
| smoothScrollTo(computeFistVisibleItemPosition, new -$$Lambda$PushComponentsContainer$TTxq_cw4f4JdFPzJVraN64D_nyc(getPushComponentView(computeFistVisibleItemPosition))); | |
| } | |
| public void onTouchScroll(int i) { | |
| if (this.mReleaseAnimator.isRunning()) { | |
| this.mReleaseAnimator.cancel(); | |
| } | |
| if (Math.abs(i) > 5) { | |
| this.mIsScrollingToTop = i > 0; | |
| } | |
| int scrollY = getScrollY(); | |
| i += scrollY; | |
| if (i < this.MINIMUM_SCROLL) { | |
| i = 0; | |
| } else { | |
| int i2 = this.MAXIMUM_SCROLL; | |
| if (i > i2) { | |
| i = i2; | |
| } | |
| } | |
| if (i != scrollY) { | |
| runActionForAllPushComponentViews(-$$Lambda$PushComponentsContainer$9UVSyOmvDh5nhXFB89kRQFNjgIg.INSTANCE); | |
| scrollTo(0, i); | |
| handleComponentsHeight(i); | |
| } | |
| } | |
| public void scrollToTop() { | |
| if (computeFistVisibleItemPosition() != 0) { | |
| this.mHandler.post(new -$$Lambda$PushComponentsContainer$U4A2KDLg5y1sFHHUyQWHYjKsLGc()); | |
| } | |
| } | |
| public void setComponents(List<PushPresenter> list, EndPagePush endPagePush) { | |
| initPushComponents(list); | |
| initEndPagePush(endPagePush); | |
| setOnTouchListener(this.mPushComponentsGesture); | |
| } | |
| public void setHeightAreaForEndPush(int i) { | |
| this.mHeightMaxForEndPush = i; | |
| } | |
| public void setImageTransformation(Transformation transformation) { | |
| this.mImageTransformation = transformation; | |
| } | |
| public void setListener(PushComponentsContainerListener pushComponentsContainerListener) { | |
| this.mListener = pushComponentsContainerListener; | |
| } | |
| public void setPushSizeHelper(PushHelper pushHelper) { | |
| this.mPushSizeHelper = pushHelper; | |
| this.COLLAPSED_ITEM_HEIGHT = pushHelper.COLLAPSED_ITEM_HEIGHT; | |
| this.EXPANDED_ITEM_HEIGHT = pushHelper.getExpandedItemHeight(); | |
| } | |
| public void setVideoTransformation(Transformation transformation) { | |
| this.mVideoTransformation = transformation; | |
| } | |
| public PushComponentsContainer(Context context, AttributeSet attributeSet) { | |
| this(context, attributeSet, 0); | |
| } | |
| public PushComponentsContainer(Context context, AttributeSet attributeSet, int i) { | |
| super(context, attributeSet, i); | |
| this.mHandler = new Handler(); | |
| this.mHeightMaxForEndPush = Constant.SCREEN_HEIGHT; | |
| setOrientation(1); | |
| this.mPushComponentsGesture = new PushComponentsGesture(getContext(), this); | |
| getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { | |
| public void onGlobalLayout() { | |
| PushComponentsContainer.this.getViewTreeObserver().removeOnGlobalLayoutListener(this); | |
| PushComponentsContainer.this.mPushComponentsGesture.setBounds(PushComponentsContainer.this.getWidth(), PushComponentsContainer.this.getHeight()); | |
| } | |
| }); | |
| context = new ValueAnimator(); | |
| this.mReleaseAnimator = context; | |
| context.setDuration(300); | |
| this.mReleaseAnimator.setInterpolator(new DecelerateInterpolator()); | |
| this.mReleaseAnimator.addUpdateListener(new -$$Lambda$PushComponentsContainer$QUM811KK3pGt73dlx2qcvAZZt6o()); | |
| this.mReleaseAnimator.addListener(new SimpleAnimatorListener() { | |
| public void onAnimationEnd(Animator animator) { | |
| if (PushComponentsContainer.this.mReleaseAnimatorListener != null) { | |
| PushComponentsContainer.this.mReleaseAnimatorListener.onReleaseFinished(); | |
| } | |
| } | |
| }); | |
| this.mPushComponentsCount = null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment