mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-05-06 18:41:05 +03:00
Remove migration function from 2020.
All regular users will have run the migration by now.
This commit is contained in:
parent
287169649a
commit
1d88c585c4
ultrasonic/src/main/kotlin/org/moire/ultrasonic
@ -157,9 +157,8 @@ class NavigationActivity : AppCompatActivity() {
|
|||||||
setMenuForServerCapabilities()
|
setMenuForServerCapabilities()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine first run and migrate server settings to DB as early as possible
|
// Determine if this is a first run
|
||||||
var showWelcomeScreen = Util.isFirstRun()
|
val showWelcomeScreen = Util.isFirstRun()
|
||||||
val areServersMigrated: Boolean = serverSettingsModel.migrateFromPreferences()
|
|
||||||
|
|
||||||
// Migrate Feature storage if needed
|
// Migrate Feature storage if needed
|
||||||
// TODO: Remove in December 2022
|
// TODO: Remove in December 2022
|
||||||
@ -167,9 +166,6 @@ class NavigationActivity : AppCompatActivity() {
|
|||||||
Settings.migrateFeatureStorage()
|
Settings.migrateFeatureStorage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are any servers in the DB, do not show the welcome screen
|
|
||||||
showWelcomeScreen = showWelcomeScreen and !areServersMigrated
|
|
||||||
|
|
||||||
loadSettings()
|
loadSettings()
|
||||||
|
|
||||||
// This is a first run with only the demo entry inside the database
|
// This is a first run with only the demo entry inside the database
|
||||||
@ -194,14 +190,14 @@ class NavigationActivity : AppCompatActivity() {
|
|||||||
recreate()
|
recreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
serverRepository.liveServerCount().observe(
|
serverRepository.liveServerCount().observe(this) { count ->
|
||||||
this,
|
cachedServerCount = count ?: 0
|
||||||
{ count ->
|
updateNavigationHeaderForServer()
|
||||||
cachedServerCount = count ?: 0
|
}
|
||||||
updateNavigationHeaderForServer()
|
|
||||||
}
|
ActiveServerProvider.liveActiveServerId.observe(this) {
|
||||||
)
|
updateNavigationHeaderForServer()
|
||||||
ActiveServerProvider.liveActiveServerId.observe(this, { updateNavigationHeaderForServer() })
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateNavigationHeaderForServer() {
|
private fun updateNavigationHeaderForServer() {
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package org.moire.ultrasonic.model
|
package org.moire.ultrasonic.model
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.SharedPreferences
|
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
@ -29,46 +27,6 @@ class ServerSettingsModel(
|
|||||||
|
|
||||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
|
||||||
/**
|
|
||||||
* This function will try and convert settings from the Preferences to the Database
|
|
||||||
* @return True, if the migration was executed, False otherwise
|
|
||||||
*/
|
|
||||||
fun migrateFromPreferences(): Boolean {
|
|
||||||
var migrated = true
|
|
||||||
|
|
||||||
runBlocking {
|
|
||||||
val rowCount = repository.count()
|
|
||||||
|
|
||||||
if (rowCount == null || rowCount == 0) {
|
|
||||||
// First time load up the server settings from the Preferences
|
|
||||||
val dbServerList = mutableListOf<ServerSetting>()
|
|
||||||
val context = getApplication<Application>().applicationContext
|
|
||||||
val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)
|
|
||||||
|
|
||||||
if (serverNum != 0) {
|
|
||||||
var index = 1
|
|
||||||
for (x in 1 until serverNum + 1) {
|
|
||||||
val newServerSetting = loadServerSettingFromPreferences(x, index, settings)
|
|
||||||
if (newServerSetting != null) {
|
|
||||||
dbServerList.add(newServerSetting)
|
|
||||||
repository.insert(newServerSetting)
|
|
||||||
index++
|
|
||||||
Timber.i(
|
|
||||||
"Imported server from Preferences to Database: %s",
|
|
||||||
newServerSetting.name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
migrated = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return migrated
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the list of the configured servers from the database.
|
* Retrieves the list of the configured servers from the database.
|
||||||
* This function is asynchronous, uses LiveData to provide the Setting.
|
* This function is asynchronous, uses LiveData to provide the Setting.
|
||||||
@ -192,40 +150,6 @@ class ServerSettingsModel(
|
|||||||
return demo.id
|
return demo.id
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads up a Server Setting stored in the obsolete Preferences
|
|
||||||
*/
|
|
||||||
private fun loadServerSettingFromPreferences(
|
|
||||||
preferenceId: Int,
|
|
||||||
serverId: Int,
|
|
||||||
settings: SharedPreferences
|
|
||||||
): ServerSetting? {
|
|
||||||
val url = settings.getString(PREFERENCES_KEY_SERVER_URL + preferenceId, "")
|
|
||||||
val userName = settings.getString(PREFERENCES_KEY_USERNAME + preferenceId, "")
|
|
||||||
val isMigrated = settings.getBoolean(PREFERENCES_KEY_SERVER_MIGRATED + preferenceId, false)
|
|
||||||
|
|
||||||
if (url.isNullOrEmpty() || userName.isNullOrEmpty() || isMigrated) return null
|
|
||||||
setServerMigrated(settings, preferenceId)
|
|
||||||
|
|
||||||
return ServerSetting(
|
|
||||||
preferenceId,
|
|
||||||
serverId,
|
|
||||||
settings.getString(PREFERENCES_KEY_SERVER_NAME + preferenceId, "")!!,
|
|
||||||
url,
|
|
||||||
null,
|
|
||||||
userName,
|
|
||||||
settings.getString(PREFERENCES_KEY_PASSWORD + preferenceId, "")!!,
|
|
||||||
settings.getBoolean(PREFERENCES_KEY_JUKEBOX_BY_DEFAULT + preferenceId, false),
|
|
||||||
settings.getBoolean(
|
|
||||||
PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + preferenceId,
|
|
||||||
false
|
|
||||||
),
|
|
||||||
settings.getBoolean(PREFERENCES_KEY_LDAP_SUPPORT + preferenceId, false),
|
|
||||||
settings.getString(PREFERENCES_KEY_MUSIC_FOLDER_ID + preferenceId, null),
|
|
||||||
null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there are any missing indexes in the ServerSetting list
|
* Checks if there are any missing indexes in the ServerSetting list
|
||||||
* For displaying the Server Settings in a ListView, it is mandatory that their indexes
|
* For displaying the Server Settings in a ListView, it is mandatory that their indexes
|
||||||
@ -263,25 +187,7 @@ class ServerSettingsModel(
|
|||||||
return indexesInDatabase
|
return indexesInDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setServerMigrated(settings: SharedPreferences, preferenceId: Int) {
|
|
||||||
val editor = settings.edit()
|
|
||||||
editor.putBoolean(PREFERENCES_KEY_SERVER_MIGRATED + preferenceId, true)
|
|
||||||
editor.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PREFERENCES_KEY_SERVER_MIGRATED = "serverMigrated"
|
|
||||||
// These constants were removed from Constants.java as they are deprecated and only used here
|
|
||||||
private const val PREFERENCES_KEY_JUKEBOX_BY_DEFAULT = "jukeboxEnabled"
|
|
||||||
private const val PREFERENCES_KEY_SERVER_NAME = "serverName"
|
|
||||||
private const val PREFERENCES_KEY_SERVER_URL = "serverUrl"
|
|
||||||
private const val PREFERENCES_KEY_ACTIVE_SERVERS = "activeServers"
|
|
||||||
private const val PREFERENCES_KEY_USERNAME = "username"
|
|
||||||
private const val PREFERENCES_KEY_PASSWORD = "password"
|
|
||||||
private const val PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE = "allowSSCertificate"
|
|
||||||
private const val PREFERENCES_KEY_LDAP_SUPPORT = "enableLdapSupport"
|
|
||||||
private const val PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"
|
|
||||||
|
|
||||||
private val DEMO_SERVER_CONFIG = ServerSetting(
|
private val DEMO_SERVER_CONFIG = ServerSetting(
|
||||||
id = 0,
|
id = 0,
|
||||||
index = 0,
|
index = 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user