From e54954a97dc607907445799780d75cc656ddfd56 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 11 Sep 2022 17:20:35 +0200 Subject: [PATCH] remove database migration code --- .../main/java/com/github/libretube/MyApp.kt | 73 ------------------- .../extensions/SetFormattedDuration.kt | 1 - 2 files changed, 74 deletions(-) diff --git a/app/src/main/java/com/github/libretube/MyApp.kt b/app/src/main/java/com/github/libretube/MyApp.kt index c3d24e891..12f01bb64 100644 --- a/app/src/main/java/com/github/libretube/MyApp.kt +++ b/app/src/main/java/com/github/libretube/MyApp.kt @@ -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>() {} - 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>() {} - 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() - } } diff --git a/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt b/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt index 2b8753b81..1bc173c7e 100644 --- a/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt +++ b/app/src/main/java/com/github/libretube/extensions/SetFormattedDuration.kt @@ -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) {