mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 22:37:59 +01:00
store only the current fragments video position, if it was started
This commit is contained in:
parent
0cb1b12933
commit
ff9135c215
3 changed files with 23 additions and 21 deletions
|
@ -59,6 +59,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
private var mWasFragmentInit = false
|
private var mWasFragmentInit = false
|
||||||
private var mIsExoPlayerInitialized = false
|
private var mIsExoPlayerInitialized = false
|
||||||
private var mIsPanorama = false
|
private var mIsPanorama = false
|
||||||
|
private var mWasVideoStarted = false
|
||||||
private var mCurrTime = 0
|
private var mCurrTime = 0
|
||||||
private var mDuration = 0
|
private var mDuration = 0
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
private var mStoredExtendedDetails = 0
|
private var mStoredExtendedDetails = 0
|
||||||
private var mStoredRememberLastVideoPosition = false
|
private var mStoredRememberLastVideoPosition = false
|
||||||
private var mStoredLastVideoPath = ""
|
private var mStoredLastVideoPath = ""
|
||||||
private var mStoredLastVideoProgress = 0
|
private var mStoredLastVideoPosition = 0
|
||||||
|
|
||||||
private lateinit var mTimeHolder: View
|
private lateinit var mTimeHolder: View
|
||||||
private lateinit var mBrightnessSideScroll: MediaSideScroll
|
private lateinit var mBrightnessSideScroll: MediaSideScroll
|
||||||
|
@ -171,7 +172,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
setupVideoDuration()
|
setupVideoDuration()
|
||||||
if (mStoredRememberLastVideoPosition) {
|
if (mStoredRememberLastVideoPosition) {
|
||||||
setLastVideoSavedProgress()
|
setLastVideoSavedPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
updateInstantSwitchWidths()
|
updateInstantSwitchWidths()
|
||||||
|
@ -208,7 +209,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
if (mStoredRememberLastVideoPosition) {
|
if (mStoredRememberLastVideoPosition && mIsFragmentVisible && mWasVideoStarted) {
|
||||||
saveVideoProgress()
|
saveVideoProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +251,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
mStoredBottomActions = bottomActions
|
mStoredBottomActions = bottomActions
|
||||||
mStoredRememberLastVideoPosition = rememberLastVideoPosition
|
mStoredRememberLastVideoPosition = rememberLastVideoPosition
|
||||||
mStoredLastVideoPath = lastVideoPath
|
mStoredLastVideoPath = lastVideoPath
|
||||||
mStoredLastVideoProgress = lastVideoProgress
|
mStoredLastVideoPosition = lastVideoPosition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,12 +270,12 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
private fun saveVideoProgress() {
|
private fun saveVideoProgress() {
|
||||||
if (!videoEnded()) {
|
if (!videoEnded()) {
|
||||||
mStoredLastVideoProgress = mExoPlayer!!.currentPosition.toInt() / 1000
|
mStoredLastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
|
||||||
mStoredLastVideoPath = medium.path
|
mStoredLastVideoPath = medium.path
|
||||||
}
|
}
|
||||||
|
|
||||||
context!!.config.apply {
|
context!!.config.apply {
|
||||||
lastVideoProgress = mStoredLastVideoProgress
|
lastVideoPosition = mStoredLastVideoPosition
|
||||||
lastVideoPath = mStoredLastVideoPath
|
lastVideoPath = mStoredLastVideoPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,9 +343,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
listener?.fragmentClicked()
|
listener?.fragmentClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setLastVideoSavedProgress() {
|
private fun setLastVideoSavedPosition() {
|
||||||
if (mStoredLastVideoPath == medium.path && mStoredLastVideoProgress > 0) {
|
if (mStoredLastVideoPath == medium.path && mStoredLastVideoPosition > 0) {
|
||||||
setProgress(mStoredLastVideoProgress)
|
setPosition(mStoredLastVideoPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,11 +463,11 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
val wasEnded = videoEnded()
|
val wasEnded = videoEnded()
|
||||||
if (wasEnded) {
|
if (wasEnded) {
|
||||||
setProgress(0)
|
setPosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStoredRememberLastVideoPosition) {
|
if (mStoredRememberLastVideoPosition) {
|
||||||
setLastVideoSavedProgress()
|
setLastVideoSavedPosition()
|
||||||
clearLastVideoSavedProgress()
|
clearLastVideoSavedProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,13 +477,14 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
}
|
}
|
||||||
|
|
||||||
schedulePlayPauseFadeOut()
|
schedulePlayPauseFadeOut()
|
||||||
|
mWasVideoStarted = true
|
||||||
mIsPlaying = true
|
mIsPlaying = true
|
||||||
mExoPlayer?.playWhenReady = true
|
mExoPlayer?.playWhenReady = true
|
||||||
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearLastVideoSavedProgress() {
|
private fun clearLastVideoSavedProgress() {
|
||||||
mStoredLastVideoProgress = 0
|
mStoredLastVideoPosition = 0
|
||||||
mStoredLastVideoPath = ""
|
mStoredLastVideoPath = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,7 +517,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
return currentPos != 0L && currentPos >= duration
|
return currentPos != 0L && currentPos >= duration
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setProgress(seconds: Int) {
|
private fun setPosition(seconds: Int) {
|
||||||
mExoPlayer?.seekTo(seconds * 1000L)
|
mExoPlayer?.seekTo(seconds * 1000L)
|
||||||
mSeekBar!!.progress = seconds
|
mSeekBar!!.progress = seconds
|
||||||
mCurrTimeView!!.text = seconds.getFormattedDuration()
|
mCurrTimeView!!.text = seconds.getFormattedDuration()
|
||||||
|
@ -530,14 +532,14 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTimeHolder()
|
setupTimeHolder()
|
||||||
setProgress(0)
|
setPosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun videoPrepared() {
|
private fun videoPrepared() {
|
||||||
if (mDuration == 0) {
|
if (mDuration == 0) {
|
||||||
mDuration = (mExoPlayer!!.duration / 1000).toInt()
|
mDuration = (mExoPlayer!!.duration / 1000).toInt()
|
||||||
setupTimeHolder()
|
setupTimeHolder()
|
||||||
setProgress(mCurrTime)
|
setPosition(mCurrTime)
|
||||||
|
|
||||||
if (mIsFragmentVisible && (context!!.config.autoplayVideos)) {
|
if (mIsFragmentVisible && (context!!.config.autoplayVideos)) {
|
||||||
playVideo()
|
playVideo()
|
||||||
|
@ -649,7 +651,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
val newProgress = if (forward) curr + twoPercents else curr - twoPercents
|
val newProgress = if (forward) curr + twoPercents else curr - twoPercents
|
||||||
val roundProgress = Math.round(newProgress / 1000f)
|
val roundProgress = Math.round(newProgress / 1000f)
|
||||||
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt(), roundProgress), 0)
|
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt(), roundProgress), 0)
|
||||||
setProgress(limitedProgress)
|
setPosition(limitedProgress)
|
||||||
if (!mIsPlaying) {
|
if (!mIsPlaying) {
|
||||||
togglePlayPause()
|
togglePlayPause()
|
||||||
}
|
}
|
||||||
|
@ -657,7 +659,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
if (mExoPlayer != null && fromUser) {
|
if (mExoPlayer != null && fromUser) {
|
||||||
setProgress(progress)
|
setPosition(progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -373,9 +373,9 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
get() = prefs.getString(LAST_VIDEO_PATH, "")
|
get() = prefs.getString(LAST_VIDEO_PATH, "")
|
||||||
set(lastVideoPath) = prefs.edit().putString(LAST_VIDEO_PATH, lastVideoPath).apply()
|
set(lastVideoPath) = prefs.edit().putString(LAST_VIDEO_PATH, lastVideoPath).apply()
|
||||||
|
|
||||||
var lastVideoProgress: Int
|
var lastVideoPosition: Int
|
||||||
get() = prefs.getInt(LAST_VIDEO_PROGRESS, 0)
|
get() = prefs.getInt(LAST_VIDEO_POSITION, 0)
|
||||||
set(lastVideoProgress) = prefs.edit().putInt(LAST_VIDEO_PROGRESS, lastVideoProgress).apply()
|
set(lastVideoPosition) = prefs.edit().putInt(LAST_VIDEO_POSITION, lastVideoPosition).apply()
|
||||||
|
|
||||||
var visibleBottomActions: Int
|
var visibleBottomActions: Int
|
||||||
get() = prefs.getInt(VISIBLE_BOTTOM_ACTIONS, DEFAULT_BOTTOM_ACTIONS)
|
get() = prefs.getInt(VISIBLE_BOTTOM_ACTIONS, DEFAULT_BOTTOM_ACTIONS)
|
||||||
|
|
|
@ -53,7 +53,7 @@ const val WAS_OTG_HANDLED = "was_otg_handled"
|
||||||
const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation"
|
const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation"
|
||||||
const val BOTTOM_ACTIONS = "bottom_actions"
|
const val BOTTOM_ACTIONS = "bottom_actions"
|
||||||
const val LAST_VIDEO_PATH = "last_video_path"
|
const val LAST_VIDEO_PATH = "last_video_path"
|
||||||
const val LAST_VIDEO_PROGRESS = "last_video_progress"
|
const val LAST_VIDEO_POSITION = "last_video_position"
|
||||||
const val VISIBLE_BOTTOM_ACTIONS = "visible_bottom_actions"
|
const val VISIBLE_BOTTOM_ACTIONS = "visible_bottom_actions"
|
||||||
const val WERE_FAVORITES_PINNED = "were_favorites_pinned"
|
const val WERE_FAVORITES_PINNED = "were_favorites_pinned"
|
||||||
const val WAS_RECYCLE_BIN_PINNED = "was_recycle_bin_pinned"
|
const val WAS_RECYCLE_BIN_PINNED = "was_recycle_bin_pinned"
|
||||||
|
|
Loading…
Reference in a new issue