Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun autoRotate(pager: ViewPager2, data: BannerRow, childCount: Int) {
- timer = Timer()
- timer.scheduleAtFixedRate(object : TimerTask() {
- override fun run() {
- var next = pager.currentItem
- if (!data.shuffle) {
- if (next >= childCount - 1) {
- next = 0
- } else {
- next += 1
- }
- } else {
- while (true) {
- val random = Random().nextInt(childCount - 1)
- if (random != pager.currentItem) {
- next = random
- break
- }
- }
- }
- pager.currentItem = next
- }
- }, 3000, data.autoScrollRateInSeconds.toLong() * 1000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement