Merge pull request #1038 from mathevs/master

#505 remembering last video position
This commit is contained in:
Tibor Kaputa 2018-11-01 12:05:29 +01:00 committed by GitHub
commit ad0cebf6a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 121 additions and 1 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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()

View File

@ -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"

View File

@ -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"

View File

@ -137,6 +137,7 @@
<!-- Settings -->
<string name="autoplay_videos">تشغيل الفديوهات تلقائيا</string>
<string name="remember_last_video" >Remember last video playback position</string>
<string name="toggle_filename">تبديل رؤية اسم الملف</string>
<string name="loop_videos">حلقة الفيديو</string>
<string name="animate_gifs">عرض صور GIF المتحركة في الصور المصغرة</string>

View File

@ -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>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Reproduir vídeos automàticament</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Canviar la visibilitat del nom d\'arxiu</string>
<string name="loop_videos">Reproducció continua de vídeos</string>
<string name="animate_gifs">Animar les miniatures dels GIFs</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Automaticky přehrávat videa</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Přepnout viditelnost názvů souborů</string>
<string name="loop_videos">Přehrávat videa ve smyčce</string>
<string name="animate_gifs">Animovat náhledy souborů GIF</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Afspil automatisk videoer</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Toggle filename visibility</string>
<string name="loop_videos">Kør videoer i sløjfe</string>
<string name="animate_gifs">Animér GIF\'er i miniaturer</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Videos automatisch abspielen</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Beschriftungen ein/aus</string>
<string name="loop_videos">Videos in Endlosschleife abspielen</string>
<string name="animate_gifs">Kacheln von GIFs animieren</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Αυτόματη αναπαραγωγή βίντεο</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Αλλαγή προβολής ονόματος αρχείων</string>
<string name="loop_videos">Επανάληψη βίντεο</string>
<string name="animate_gifs">Εμφάνιση κινούμενων GIFs στα εικονίδια</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Reproducir vídeos automáticamente</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Cambiar la visibilidad del nombre de archivo</string>
<string name="loop_videos">Reproducción continua de vídeos</string>
<string name="animate_gifs">Animar las miniaturas de GIFs</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Toista videot automaattisesti</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Tiedostonimien näkyvyys</string>
<string name="loop_videos">Jatkuvat videot</string>
<string name="animate_gifs">Animoi GIFit pienoiskuvissa</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Lecture automatique des vidéos</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Permuter la visibilité des noms de fichier</string>
<string name="loop_videos">Lecture en boucle des vidéos</string>
<string name="animate_gifs">GIFs animés sur les miniatures</string>
@ -235,7 +236,7 @@
This app is just one piece of a bigger series of apps. You can find the rest of them at https://www.simplemobiletools.com
</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Reproducir vídeos automticamente</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Mudar a visibilidade do ficheiro</string>
<string name="loop_videos">videos en bucle</string>
<string name="animate_gifs">Animar os GIFs na icona</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Automatsko pokretanje videa</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Uključi prikaz naziva datoteka</string>
<string name="loop_videos">Ponavljanje videa</string>
<string name="animate_gifs">Prikaz animacije GIF-ova na sličicama</string>

View File

@ -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>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Riproduci i video automaticamente</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Visibilità nome del file</string>
<string name="loop_videos">Ripeti i video</string>
<string name="animate_gifs">Anima le GIF in miniatura</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">ビデオを自動再生</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">ファイル名の表示を切り替え</string>
<string name="loop_videos">ビデオを繰り返し再生</string>
<string name="animate_gifs">アニメーションGIFを動かす</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">비디오 자동재생</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">파일이름 보기</string>
<string name="loop_videos">비디오 반복</string>
<string name="animate_gifs">섬네일에서 GIFs 애니메이션 활성화</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Groti vaizdo įrašus automatiškai</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Perjungti bylos pavadinimo matomumą</string>
<string name="loop_videos">Klipuoti vaizdo įrašus</string>
<string name="animate_gifs">Animuoti GIF\'us miniatiūrose</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Avspill videoer automatisk</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Vis/skjul filnavn</string>
<string name="loop_videos">Gjenta videoer</string>
<string name="animate_gifs">Animert GIF i minibildevisning</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Video\'s automatisch afspelen</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Bestandsnamen tonen</string>
<string name="loop_videos">Video\'s herhalen</string>
<string name="animate_gifs">GIF-bestanden afspelen in overzicht</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Odtwarzaj filmy automatycznie</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Pokazuj / ukrywaj nazwy plików</string>
<string name="loop_videos">Zapętlaj odtwarzanie filmów</string>
<string name="animate_gifs">Animowane miniatury GIFów</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Reproduzir vídeos automaticamente</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Mostrar/ocultar nome do arquivo</string>
<string name="loop_videos">Reproduzir vídeos em ciclo</string>
<string name="animate_gifs">Animação de GIFs nas miniaturas</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Reproduzir vídeos automaticamente</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Mostrar/ocultar nome do ficheiro</string>
<string name="loop_videos">Vídeos em ciclo</string>
<string name="animate_gifs">Animação de GIF nas miniaturas</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Воспроизводить видео автоматически</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Переключить отображение имени файла</string>
<string name="loop_videos">Повтор видео</string>
<string name="animate_gifs">Анимировать эскизы GIF</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Spúšťať videá automaticky</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Prepnúť viditeľnosť názvov súborov</string>
<string name="loop_videos">Automaticky reštartovať videá</string>
<string name="animate_gifs">Animovať GIF súbory pri náhľade</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Spela upp videor automatiskt</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Visa/dölj filnamn</string>
<string name="loop_videos">Spela upp videor om och om igen</string>
<string name="animate_gifs">Animera GIF-bilders miniatyrer</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Videoları otomatik olarak oynat</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Dosya adı görünürlüğünü değiştir</string>
<string name="loop_videos">Videolar döngüsü</string>
<string name="animate_gifs">Küçük resimlerde GIF\'leri canlandırın</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">Відтворювати відео автоматично</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">Перемкнути відображення імені файлу</string>
<string name="loop_videos">Зациклити відео</string>
<string name="animate_gifs">Анімувати ескізи GIF-файлів</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">自动播放</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">显示文件名</string>
<string name="loop_videos">循环播放视频</string>
<string name="animate_gifs">GIF 缩略图</string>

View File

@ -133,6 +133,7 @@
<!-- Settings -->
<string name="autoplay_videos">自動播放影片</string>
<string name="remember_last_video">Remember last video playback position</string>
<string name="toggle_filename">顯示檔案名稱</string>
<string name="loop_videos">影片循環播放</string>
<string name="animate_gifs">縮圖顯示GIF動畫</string>

View File

@ -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>