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 6b6c47cf2..e77a47a48 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -15,6 +15,7 @@ import android.media.ExifInterface import android.net.Uri import android.os.Build import android.os.Bundle +import android.os.Handler import android.provider.MediaStore import android.support.v4.view.ViewPager import android.util.DisplayMetrics @@ -51,6 +52,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mRotationDegrees = 0f private var mLastHandledOrientation = 0 private var mPrevHashcode = 0 + private var mSlideshowHandler = Handler() + private var mSlideshowInterval = SLIDESHOW_DEFAULT_INTERVAL companion object { var screenWidth = 0 @@ -189,6 +192,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun onPause() { super.onPause() mOrientationEventListener.disable() + stopSlideshow() } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -256,13 +260,29 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun startSlideshow() { hideSystemUI() + mSlideshowInterval = config.slideshowInterval mIsSlideshowActive = true + scheduleSwipe() + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } private fun stopSlideshow() { if (mIsSlideshowActive) { showSystemUI() mIsSlideshowActive = false + mSlideshowHandler.removeCallbacksAndMessages(null) + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + } + + private fun scheduleSwipe() { + mSlideshowHandler.removeCallbacksAndMessages(null) + if (mIsSlideshowActive) { + mSlideshowHandler.postDelayed({ + if (mIsSlideshowActive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) { + view_pager.currentItem = ++view_pager.currentItem + } + }, mSlideshowInterval * 1000L) } } @@ -587,6 +607,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View updateActionbarTitle() mRotationDegrees = 0f supportInvalidateOptionsMenu() + scheduleSwipe() } override fun onPageScrollStateChanged(state: Int) { 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 94533b0e7..8bc0ca1ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.SLIDESHOW_DEFAULT_DURATION +import com.simplemobiletools.gallery.helpers.SLIDESHOW_DEFAULT_INTERVAL import kotlinx.android.synthetic.main.dialog_slideshow.view.* class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) { @@ -61,7 +61,7 @@ class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) { private fun dialogConfirmed() { var interval = view.interval_value.text.toString() if (interval.trim('0').isEmpty()) - interval = SLIDESHOW_DEFAULT_DURATION.toString() + interval = SLIDESHOW_DEFAULT_INTERVAL.toString() activity.config.apply { slideshowInterval = interval.toInt() 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 32632a0d5..a80d599d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -234,7 +234,7 @@ class Config(context: Context) : BaseConfig(context) { set(replaceShare) = prefs.edit().putBoolean(REPLACE_SHARE_WITH_ROTATE, replaceShare).apply() var slideshowInterval: Int - get() = prefs.getInt(SLIDESHOW_INTERVAL, SLIDESHOW_DEFAULT_DURATION) + get() = prefs.getInt(SLIDESHOW_INTERVAL, SLIDESHOW_DEFAULT_INTERVAL) set(slideshowInterval) = prefs.edit().putInt(SLIDESHOW_INTERVAL, slideshowInterval).apply() var slideshowIncludeVideos: Boolean 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 465904cea..f3350813f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -39,7 +39,7 @@ val SLIDESHOW_INTERVAL = "slideshow_interval" val SLIDESHOW_INCLUDE_VIDEOS = "slideshow_include_videos" val SLIDESHOW_RANDOM_ORDER = "slideshow_random_order" val SLIDESHOW_USE_FADE = "slideshow_use_fade" -val SLIDESHOW_DEFAULT_DURATION = 5 +val SLIDESHOW_DEFAULT_INTERVAL = 5 val NOMEDIA = ".nomedia"