aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/FrostViewPager.kt
blob: 18b7ae49130f6d0eed68d0b14410d5a9d720c08a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.pitchedapps.frost.views

import android.annotation.SuppressLint
import android.content.Context
import androidx.viewpager.widget.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
import com.pitchedapps.frost.utils.Prefs

/**
 * Created by Allan Wang on 2017-07-07.
 *
 * Basic override to allow us to control swiping
 */
class FrostViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
    var enableSwipe = true

    override fun onInterceptTouchEvent(ev: MotionEvent?) =
            try {
                Prefs.viewpagerSwipe && enableSwipe && super.onInterceptTouchEvent(ev)
            } catch (e: IllegalArgumentException) {
                false
            }

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(ev: MotionEvent?): Boolean =
            try {
                Prefs.viewpagerSwipe && enableSwipe && super.onTouchEvent(ev)
            } catch (e: IllegalArgumentException) {
                false
            }
}