diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt
index c50d01c1a..45badc869 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt
@@ -45,6 +45,7 @@ class SettingsActivity : SimpleActivity() {
setupShowHiddenItems()
setupDoExtraCheck()
setupAutoplayVideos()
+ setupRememberLastVideo()
setupLoopVideos()
setupAnimateGifs()
setupMaxBrightness()
@@ -175,6 +176,14 @@ class SettingsActivity : SimpleActivity() {
}
}
+ private fun setupRememberLastVideo() {
+ settings_remember_last_video.isChecked = config.rememberLastVideo
+ settings_remember_last_video_holder.setOnClickListener {
+ settings_remember_last_video.toggle()
+ config.rememberLastVideo = settings_remember_last_video.isChecked
+ }
+ }
+
private fun setupLoopVideos() {
settings_loop_videos.isChecked = config.loopVideos
settings_loop_videos_holder.setOnClickListener {
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt
index 438565493..c60f20c31 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt
@@ -66,6 +66,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private var mStoredHideExtendedDetails = false
private var mStoredBottomActions = true
private var mStoredExtendedDetails = 0
+ private var mStoredRememberLastVideo = false
+ private var mStoredLastVideoPath = ""
+ private var mStoredLastVideoProgress = 0
private lateinit var mTimeHolder: View
private lateinit var mBrightnessSideScroll: MediaSideScroll
@@ -167,6 +170,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
}
setupVideoDuration()
+ if (mStoredRememberLastVideo) {
+ setSavedProgress()
+ }
+
updateInstantSwitchWidths()
return mView
@@ -201,6 +208,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
override fun onPause() {
super.onPause()
pauseVideo()
+ if (mStoredRememberLastVideo) {
+ saveVideoProgress()
+ }
+
storeStateVariables()
}
@@ -237,6 +248,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
mStoredHideExtendedDetails = hideExtendedDetails
mStoredExtendedDetails = extendedDetails
mStoredBottomActions = bottomActions
+ mStoredRememberLastVideo = rememberLastVideo
+ mStoredLastVideoPath = lastVideoPath
+ mStoredLastVideoProgress = lastVideoProgress
}
}
@@ -253,6 +267,18 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
checkExtendedDetails()
}
+ private fun saveVideoProgress() {
+ if (!videoEnded()) {
+ mStoredLastVideoProgress = mExoPlayer!!.currentPosition.toInt() / 1000
+ mStoredLastVideoPath = medium.path
+ }
+
+ context!!.config.apply {
+ lastVideoProgress = mStoredLastVideoProgress
+ lastVideoPath = mStoredLastVideoPath
+ }
+ }
+
private fun initExoPlayer() {
val isContentUri = medium.path.startsWith("content://")
val uri = if (isContentUri) Uri.parse(medium.path) else Uri.fromFile(File(medium.path))
@@ -316,6 +342,12 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
listener?.fragmentClicked()
}
+ private fun setSavedProgress() {
+ if (mStoredLastVideoPath == medium.path && mStoredLastVideoProgress > 0) {
+ setProgress(mStoredLastVideoProgress)
+ }
+ }
+
private fun initTimeHolder() {
val res = resources
val left = 0
@@ -434,6 +466,11 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
setProgress(0)
}
+ if (mStoredRememberLastVideo) {
+ setSavedProgress()
+ clearSavedProgress()
+ }
+
if (!wasEnded || context?.config?.loopVideos == false) {
mView.video_play_outline.setImageResource(R.drawable.ic_pause)
mView.video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA
@@ -445,6 +482,11 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
+ private fun clearSavedProgress() {
+ mStoredLastVideoProgress = 0
+ mStoredLastVideoPath = "/"
+ }
+
private fun pauseVideo() {
if (mExoPlayer == null) {
return
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 40838d5cd..fbb3a0831 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt
@@ -148,6 +148,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(AUTOPLAY_VIDEOS, false)
set(autoplay) = prefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).apply()
+ var rememberLastVideo: Boolean
+ get() = prefs.getBoolean(REMEMBER_LAST_VIDEO, false)
+ set(rememberVideo) = prefs.edit().putBoolean(REMEMBER_LAST_VIDEO, rememberVideo).apply()
+
var animateGifs: Boolean
get() = prefs.getBoolean(ANIMATE_GIFS, false)
set(animateGifs) = prefs.edit().putBoolean(ANIMATE_GIFS, animateGifs).apply()
@@ -365,6 +369,14 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(BOTTOM_ACTIONS, true)
set(bottomActions) = prefs.edit().putBoolean(BOTTOM_ACTIONS, bottomActions).apply()
+ var lastVideoPath: String
+ get() = prefs.getString(LAST_VIDEO_PATH, "/")
+ set(lastVideoPath) = prefs.edit().putString(LAST_VIDEO_PATH, lastVideoPath).apply()
+
+ var lastVideoProgress: Int
+ get() = prefs.getInt(LAST_VIDEO_PROGRESS, 0)
+ set(lastVideoProgress) = prefs.edit().putInt(LAST_VIDEO_PROGRESS, lastVideoProgress).apply()
+
var visibleBottomActions: Int
get() = prefs.getInt(VISIBLE_BOTTOM_ACTIONS, DEFAULT_BOTTOM_ACTIONS)
set(visibleBottomActions) = prefs.edit().putInt(VISIBLE_BOTTOM_ACTIONS, visibleBottomActions).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 fc438b9f6..529eae1c6 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt
@@ -10,6 +10,7 @@ const val SHOW_HIDDEN_MEDIA = "show_hidden_media"
const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
const val IS_THIRD_PARTY_INTENT = "is_third_party_intent"
const val AUTOPLAY_VIDEOS = "autoplay_videos"
+const val REMEMBER_LAST_VIDEO = "remember_last_video"
const val LOOP_VIDEOS = "loop_videos"
const val ANIMATE_GIFS = "animate_gifs"
const val MAX_BRIGHTNESS = "max_brightness"
@@ -51,6 +52,8 @@ const val LAST_FILEPICKER_PATH = "last_filepicker_path"
const val WAS_OTG_HANDLED = "was_otg_handled"
const val TEMP_SKIP_DELETE_CONFIRMATION = "temp_skip_delete_confirmation"
const val BOTTOM_ACTIONS = "bottom_actions"
+const val LAST_VIDEO_PATH = "last_video_path"
+const val LAST_VIDEO_PROGRESS = "last_video_progress"
const val VISIBLE_BOTTOM_ACTIONS = "visible_bottom_actions"
const val WERE_FAVORITES_PINNED = "were_favorites_pinned"
const val WAS_RECYCLE_BIN_PINNED = "was_recycle_bin_pinned"
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 480a71a42..7699cd830 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -278,6 +278,30 @@
+
+
+
+
+
+
Play videos automatically
+ Remember last video playback position
Toggle filename visibility
Loop videos
Animate GIFs at thumbnails