From 8ea418dad6c634c96605b11b3bc4b569e744e3a8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 5 Sep 2017 20:04:09 +0200 Subject: [PATCH] add an option to loop slideshows --- .../gallery/activities/ViewPagerActivity.kt | 16 ++++++++++++-- .../gallery/dialogs/SlideshowDialog.kt | 7 +++++++ .../gallery/helpers/Config.kt | 4 ++++ .../gallery/helpers/Constants.kt | 1 + app/src/main/res/layout/dialog_slideshow.xml | 21 +++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 71cb64e7a..87f0129cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -301,8 +301,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View view_pager.endFakeDrag() if (view_pager.currentItem == oldPosition) { - stopSlideshow() - toast(R.string.slideshow_ended) + slideshowEnded(forward) } } @@ -330,6 +329,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View animator.start() } + private fun slideshowEnded(forward: Boolean) { + if (config.loopSlideshow) { + if (forward) { + view_pager.setCurrentItem(0, false) + } else { + view_pager.setCurrentItem(view_pager.adapter!!.count - 1, false) + } + } else { + stopSlideshow() + toast(R.string.slideshow_ended) + } + } + private fun stopSlideshow() { if (mIsSlideshowActive) { showSystemUI() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt index d4753c047..cffb769b6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt @@ -61,6 +61,11 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) { interval_value.clearFocus() move_backwards.toggle() } + + loop_slideshow_holder.setOnClickListener { + interval_value.clearFocus() + loop_slideshow.toggle() + } } setupValues() @@ -93,6 +98,7 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) { random_order.isChecked = config.slideshowRandomOrder use_fade.isChecked = config.slideshowUseFade move_backwards.isChecked = config.slideshowMoveBackwards + loop_slideshow.isChecked = config.loopSlideshow } } @@ -109,6 +115,7 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) { slideshowRandomOrder = view.random_order.isChecked slideshowUseFade = view.use_fade.isChecked slideshowMoveBackwards = view.move_backwards.isChecked + loopSlideshow = view.loop_slideshow.isChecked } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 882a9ddef..9fa94ce47 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -272,4 +272,8 @@ class Config(context: Context) : BaseConfig(context) { var slideshowMoveBackwards: Boolean get() = prefs.getBoolean(SLIDESHOW_MOVE_BACKWARDS, false) set(slideshowMoveBackwards) = prefs.edit().putBoolean(SLIDESHOW_MOVE_BACKWARDS, slideshowMoveBackwards).apply() + + var loopSlideshow: Boolean + get() = prefs.getBoolean(SLIDESHOW_LOOP, false) + set(loopSlideshow) = prefs.edit().putBoolean(SLIDESHOW_LOOP, loopSlideshow).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 3e3cb7285..7b743837f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -45,6 +45,7 @@ val SLIDESHOW_INCLUDE_GIFS = "slideshow_include_gifs" val SLIDESHOW_RANDOM_ORDER = "slideshow_random_order" val SLIDESHOW_USE_FADE = "slideshow_use_fade" val SLIDESHOW_MOVE_BACKWARDS = "slideshow_move_backwards" +val SLIDESHOW_LOOP = "loop_slideshow" val SLIDESHOW_DEFAULT_INTERVAL = 5 val SLIDESHOW_SCROLL_DURATION = 500L diff --git a/app/src/main/res/layout/dialog_slideshow.xml b/app/src/main/res/layout/dialog_slideshow.xml index 570c48c03..dd17378d4 100644 --- a/app/src/main/res/layout/dialog_slideshow.xml +++ b/app/src/main/res/layout/dialog_slideshow.xml @@ -161,5 +161,26 @@ android:text="@string/move_backwards"/> + + + + + +