making the incrementing helper specific to increments of 1 and incrementing first before returning the minimum value

This commit is contained in:
Adam Brown 2022-01-05 10:53:50 +00:00
parent fa30691583
commit 486671f385
2 changed files with 10 additions and 3 deletions

View File

@ -16,4 +16,11 @@
package im.vector.app.core.extensions package im.vector.app.core.extensions
fun Int.incrementAndWrap(max: Int, min: Int = 0, amount: Int = 1) = if (this == max) min else this + amount fun Int.incrementByOneAndWrap(max: Int, min: Int = 0): Int {
val incrementedValue = this + 1
return if (incrementedValue > max) {
min
} else {
incrementedValue
}
}

View File

@ -28,7 +28,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import im.vector.app.BuildConfig import im.vector.app.BuildConfig
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.incrementAndWrap import im.vector.app.core.extensions.incrementByOneAndWrap
import im.vector.app.core.extensions.setCurrentItem import im.vector.app.core.extensions.setCurrentItem
import im.vector.app.core.flow.tickerFlow import im.vector.app.core.flow.tickerFlow
import im.vector.app.databinding.FragmentFtueSplashCarouselBinding import im.vector.app.databinding.FragmentFtueSplashCarouselBinding
@ -83,7 +83,7 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
views.splashCarousel.apply { views.splashCarousel.apply {
val itemCount = carouselAdapter.itemCount val itemCount = carouselAdapter.itemCount
tickerFlow(lifecycleScope, delayMillis = CAROUSEL_ROTATION_DELAY_MS) tickerFlow(lifecycleScope, delayMillis = CAROUSEL_ROTATION_DELAY_MS)
.onEach { setCurrentItem(currentItem.incrementAndWrap(max = itemCount - 1), duration = CAROUSEL_TRANSITION_TIME_MS) } .onEach { setCurrentItem(currentItem.incrementByOneAndWrap(max = itemCount - 1), duration = CAROUSEL_TRANSITION_TIME_MS) }
.launchIn(lifecycleScope) .launchIn(lifecycleScope)
} }
} }