[Android] Allow skipping resuming video playback + settings migration

Nicolas Pomepuy git at videolan.org
Mon Oct 7 15:05:30 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Sep 20 11:20:03 2019 +0200| [3539249c7e6b6004cee035f00147b37564fc118e] | committer: Geoffrey Métais

Allow skipping resuming video playback + settings migration

Fixes #1042

> https://code.videolan.org/videolan/vlc-android/commit/3539249c7e6b6004cee035f00147b37564fc118e
---

 vlc-android/res/values/arrays.xml                  | 12 +++++
 vlc-android/res/values/strings.xml                 |  6 ++-
 vlc-android/res/xml/preferences_video.xml          | 10 ++--
 vlc-android/src/org/videolan/vlc/VLCApplication.kt |  1 +
 .../videolan/vlc/gui/video/VideoPlayerActivity.kt  |  6 +--
 vlc-android/src/org/videolan/vlc/util/Settings.kt  |  3 ++
 .../src/org/videolan/vlc/util/SettingsMigration.kt | 53 ++++++++++++++++++++++
 7 files changed, 82 insertions(+), 9 deletions(-)

diff --git a/vlc-android/res/values/arrays.xml b/vlc-android/res/values/arrays.xml
index bc55f6c38..2b6170575 100644
--- a/vlc-android/res/values/arrays.xml
+++ b/vlc-android/res/values/arrays.xml
@@ -411,4 +411,16 @@
         <item>2</item>
     </string-array>
 
+    <string-array name="ask_confirmation_entries">
+        <item>@string/always</item>
+        <item>@string/never</item>
+        <item>@string/ask_confirmation</item>
+    </string-array>
+
+    <string-array name="ask_confirmation_values">
+        <item>0</item>
+        <item>1</item>
+        <item>2</item>
+    </string-array>
+
 </resources>
\ No newline at end of file
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 24c6a9e45..585e299e0 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -510,8 +510,7 @@
     <string name="chapter">Chapter</string>
     <string name="resume_from_position">Resume from last position</string>
     <string name="confirm_resume">Resume from last position?</string>
-    <string name="confirm_resume_title">Ask confirmation to resume</string>
-    <string name="confirm_resume_summary">if activated you will be asked to confirm when a video can be resumed from last position</string>
+    <string name="confirm_resume_title">Resume played videos</string>
     <string name="directory_empty">Directory is empty</string>
     <string name="tv_ui_title">Android TV interface</string>
     <string name="tv_ui_summary">Change UI to TV adapted theme</string>
@@ -731,6 +730,9 @@
     <string name="report_a_crash">Report a crash</string>
     <string name="describe_crash">Please describe how this crash happened</string>
     <string name="favorite">Favorite</string>
+    <string name="always">Always</string>
+    <string name="never">Never</string>
+    <string name="ask_confirmation">Ask confirmation</string>
     <string name="add_to_scanned">Scan this folder</string>
     <string name="directory_not_scanned">This directory is not scanned</string>
     <string name="scanned_directory_added">%s added to your scanned directories</string>
diff --git a/vlc-android/res/xml/preferences_video.xml b/vlc-android/res/xml/preferences_video.xml
index 193d674f5..a6b4faea6 100644
--- a/vlc-android/res/xml/preferences_video.xml
+++ b/vlc-android/res/xml/preferences_video.xml
@@ -41,11 +41,13 @@
             android:key="popup_force_legacy"
             android:summary="@string/popup_force_legacy_summary"
             android:title="@string/popup_force_legacy_title"/>
-    <CheckBoxPreference
+    <ListPreference
             app:singleLineTitle="false"
-            android:defaultValue="false"
-            android:key="dialog_confirm_resume"
-            android:summary="@string/confirm_resume_summary"
+            android:defaultValue="0"
+            android:key="video_confirm_resume"
+            android:entries="@array/ask_confirmation_entries"
+            android:entryValues="@array/ask_confirmation_values"
+            android:summary="%s"
             android:title="@string/confirm_resume_title"/>
 
     <PreferenceCategory android:title="@string/controls_prefs_category">
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.kt b/vlc-android/src/org/videolan/vlc/VLCApplication.kt
index 09bc4f694..c443b09db 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.kt
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.kt
@@ -114,6 +114,7 @@ class VLCApplication : MultiDexApplication() {
             })
             packageManager.setComponentEnabledSetting(ComponentName(this, SendCrashActivity::class.java),
                     if (BuildConfig.BETA) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
+            SettingsMigration.migrateSettings(this)
         }).start()
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 72399cace..615287faa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -442,7 +442,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
 
         switchingView = false
 
-        askResume = settings.getBoolean("dialog_confirm_resume", false)
+        askResume = settings.getString(KEY_VIDEO_CONFIRM_RESUME, "0") == "2"
         sDisplayRemainingTime = settings.getBoolean(KEY_REMAINING_TIME_DISPLAY, false)
         // Clear the resume time, since it is only used for resumes in external
         // videos.
@@ -2291,7 +2291,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
         service?.let { service ->
             isPlaying = false
             var title: String? = null
-            var fromStart = false
+            var fromStart = settings.getString(KEY_VIDEO_CONFIRM_RESUME, "0") == "1"
             var itemTitle: String? = null
             var positionInPlaylist = -1
             val intent = intent
@@ -2316,7 +2316,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
             if (extras != null) {
                 if (intent.hasExtra(PLAY_EXTRA_ITEM_LOCATION))
                     videoUri = extras.getParcelable(PLAY_EXTRA_ITEM_LOCATION)
-                fromStart = extras.getBoolean(PLAY_EXTRA_FROM_START, false)
+                fromStart = extras.getBoolean(PLAY_EXTRA_FROM_START, false) || settings.getString(KEY_VIDEO_CONFIRM_RESUME, "0") == "1"
                 // Consume fromStart option after first use to prevent
                 // restarting again when playback is paused.
                 intent.putExtra(PLAY_EXTRA_FROM_START, false)
diff --git a/vlc-android/src/org/videolan/vlc/util/Settings.kt b/vlc-android/src/org/videolan/vlc/util/Settings.kt
index 9f08aafdf..6ee2e3269 100644
--- a/vlc-android/src/org/videolan/vlc/util/Settings.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Settings.kt
@@ -29,12 +29,15 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ PreferenceManage
 
 }
 
+const val KEY_CURRENT_SETTINGS_VERSION = "current_settings_version"
+
 // Keys
 const val KEY_ARTISTS_SHOW_ALL = "artists_show_all"
 const val KEY_APP_THEME = "app_theme"
 const val KEY_BLACK_THEME = "enable_black_theme"
 const val KEY_DAYNIGHT = "daynight"
 const val SHOW_VIDEO_THUMBNAILS = "show_video_thumbnails"
+const val KEY_VIDEO_CONFIRM_RESUME = "video_confirm_resume"
 
 //UI
 const val LIST_TITLE_ELLIPSIZE = "list_title_ellipsize"
diff --git a/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt b/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt
new file mode 100644
index 000000000..5d000c973
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt
@@ -0,0 +1,53 @@
+/*
+ * ************************************************************************
+ *  SettingsMigration.kt
+ * *************************************************************************
+ * Copyright © 2019 VLC authors and VideoLAN
+ * Author: Nicolas POMEPUY
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * **************************************************************************
+ *
+ *
+ */
+
+package org.videolan.vlc.util
+
+import android.content.Context
+import android.content.SharedPreferences
+import android.util.Log
+import org.videolan.vlc.BuildConfig
+
+object SettingsMigration {
+
+    fun migrateSettings(context: Context) {
+        val settings = Settings.getInstance(context)
+        val lastVersion = settings.getInt(KEY_CURRENT_SETTINGS_VERSION, 0)
+        if (lastVersion < 3030000) {
+            migrateToVersion3030000(settings)
+        }
+        settings.edit().putInt(KEY_CURRENT_SETTINGS_VERSION, BuildConfig.VERSION_CODE).apply()
+    }
+
+    private fun migrateToVersion3030000(settings: SharedPreferences) {
+        Log.i(this::class.java.simpleName, "Migrating preferences to 3030000")
+        val editor = settings.edit()
+        val dialogConfirmResume = settings.getBoolean("dialog_confirm_resume", false)
+        if (dialogConfirmResume) {
+            editor.putString(KEY_VIDEO_CONFIRM_RESUME, "2")
+        }
+        editor.remove("dialog_confirm_resume")
+        editor.apply()
+    }
+}
\ No newline at end of file



More information about the Android mailing list