mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
Switch from using one single stored position to one position per file, so
you can watch multiple files and all of them will have their position saved
This commit is contained in:
parent
49eea61814
commit
880f63ab3a
5 changed files with 40 additions and 44 deletions
|
@ -615,7 +615,9 @@ class SettingsActivity : SimpleActivity() {
|
||||||
put(FILE_LOADING_PRIORITY, config.fileLoadingPriority)
|
put(FILE_LOADING_PRIORITY, config.fileLoadingPriority)
|
||||||
put(AUTOPLAY_VIDEOS, config.autoplayVideos)
|
put(AUTOPLAY_VIDEOS, config.autoplayVideos)
|
||||||
put(REMEMBER_LAST_VIDEO_POSITION, config.rememberLastVideoPosition)
|
put(REMEMBER_LAST_VIDEO_POSITION, config.rememberLastVideoPosition)
|
||||||
put(LAST_VIDEO_PATH, config.lastVideoPath)
|
config.getAllLastVideoPositions().forEach {
|
||||||
|
put(it.key, it.value.toString())
|
||||||
|
}
|
||||||
put(LOOP_VIDEOS, config.loopVideos)
|
put(LOOP_VIDEOS, config.loopVideos)
|
||||||
put(OPEN_VIDEOS_ON_SEPARATE_SCREEN, config.openVideosOnSeparateScreen)
|
put(OPEN_VIDEOS_ON_SEPARATE_SCREEN, config.openVideosOnSeparateScreen)
|
||||||
put(ALLOW_VIDEO_GESTURES, config.allowVideoGestures)
|
put(ALLOW_VIDEO_GESTURES, config.allowVideoGestures)
|
||||||
|
@ -738,7 +740,6 @@ class SettingsActivity : SimpleActivity() {
|
||||||
FILE_LOADING_PRIORITY -> config.fileLoadingPriority = value.toInt()
|
FILE_LOADING_PRIORITY -> config.fileLoadingPriority = value.toInt()
|
||||||
AUTOPLAY_VIDEOS -> config.autoplayVideos = value.toBoolean()
|
AUTOPLAY_VIDEOS -> config.autoplayVideos = value.toBoolean()
|
||||||
REMEMBER_LAST_VIDEO_POSITION -> config.rememberLastVideoPosition = value.toBoolean()
|
REMEMBER_LAST_VIDEO_POSITION -> config.rememberLastVideoPosition = value.toBoolean()
|
||||||
LAST_VIDEO_PATH -> config.lastVideoPath = value.toString()
|
|
||||||
LOOP_VIDEOS -> config.loopVideos = value.toBoolean()
|
LOOP_VIDEOS -> config.loopVideos = value.toBoolean()
|
||||||
OPEN_VIDEOS_ON_SEPARATE_SCREEN -> config.openVideosOnSeparateScreen = value.toBoolean()
|
OPEN_VIDEOS_ON_SEPARATE_SCREEN -> config.openVideosOnSeparateScreen = value.toBoolean()
|
||||||
ALLOW_VIDEO_GESTURES -> config.allowVideoGestures = value.toBoolean()
|
ALLOW_VIDEO_GESTURES -> config.allowVideoGestures = value.toBoolean()
|
||||||
|
@ -799,6 +800,10 @@ class SettingsActivity : SimpleActivity() {
|
||||||
LAST_CONFLICT_RESOLUTION -> config.lastConflictResolution = value.toInt()
|
LAST_CONFLICT_RESOLUTION -> config.lastConflictResolution = value.toInt()
|
||||||
LAST_CONFLICT_APPLY_TO_ALL -> config.lastConflictApplyToAll = value.toBoolean()
|
LAST_CONFLICT_APPLY_TO_ALL -> config.lastConflictApplyToAll = value.toBoolean()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(key.startsWith(LAST_VIDEO_POSITION_PREFIX)) {
|
||||||
|
config.saveLastVideoPosition(key, value as Int)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toast(if (configValues.size > 0) R.string.settings_imported_successfully else R.string.no_entries_for_importing)
|
toast(if (configValues.size > 0) R.string.settings_imported_successfully else R.string.no_entries_for_importing)
|
||||||
|
|
|
@ -324,8 +324,9 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setLastVideoSavedPosition() {
|
private fun setLastVideoSavedPosition() {
|
||||||
if (config.lastVideoPath == mUri.toString() && config.lastVideoPosition > 0) {
|
val pos = config.getLastVideoPosition(mUri.toString())
|
||||||
setPosition(config.lastVideoPosition)
|
if(pos > 0) {
|
||||||
|
setPosition(pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,18 +354,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
|
|
||||||
private fun saveVideoProgress() {
|
private fun saveVideoProgress() {
|
||||||
if (!didVideoEnd()) {
|
if (!didVideoEnd()) {
|
||||||
config.apply {
|
config.saveLastVideoPosition(mUri.toString(), mExoPlayer!!.currentPosition.toInt() / 1000)
|
||||||
lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
|
|
||||||
lastVideoPath = mUri.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearLastVideoSavedProgress() {
|
private fun clearLastVideoSavedProgress() {
|
||||||
config.apply {
|
config.removeLastVideoPosition(mUri.toString())
|
||||||
lastVideoPosition = 0
|
|
||||||
lastVideoPath = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setVideoSize() {
|
private fun setVideoSize() {
|
||||||
|
|
|
@ -61,8 +61,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
private var mStoredBottomActions = true
|
private var mStoredBottomActions = true
|
||||||
private var mStoredExtendedDetails = 0
|
private var mStoredExtendedDetails = 0
|
||||||
private var mStoredRememberLastVideoPosition = false
|
private var mStoredRememberLastVideoPosition = false
|
||||||
private var mStoredLastVideoPath = ""
|
|
||||||
private var mStoredLastVideoPosition = 0
|
|
||||||
|
|
||||||
private lateinit var mTimeHolder: View
|
private lateinit var mTimeHolder: View
|
||||||
private lateinit var mBrightnessSideScroll: MediaSideScroll
|
private lateinit var mBrightnessSideScroll: MediaSideScroll
|
||||||
|
@ -183,7 +181,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
setupVideoDuration()
|
setupVideoDuration()
|
||||||
if (mStoredRememberLastVideoPosition) {
|
if (mStoredRememberLastVideoPosition) {
|
||||||
setLastVideoSavedPosition()
|
restoreLastVideoSavedPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
updateInstantSwitchWidths()
|
updateInstantSwitchWidths()
|
||||||
|
@ -263,8 +261,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
mStoredExtendedDetails = extendedDetails
|
mStoredExtendedDetails = extendedDetails
|
||||||
mStoredBottomActions = bottomActions
|
mStoredBottomActions = bottomActions
|
||||||
mStoredRememberLastVideoPosition = rememberLastVideoPosition
|
mStoredRememberLastVideoPosition = rememberLastVideoPosition
|
||||||
mStoredLastVideoPath = lastVideoPath
|
|
||||||
mStoredLastVideoPosition = lastVideoPosition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,19 +281,14 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
private fun saveVideoProgress() {
|
private fun saveVideoProgress() {
|
||||||
if (!videoEnded()) {
|
if (!videoEnded()) {
|
||||||
mStoredLastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
|
mConfig.saveLastVideoPosition(mMedium.path, mExoPlayer!!.currentPosition.toInt() / 1000)
|
||||||
mStoredLastVideoPath = mMedium.path
|
|
||||||
}
|
|
||||||
|
|
||||||
mConfig.apply {
|
|
||||||
lastVideoPosition = mStoredLastVideoPosition
|
|
||||||
lastVideoPath = mStoredLastVideoPath
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setLastVideoSavedPosition() {
|
private fun restoreLastVideoSavedPosition() {
|
||||||
if (mStoredLastVideoPath == mMedium.path && mStoredLastVideoPosition > 0) {
|
val pos = mConfig.getLastVideoPosition(mMedium.path)
|
||||||
setPosition(mStoredLastVideoPosition)
|
if(pos > 0) {
|
||||||
|
setPosition(pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,8 +554,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStoredRememberLastVideoPosition) {
|
if (mStoredRememberLastVideoPosition) {
|
||||||
setLastVideoSavedPosition()
|
restoreLastVideoSavedPosition()
|
||||||
clearLastVideoSavedProgress()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wasEnded || !mConfig.loopVideos) {
|
if (!wasEnded || !mConfig.loopVideos) {
|
||||||
|
@ -582,11 +572,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearLastVideoSavedProgress() {
|
|
||||||
mStoredLastVideoPosition = 0
|
|
||||||
mStoredLastVideoPath = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun pauseVideo() {
|
private fun pauseVideo() {
|
||||||
if (mExoPlayer == null) {
|
if (mExoPlayer == null) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -375,18 +375,30 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
get() = prefs.getBoolean(BOTTOM_ACTIONS, true)
|
get() = prefs.getBoolean(BOTTOM_ACTIONS, true)
|
||||||
set(bottomActions) = prefs.edit().putBoolean(BOTTOM_ACTIONS, bottomActions).apply()
|
set(bottomActions) = prefs.edit().putBoolean(BOTTOM_ACTIONS, bottomActions).apply()
|
||||||
|
|
||||||
|
fun removeLastVideoPosition(path: String) {
|
||||||
|
System.out.println("Remove position: $path")
|
||||||
|
prefs.edit().remove(LAST_VIDEO_POSITION_PREFIX + path.toLowerCase()).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveLastVideoPosition(path: String, value: Int) {
|
||||||
|
if (!path.isEmpty()) {
|
||||||
|
System.out.println("Saving position: $path at $value")
|
||||||
|
prefs.edit().putInt(LAST_VIDEO_POSITION_PREFIX + path.toLowerCase(), value).apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLastVideoPosition(path: String): Int {
|
||||||
|
val value = prefs.getInt(LAST_VIDEO_POSITION_PREFIX + path.toLowerCase(), 0)
|
||||||
|
System.out.println("Get position: $path at $value")
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllLastVideoPositions() = prefs.all.filterKeys { it.startsWith(LAST_VIDEO_POSITION_PREFIX) }
|
||||||
|
|
||||||
var rememberLastVideoPosition: Boolean
|
var rememberLastVideoPosition: Boolean
|
||||||
get() = prefs.getBoolean(REMEMBER_LAST_VIDEO_POSITION, false)
|
get() = prefs.getBoolean(REMEMBER_LAST_VIDEO_POSITION, false)
|
||||||
set(rememberLastVideoPosition) = prefs.edit().putBoolean(REMEMBER_LAST_VIDEO_POSITION, rememberLastVideoPosition).apply()
|
set(rememberLastVideoPosition) = prefs.edit().putBoolean(REMEMBER_LAST_VIDEO_POSITION, rememberLastVideoPosition).apply()
|
||||||
|
|
||||||
var lastVideoPath: String
|
|
||||||
get() = prefs.getString(LAST_VIDEO_PATH, "")
|
|
||||||
set(lastVideoPath) = prefs.edit().putString(LAST_VIDEO_PATH, lastVideoPath).apply()
|
|
||||||
|
|
||||||
var lastVideoPosition: Int
|
|
||||||
get() = prefs.getInt(LAST_VIDEO_POSITION, 0)
|
|
||||||
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)
|
||||||
set(visibleBottomActions) = prefs.edit().putInt(VISIBLE_BOTTOM_ACTIONS, visibleBottomActions).apply()
|
set(visibleBottomActions) = prefs.edit().putInt(VISIBLE_BOTTOM_ACTIONS, visibleBottomActions).apply()
|
||||||
|
|
|
@ -52,8 +52,7 @@ const val WAS_NEW_APP_SHOWN = "was_new_app_shown_clock"
|
||||||
const val LAST_FILEPICKER_PATH = "last_filepicker_path"
|
const val LAST_FILEPICKER_PATH = "last_filepicker_path"
|
||||||
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_POSITION_PREFIX = "last_video_position_"
|
||||||
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