Merge branch 'remember_multiple_video_positions' of https://github.com/centic9/Simple-Gallery

This commit is contained in:
tibbi 2019-04-01 12:16:00 +02:00
commit bd498da261
5 changed files with 36 additions and 44 deletions

View File

@ -615,7 +615,9 @@ class SettingsActivity : SimpleActivity() {
put(FILE_LOADING_PRIORITY, config.fileLoadingPriority)
put(AUTOPLAY_VIDEOS, config.autoplayVideos)
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(OPEN_VIDEOS_ON_SEPARATE_SCREEN, config.openVideosOnSeparateScreen)
put(ALLOW_VIDEO_GESTURES, config.allowVideoGestures)
@ -738,7 +740,6 @@ class SettingsActivity : SimpleActivity() {
FILE_LOADING_PRIORITY -> config.fileLoadingPriority = value.toInt()
AUTOPLAY_VIDEOS -> config.autoplayVideos = value.toBoolean()
REMEMBER_LAST_VIDEO_POSITION -> config.rememberLastVideoPosition = value.toBoolean()
LAST_VIDEO_PATH -> config.lastVideoPath = value.toString()
LOOP_VIDEOS -> config.loopVideos = value.toBoolean()
OPEN_VIDEOS_ON_SEPARATE_SCREEN -> config.openVideosOnSeparateScreen = 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_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)

View File

@ -324,8 +324,9 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
}
private fun setLastVideoSavedPosition() {
if (config.lastVideoPath == mUri.toString() && config.lastVideoPosition > 0) {
setPosition(config.lastVideoPosition)
val pos = config.getLastVideoPosition(mUri.toString())
if(pos > 0) {
setPosition(pos)
}
}
@ -353,18 +354,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
private fun saveVideoProgress() {
if (!didVideoEnd()) {
config.apply {
lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
lastVideoPath = mUri.toString()
}
config.saveLastVideoPosition(mUri.toString(), mExoPlayer!!.currentPosition.toInt() / 1000)
}
}
private fun clearLastVideoSavedProgress() {
config.apply {
lastVideoPosition = 0
lastVideoPath = ""
}
config.removeLastVideoPosition(mUri.toString())
}
private fun setVideoSize() {

View File

@ -61,8 +61,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private var mStoredBottomActions = true
private var mStoredExtendedDetails = 0
private var mStoredRememberLastVideoPosition = false
private var mStoredLastVideoPath = ""
private var mStoredLastVideoPosition = 0
private lateinit var mTimeHolder: View
private lateinit var mBrightnessSideScroll: MediaSideScroll
@ -183,7 +181,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
setupVideoDuration()
if (mStoredRememberLastVideoPosition) {
setLastVideoSavedPosition()
restoreLastVideoSavedPosition()
}
updateInstantSwitchWidths()
@ -263,8 +261,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
mStoredExtendedDetails = extendedDetails
mStoredBottomActions = bottomActions
mStoredRememberLastVideoPosition = rememberLastVideoPosition
mStoredLastVideoPath = lastVideoPath
mStoredLastVideoPosition = lastVideoPosition
}
}
@ -285,19 +281,14 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private fun saveVideoProgress() {
if (!videoEnded()) {
mStoredLastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
mStoredLastVideoPath = mMedium.path
}
mConfig.apply {
lastVideoPosition = mStoredLastVideoPosition
lastVideoPath = mStoredLastVideoPath
mConfig.saveLastVideoPosition(mMedium.path, mExoPlayer!!.currentPosition.toInt() / 1000)
}
}
private fun setLastVideoSavedPosition() {
if (mStoredLastVideoPath == mMedium.path && mStoredLastVideoPosition > 0) {
setPosition(mStoredLastVideoPosition)
private fun restoreLastVideoSavedPosition() {
val pos = mConfig.getLastVideoPosition(mMedium.path)
if(pos > 0) {
setPosition(pos)
}
}
@ -563,8 +554,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
}
if (mStoredRememberLastVideoPosition) {
setLastVideoSavedPosition()
clearLastVideoSavedProgress()
restoreLastVideoSavedPosition()
}
if (!wasEnded || !mConfig.loopVideos) {
@ -582,11 +572,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
private fun clearLastVideoSavedProgress() {
mStoredLastVideoPosition = 0
mStoredLastVideoPath = ""
}
private fun pauseVideo() {
if (mExoPlayer == null) {
return

View File

@ -375,18 +375,26 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(BOTTOM_ACTIONS, true)
set(bottomActions) = prefs.edit().putBoolean(BOTTOM_ACTIONS, bottomActions).apply()
fun removeLastVideoPosition(path: String) {
prefs.edit().remove("$LAST_VIDEO_POSITION_PREFIX${path.toLowerCase()}").apply()
}
fun saveLastVideoPosition(path: String, value: Int) {
if (!path.isEmpty()) {
prefs.edit().putInt("$LAST_VIDEO_POSITION_PREFIX${path.toLowerCase()}", value).apply()
}
}
fun getLastVideoPosition(path: String): Int {
return prefs.getInt("$LAST_VIDEO_POSITION_PREFIX${path.toLowerCase()}", 0)
}
fun getAllLastVideoPositions() = prefs.all.filterKeys { it.startsWith(LAST_VIDEO_POSITION_PREFIX) }
var rememberLastVideoPosition: Boolean
get() = prefs.getBoolean(REMEMBER_LAST_VIDEO_POSITION, false)
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
get() = prefs.getInt(VISIBLE_BOTTOM_ACTIONS, DEFAULT_BOTTOM_ACTIONS)
set(visibleBottomActions) = prefs.edit().putInt(VISIBLE_BOTTOM_ACTIONS, visibleBottomActions).apply()

View File

@ -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 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_POSITION = "last_video_position"
const val LAST_VIDEO_POSITION_PREFIX = "last_video_position_"
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"