diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java deleted file mode 100644 index 8ecdc60..0000000 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wbrawner.simplemarkdown.view; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.util.AttributeSet; -import android.view.MotionEvent; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.viewpager.widget.ViewPager; - -public class DisableableViewPager extends ViewPager { - private boolean isSwipeLocked = false; - - public DisableableViewPager(@NonNull Context context) { - super(context); - } - - public DisableableViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - return !isSwipeLocked && super.onInterceptTouchEvent(ev); - } - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouchEvent(MotionEvent ev) { - return !isSwipeLocked && super.onTouchEvent(ev); - } - - public void setSwipeLocked(boolean locked) { - this.isSwipeLocked = locked; - } -} diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt new file mode 100644 index 0000000..229fd2a --- /dev/null +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt @@ -0,0 +1,28 @@ +package com.wbrawner.simplemarkdown.view + +import android.annotation.SuppressLint +import android.content.Context +import android.util.AttributeSet +import android.view.MotionEvent +import androidx.viewpager.widget.ViewPager + +class DisableableViewPager : ViewPager { + private var isSwipeLocked = false + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + return !isSwipeLocked && super.onInterceptTouchEvent(ev) + } + + @SuppressLint("ClickableViewAccessibility") + override fun onTouchEvent(ev: MotionEvent): Boolean { + return !isSwipeLocked && super.onTouchEvent(ev) + } + + fun setSwipeLocked(locked: Boolean) { + this.isSwipeLocked = locked + } +}