adding some basic slideshow functionality

This commit is contained in:
tibbi 2017-08-05 12:27:48 +02:00
parent 1d04016c9b
commit 86a5107cc6
4 changed files with 25 additions and 4 deletions

View File

@ -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) {

View File

@ -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()

View File

@ -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

View File

@ -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"