mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-11 17:20:39 +01:00
Fixed migration to check for empty database at every start
This commit is contained in:
parent
e8310b2ac8
commit
cc954e4d5a
@ -71,11 +71,10 @@ public class MainActivity extends SubsonicTabActivity
|
|||||||
|
|
||||||
// Determine first run and migrate server settings to DB as early as possible
|
// Determine first run and migrate server settings to DB as early as possible
|
||||||
boolean showWelcomeScreen = Util.isFirstRun(this);
|
boolean showWelcomeScreen = Util.isFirstRun(this);
|
||||||
if (showWelcomeScreen)
|
boolean areServersMigrated = serverSettingsModel.getValue().migrateFromPreferences();
|
||||||
{
|
|
||||||
// If settings were migrated, do not show welcome screen
|
// If there are any servers in the DB, do not show the welcome screen
|
||||||
showWelcomeScreen = !serverSettingsModel.getValue().migrateFromPreferences();
|
showWelcomeScreen &= !areServersMigrated;
|
||||||
}
|
|
||||||
|
|
||||||
if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT))
|
if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT))
|
||||||
{
|
{
|
||||||
|
@ -251,7 +251,7 @@ public class SelectArtistActivity extends SubsonicTabActivity implements Adapter
|
|||||||
String musicFolderId = activeServerProvider.getValue().getActiveServer().getMusicFolderId();
|
String musicFolderId = activeServerProvider.getValue().getActiveServer().getMusicFolderId();
|
||||||
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
|
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
|
||||||
|
|
||||||
if (musicFolderId == null)
|
if (musicFolderId == null || musicFolderId.isEmpty())
|
||||||
{
|
{
|
||||||
menuItem.setChecked(true);
|
menuItem.setChecked(true);
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,11 @@ class ServerSettingsModel(
|
|||||||
var migrated = true
|
var migrated = true
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val dbServerList = repository.loadAllServerSettings().toMutableList()
|
val rowCount = repository.count()
|
||||||
|
|
||||||
if (dbServerList.isEmpty()) {
|
if (rowCount == null || rowCount == 0) {
|
||||||
// First time load up the server settings from the Preferences
|
// First time load up the server settings from the Preferences
|
||||||
|
val dbServerList = mutableListOf<ServerSetting>()
|
||||||
val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)
|
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)
|
||||||
|
|
||||||
@ -192,7 +193,7 @@ class ServerSettingsModel(
|
|||||||
if (serverSetting == null) return
|
if (serverSetting == null) return
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
serverSetting.index = (repository.getMaxIndex() ?: 0) + 1
|
serverSetting.index = (repository.count() ?: 0) + 1
|
||||||
serverSetting.id = serverSetting.index
|
serverSetting.id = serverSetting.index
|
||||||
repository.insert(serverSetting)
|
repository.insert(serverSetting)
|
||||||
Log.d(TAG, "saveNewItem saved server setting: $serverSetting")
|
Log.d(TAG, "saveNewItem saved server setting: $serverSetting")
|
||||||
|
@ -50,8 +50,8 @@ interface ServerSettingDao {
|
|||||||
suspend fun findByIndex(index: Int): ServerSetting?
|
suspend fun findByIndex(index: Int): ServerSetting?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the greatest Index in stored in the table
|
* Retrieves the count of rows in the table
|
||||||
*/
|
*/
|
||||||
@Query("SELECT MAX([index]) FROM serverSetting")
|
@Query("SELECT COUNT(*) FROM serverSetting")
|
||||||
suspend fun getMaxIndex(): Int?
|
suspend fun count(): Int?
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user