fixed collapsing toolbar left/right scrolling behavior

This commit is contained in:
nuclearfog 2023-04-13 01:23:45 +02:00
parent 6398b829c1
commit c6c8fa20ea
No known key found for this signature in database
GPG Key ID: 03488A185C476379
3 changed files with 28 additions and 13 deletions

View File

@ -650,7 +650,7 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
public void onSuccess() {
// setup toolbar background
if (settings.toolbarOverlapEnabled()) {
AppStyles.setToolbarBackground(ProfileActivity.this, bannerImage, toolbarBackground);
AppStyles.setToolbarBackground(this, bannerImage, toolbarBackground);
}
}

View File

@ -23,13 +23,13 @@ public class LockableConstraintLayout extends ConstraintLayout {
* @inheritDoc
*/
public LockableConstraintLayout(Context context) {
super(context);
this(context, null);
}
/**
* @inheritDoc
*/
public LockableConstraintLayout(Context context, AttributeSet attr) {
public LockableConstraintLayout(Context context, @Nullable AttributeSet attr) {
super(context, attr);
}
@ -42,7 +42,9 @@ public class LockableConstraintLayout extends ConstraintLayout {
break;
case MotionEvent.ACTION_MOVE:
if (ev.getY() < yPos && callback != null) {// scroll down
// detect scroll down, then aquire scroll lock
float deltaY = ev.getY() - yPos;
if (deltaY < 0.0f && callback != null) {
lock = callback.aquireLock();
}
yPos = ev.getY();

View File

@ -14,33 +14,36 @@ import androidx.annotation.Nullable;
*/
public class LockableLinearLayout extends LinearLayout {
/**
* minimum X-Y ratio of a swipe to determine if it's a left right swipe
*/
private static final float LEFT_RIGHT_SWIPE_RATIO = 2.0f;
@Nullable
private LockCallback callback;
private boolean lock = false;
private float xPos = 0.0f;
private float yPos = 0.0f;
/**
* @inheritDoc
*/
public LockableLinearLayout(Context context) {
super(context);
setOrientation(VERTICAL);
this(context, null);
}
/**
* @inheritDoc
*/
public LockableLinearLayout(Context context, AttributeSet attr) {
super(context, attr);
setOrientation(VERTICAL);
public LockableLinearLayout(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* @inheritDoc
*/
public LockableLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOrientation(VERTICAL);
this(context, attrs, defStyleAttr, 0);
}
/**
@ -60,9 +63,19 @@ public class LockableLinearLayout extends LinearLayout {
break;
case MotionEvent.ACTION_MOVE:
if (ev.getY() < yPos && callback != null) {
lock = callback.aquireLock();
float deltaX = ev.getX() - xPos;
float deltaY = ev.getY() - yPos;
// detect up/down swipe
if (deltaY < 0.0f && Math.abs(deltaX * LEFT_RIGHT_SWIPE_RATIO) < Math.abs(deltaY)) {
if (callback != null) {
lock = callback.aquireLock();
}
}
// detect left/right swipe
else {
lock = false;
}
xPos = ev.getX();
yPos = ev.getY();
break;
}