properly handle launching videos in slideshows
This commit is contained in:
parent
74e6c69473
commit
3f1cfab633
|
@ -162,4 +162,6 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
|||
showSystemUI()
|
||||
}
|
||||
}
|
||||
|
||||
override fun videoEnded() = false
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
|||
import com.simplemobiletools.gallery.dialogs.SlideshowDialog
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||
import com.simplemobiletools.gallery.fragments.VideoFragment
|
||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
|
@ -56,6 +57,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mSlideshowHandler = Handler()
|
||||
private var mSlideshowInterval = SLIDESHOW_DEFAULT_INTERVAL
|
||||
private var mSlideshowMoveBackwards = false
|
||||
private var mSlideshowMedia = mutableListOf<Medium>()
|
||||
private var mAreSlideShowMediaVisible = false
|
||||
|
||||
companion object {
|
||||
var screenWidth = 0
|
||||
|
@ -262,12 +265,20 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun startSlideshow() {
|
||||
if (getMediaForSlideshow()) {
|
||||
view_pager.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
view_pager.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed)
|
||||
return
|
||||
|
||||
hideSystemUI()
|
||||
mSlideshowInterval = config.slideshowInterval
|
||||
mSlideshowMoveBackwards = config.slideshowMoveBackwards
|
||||
mIsSlideshowActive = true
|
||||
scheduleSwipe()
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
scheduleSwipe()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,8 +294,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private fun scheduleSwipe() {
|
||||
mSlideshowHandler.removeCallbacksAndMessages(null)
|
||||
if (mIsSlideshowActive) {
|
||||
if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGif()) {
|
||||
mSlideshowHandler.postDelayed({
|
||||
if (mIsSlideshowActive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) {
|
||||
swipeToNextMedium()
|
||||
}
|
||||
}, mSlideshowInterval * 1000L)
|
||||
} else {
|
||||
(getCurrentFragment() as? VideoFragment)!!.playVideo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun swipeToNextMedium() {
|
||||
val before = view_pager.currentItem
|
||||
view_pager.currentItem = if (mSlideshowMoveBackwards) --view_pager.currentItem else ++view_pager.currentItem
|
||||
if (before == view_pager.currentItem) {
|
||||
|
@ -292,29 +314,27 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
toast(R.string.slideshow_ended)
|
||||
}
|
||||
}
|
||||
}, mSlideshowInterval * 1000L)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMediaForSlideshow(): Boolean {
|
||||
var slideshowMedia = mMedia.toMutableList()
|
||||
mSlideshowMedia = mMedia.toMutableList()
|
||||
if (!config.slideshowIncludeVideos) {
|
||||
slideshowMedia = slideshowMedia.filter { it.isImage() || it.isGif() } as MutableList
|
||||
mSlideshowMedia = mSlideshowMedia.filter { it.isImage() || it.isGif() } as MutableList
|
||||
}
|
||||
|
||||
if (config.slideshowRandomOrder) {
|
||||
Collections.shuffle(slideshowMedia)
|
||||
Collections.shuffle(mSlideshowMedia)
|
||||
mPos = 0
|
||||
} else {
|
||||
mPath = getCurrentPath()
|
||||
mPos = getPositionInList(slideshowMedia)
|
||||
mPos = getPositionInList(mSlideshowMedia)
|
||||
}
|
||||
|
||||
return if (slideshowMedia.isEmpty()) {
|
||||
return if (mSlideshowMedia.isEmpty()) {
|
||||
toast(R.string.no_media_for_slideshow)
|
||||
false
|
||||
} else {
|
||||
updatePagerItems(slideshowMedia)
|
||||
updatePagerItems(mSlideshowMedia)
|
||||
mAreSlideShowMediaVisible = true
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -336,7 +356,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
getCurrentMedium()!!.apply {
|
||||
name = newFileName
|
||||
path = it.absolutePath
|
||||
mMedia[mPos] = this
|
||||
getCurrentMedia()[mPos] = this
|
||||
}
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
@ -498,7 +518,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(this) {
|
||||
deleteFileBg(File(mMedia[mPos].path)) {
|
||||
deleteFileBg(File(getCurrentMedia()[mPos].path)) {
|
||||
reloadViewPager()
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +535,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun renameFile() {
|
||||
RenameItemDialog(this, getCurrentPath()) {
|
||||
mMedia[mPos].path = it
|
||||
getCurrentMedia()[mPos].path = it
|
||||
updateActionbarTitle()
|
||||
}
|
||||
}
|
||||
|
@ -600,6 +620,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
checkSystemUI()
|
||||
}
|
||||
|
||||
override fun videoEnded(): Boolean {
|
||||
if (mIsSlideshowActive)
|
||||
swipeToNextMedium()
|
||||
return mIsSlideshowActive
|
||||
}
|
||||
|
||||
private fun checkSystemUI() {
|
||||
if (mIsFullScreen) {
|
||||
hideSystemUI()
|
||||
|
@ -611,19 +637,21 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun updateActionbarTitle() {
|
||||
runOnUiThread {
|
||||
if (mPos < mMedia.size) {
|
||||
title = mMedia[mPos].path.getFilenameFromPath()
|
||||
if (mPos < getCurrentMedia().size) {
|
||||
title = getCurrentMedia()[mPos].path.getFilenameFromPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentMedium(): Medium? {
|
||||
return if (mMedia.isEmpty() || mPos == -1)
|
||||
return if (getCurrentMedia().isEmpty() || mPos == -1)
|
||||
null
|
||||
else
|
||||
mMedia[Math.min(mPos, mMedia.size - 1)]
|
||||
getCurrentMedia()[Math.min(mPos, getCurrentMedia().size - 1)]
|
||||
}
|
||||
|
||||
private fun getCurrentMedia() = if (mAreSlideShowMediaVisible) mSlideshowMedia else mMedia
|
||||
|
||||
private fun getCurrentPath() = getCurrentMedium()!!.path
|
||||
|
||||
private fun getCurrentFile() = File(getCurrentPath())
|
||||
|
|
|
@ -39,6 +39,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
|||
private var mIsDragged = false
|
||||
private var mIsFullscreen = false
|
||||
private var mIsFragmentVisible = false
|
||||
private var mPlayOnPrepare = false
|
||||
private var mCurrTime = 0
|
||||
private var mDuration = 0
|
||||
|
||||
|
@ -194,9 +195,13 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
|||
}
|
||||
}
|
||||
|
||||
private fun playVideo() {
|
||||
fun playVideo() {
|
||||
if (mMediaPlayer != null) {
|
||||
mIsPlaying = true
|
||||
mMediaPlayer?.start()
|
||||
} else {
|
||||
mPlayOnPrepare = true
|
||||
}
|
||||
mView.video_play_outline.setImageDrawable(null)
|
||||
activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
@ -271,12 +276,12 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
|||
setupTimeHolder()
|
||||
setProgress(mCurrTime)
|
||||
|
||||
if (mIsFragmentVisible && context.config.autoplayVideos)
|
||||
if (mIsFragmentVisible && (context.config.autoplayVideos || mPlayOnPrepare))
|
||||
playVideo()
|
||||
}
|
||||
|
||||
private fun videoCompleted() {
|
||||
if (context.config.loopVideos) {
|
||||
if (listener?.videoEnded() == false && context.config.loopVideos) {
|
||||
playVideo()
|
||||
} else {
|
||||
mSeekBar!!.progress = mSeekBar!!.max
|
||||
|
|
|
@ -9,5 +9,7 @@ abstract class ViewPagerFragment : Fragment() {
|
|||
|
||||
interface FragmentListener {
|
||||
fun fragmentClicked()
|
||||
|
||||
fun videoEnded(): Boolean
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue