diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 0fe36ff5c..361cbc326 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -396,6 +396,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (getMediaForSlideshow()) { view_pager.onGlobalLayout { if (!isDestroyed) { + if (config.slideshowAnimation == SLIDESHOW_ANIMATION_FADE) { + view_pager.setPageTransformer(false, FadePageTransformer()) + } + hideSystemUI(true) mSlideshowInterval = config.slideshowInterval mSlideshowMoveBackwards = config.slideshowMoveBackwards @@ -436,7 +440,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } }) - animator.interpolator = DecelerateInterpolator() + if (config.slideshowAnimation == SLIDESHOW_ANIMATION_SLIDE) { + animator.interpolator = DecelerateInterpolator() + animator.duration = SLIDESHOW_SLIDE_DURATION + } else { + animator.duration = SLIDESHOW_FADE_DURATION + } + animator.addUpdateListener(object : ValueAnimator.AnimatorUpdateListener { var oldDragPosition = 0 override fun onAnimationUpdate(animation: ValueAnimator) { @@ -453,7 +463,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } }) - animator.duration = SLIDESHOW_SCROLL_DURATION view_pager.beginFakeDrag() animator.start() } @@ -473,6 +482,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun stopSlideshow() { if (mIsSlideshowActive) { + view_pager.setPageTransformer(false, DefaultPageTransformer()) mIsSlideshowActive = false showSystemUI(true) mSlideshowHandler.removeCallbacksAndMessages(null) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 267ec5ab2..8193e9de8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -88,7 +88,8 @@ const val SLIDESHOW_MOVE_BACKWARDS = "slideshow_move_backwards" const val SLIDESHOW_ANIMATION = "slideshow_animation" const val SLIDESHOW_LOOP = "loop_slideshow" const val SLIDESHOW_DEFAULT_INTERVAL = 5 -const val SLIDESHOW_SCROLL_DURATION = 500L +const val SLIDESHOW_SLIDE_DURATION = 500L +const val SLIDESHOW_FADE_DURATION = 1500L const val SLIDESHOW_START_ON_ENTER = "slideshow_start_on_enter" // slideshow animations diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/DefaultPageTransformer.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/DefaultPageTransformer.kt new file mode 100644 index 000000000..95981ba4a --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/DefaultPageTransformer.kt @@ -0,0 +1,8 @@ +package com.simplemobiletools.gallery.pro.helpers + +import android.view.View +import androidx.viewpager.widget.ViewPager + +class DefaultPageTransformer : ViewPager.PageTransformer { + override fun transformPage(view: View, position: Float) {} +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/FadePageTransformer.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/FadePageTransformer.kt new file mode 100644 index 000000000..3ed113b40 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/FadePageTransformer.kt @@ -0,0 +1,18 @@ +package com.simplemobiletools.gallery.pro.helpers + +import android.view.View +import androidx.viewpager.widget.ViewPager + +class FadePageTransformer : ViewPager.PageTransformer { + override fun transformPage(view: View, position: Float) { + view.translationX = view.width * -position + + view.alpha = if (position <= -1f || position >= 1f) { + 0f + } else if (position == 0f) { + 1f + } else { + 1f - Math.abs(position) + } + } +}