File tree Expand file tree Collapse file tree
app/src/main/java/com/github/libretube Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class LibreTubeApp : Application() {
2626 * Initialize the [PreferenceHelper]
2727 */
2828 PreferenceHelper .initialize(applicationContext)
29+ PreferenceHelper .migrate()
2930
3031 /* *
3132 * Set the api and the auth api url
Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ object PreferenceKeys {
145145 const val SELECTED_CHANNEL_GROUP = " selected_channel_group"
146146 const val SELECTED_DOWNLOAD_SORT_TYPE = " selected_download_sort_type"
147147 const val LAST_SHOWN_INFO_MESSAGE_VERSION_CODE = " last_shown_info_message_version"
148+ const val PREFERENCE_VERSION = " PREFERENCE_VERSION"
148149
149150 // use the helper methods at PreferenceHelper to access these
150151 const val LAST_USER_SEEN_FEED_TIME = " last_watched_feed_time"
Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ package com.github.libretube.helpers
22
33import android.content.Context
44import android.content.SharedPreferences
5+ import android.util.Log
56import androidx.core.content.edit
67import androidx.preference.PreferenceManager
8+ import com.github.libretube.BuildConfig
79import com.github.libretube.constants.PreferenceKeys
810
911object PreferenceHelper {
12+ private val TAG = PreferenceHelper ::class .simpleName
13+
1014 /* *
1115 * for normal preferences
1216 */
@@ -30,6 +34,19 @@ object PreferenceHelper {
3034 authSettings = getAuthenticationPreferences(context)
3135 }
3236
37+ /* *
38+ * Migrate preference to a new version
39+ */
40+ fun migrate () {
41+ val prefVersion = getInt(PreferenceKeys .PREFERENCE_VERSION , - 1 )
42+ // check if there are any prefs to migrate
43+ if (prefVersion == BuildConfig .VERSION_CODE )
44+ return
45+
46+ // mark as successfully migrated
47+ putInt(PreferenceKeys .PREFERENCE_VERSION , BuildConfig .VERSION_CODE )
48+ }
49+
3350 fun putString (key : String , value : String ) {
3451 settings.edit(commit = true ) { putString(key, value) }
3552 }
You can’t perform that action at this time.
0 commit comments