mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #1269 from Bnyro/master
remove database migration code
This commit is contained in:
commit
b4d15b9321
@ -4,22 +4,16 @@ import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.StrictMode
|
||||
import android.os.StrictMode.VmPolicy
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import com.fasterxml.jackson.core.type.TypeReference
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.github.libretube.api.CronetHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
|
||||
import com.github.libretube.constants.DOWNLOAD_CHANNEL_ID
|
||||
import com.github.libretube.constants.PUSH_CHANNEL_ID
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.WatchHistoryItem
|
||||
import com.github.libretube.db.obj.WatchPosition
|
||||
import com.github.libretube.util.ExceptionHandler
|
||||
import com.github.libretube.util.ImageHelper
|
||||
import com.github.libretube.util.NotificationHelper
|
||||
@ -70,16 +64,6 @@ class MyApp : Application() {
|
||||
val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||
val exceptionHandler = ExceptionHandler(defaultExceptionHandler)
|
||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler)
|
||||
|
||||
/**
|
||||
* Legacy preference file migration
|
||||
*/
|
||||
prefFileMigration()
|
||||
|
||||
/**
|
||||
* Database Migration
|
||||
*/
|
||||
databaseMigration()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,61 +110,4 @@ class MyApp : Application() {
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from old preference files to new one
|
||||
*/
|
||||
private fun prefFileMigration() {
|
||||
val legacyUserPrefs = getSharedPreferences("username", Context.MODE_PRIVATE)
|
||||
val username = legacyUserPrefs.getString("username", "")!!
|
||||
if (username != "") {
|
||||
PreferenceHelper.setUsername(username)
|
||||
legacyUserPrefs.edit().putString("username", "").apply()
|
||||
}
|
||||
val legacyTokenPrefs = getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
val token = legacyUserPrefs.getString("token", "")!!
|
||||
if (token != "") {
|
||||
PreferenceHelper.setToken(token)
|
||||
legacyTokenPrefs.edit().putString("token", "").apply()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from the preferences to the database
|
||||
*/
|
||||
private fun databaseMigration() {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
Thread {
|
||||
val legacyWatchHistory = prefs.getString("watch_history", "")
|
||||
if (legacyWatchHistory != "") {
|
||||
try {
|
||||
val type = object : TypeReference<List<WatchHistoryItem>>() {}
|
||||
val watchHistoryItems = mapper.readValue(legacyWatchHistory, type)
|
||||
DatabaseHolder.db.watchHistoryDao().insertAll(
|
||||
*watchHistoryItems.toTypedArray()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
prefs.edit().putString("watch_history", "").apply()
|
||||
}
|
||||
val legacyWatchPositions = prefs.getString("watch_positions", "")
|
||||
if (legacyWatchPositions != "") {
|
||||
try {
|
||||
val type = object : TypeReference<List<WatchPosition>>() {}
|
||||
val watchPositions = mapper.readValue(legacyWatchPositions, type)
|
||||
DatabaseHolder.db.watchPositionDao().insertAll(
|
||||
*watchPositions.toTypedArray()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
prefs.edit().remove("watch_positions").apply()
|
||||
}
|
||||
prefs.edit()
|
||||
.remove("custom_instances")
|
||||
.remove("local_subscriptions")
|
||||
.apply()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.github.libretube.extensions
|
||||
import android.text.format.DateUtils
|
||||
import android.widget.TextView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
|
||||
fun TextView.setFormattedDuration(duration: Long) {
|
||||
val text = if (duration < 0L) {
|
||||
|
Loading…
Reference in New Issue
Block a user