From cfd295aea8a5a1f6ba460fa25f972c1e4cc523e5 Mon Sep 17 00:00:00 2001 From: Docile-Alligator Date: Mon, 14 Mar 2022 14:15:44 +0800 Subject: Version 5.1.9-beta2. Optimize AppBarStateChangeListener. --- .../infinityforreddit/AppBarStateChangeListener.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java index dffd958c..43e11941 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java @@ -4,15 +4,21 @@ import com.google.android.material.appbar.AppBarLayout; public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener { private AppBarStateChangeListener.State mCurrentState = AppBarStateChangeListener.State.IDLE; + private int lastOffset = -1; @Override - public final void onOffsetChanged(AppBarLayout appBarLayout, int i) { - if (i == 0) { + public final void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + if (lastOffset == verticalOffset) { + return; + } + lastOffset = verticalOffset; + + if (verticalOffset == 0) { if (mCurrentState != AppBarStateChangeListener.State.EXPANDED) { onStateChanged(appBarLayout, AppBarStateChangeListener.State.EXPANDED); } mCurrentState = AppBarStateChangeListener.State.EXPANDED; - } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) { + } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) { if (mCurrentState != AppBarStateChangeListener.State.COLLAPSED) { onStateChanged(appBarLayout, AppBarStateChangeListener.State.COLLAPSED); } -- cgit v1.2.3