Version 5.1.9-beta2. Optimize AppBarStateChangeListener.

This commit is contained in:
Docile-Alligator 2022-03-14 14:15:44 +08:00
parent 3cae2b0dba
commit cfd295aea8
2 changed files with 11 additions and 5 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21
targetSdkVersion 30
versionCode 94
versionName "5.1.9-beta1"
versionCode 95
versionName "5.1.9-beta2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {

View File

@ -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);
}