From c788aef4aac1f66fcad94d38363619e78151a6f8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 28 Feb 2018 12:11:56 +0100 Subject: [PATCH] add a helper extension for listening to viewpager page changes --- build.gradle | 2 +- .../commons/extensions/ViewPager.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 commons/src/main/kotlin/com/simplemobiletools/commons/extensions/ViewPager.kt diff --git a/build.gradle b/build.gradle index 5f84850dd..0e7774729 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { propMinSdkVersion = 16 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '3.13.19' + propVersionName = '3.13.20' kotlin_version = '1.2.21' support_libs = '27.0.2' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/ViewPager.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/ViewPager.kt new file mode 100644 index 000000000..3239a1dd4 --- /dev/null +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/ViewPager.kt @@ -0,0 +1,16 @@ +package com.simplemobiletools.commons.extensions + +import android.support.v4.view.ViewPager + +fun ViewPager.onPageChangeListener(pageChangedAction: (newPosition: Int) -> Unit) = + addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + } + + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + } + + override fun onPageSelected(position: Int) { + pageChangedAction(position) + } + })