#505 remembering last video position
This commit is contained in:
parent
c8d7935705
commit
70656183a8
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -278,6 +278,30 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_remember_last_video_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_remember_last_video"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:text="@string/remember_last_video"
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_loop_videos_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -133,6 +133,7 @@
|
|||
|
||||
<!-- Settings -->
|
||||
<string name="autoplay_videos">Play videos automatically</string>
|
||||
<string name="remember_last_video">Remember last video playback position</string>
|
||||
<string name="toggle_filename">Toggle filename visibility</string>
|
||||
<string name="loop_videos">Loop videos</string>
|
||||
<string name="animate_gifs">Animate GIFs at thumbnails</string>
|
||||
|
|
Loading…
Reference in New Issue