mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-06 12:03:27 +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
|
||||
boolean showWelcomeScreen = Util.isFirstRun(this);
|
||||
if (showWelcomeScreen)
|
||||
{
|
||||
// If settings were migrated, do not show welcome screen
|
||||
showWelcomeScreen = !serverSettingsModel.getValue().migrateFromPreferences();
|
||||
}
|
||||
boolean areServersMigrated = serverSettingsModel.getValue().migrateFromPreferences();
|
||||
|
||||
// If there are any servers in the DB, do not show the welcome screen
|
||||
showWelcomeScreen &= !areServersMigrated;
|
||||
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
@ -47,10 +47,11 @@ class ServerSettingsModel(
|
||||
var migrated = true
|
||||
|
||||
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
|
||||
val dbServerList = mutableListOf<ServerSetting>()
|
||||
val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val serverNum = settings.getInt(PREFERENCES_KEY_ACTIVE_SERVERS, 0)
|
||||
|
||||
@ -192,7 +193,7 @@ class ServerSettingsModel(
|
||||
if (serverSetting == null) return
|
||||
|
||||
viewModelScope.launch {
|
||||
serverSetting.index = (repository.getMaxIndex() ?: 0) + 1
|
||||
serverSetting.index = (repository.count() ?: 0) + 1
|
||||
serverSetting.id = serverSetting.index
|
||||
repository.insert(serverSetting)
|
||||
Log.d(TAG, "saveNewItem saved server setting: $serverSetting")
|
||||
|
@ -50,8 +50,8 @@ interface ServerSettingDao {
|
||||
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")
|
||||
suspend fun getMaxIndex(): Int?
|
||||
@Query("SELECT COUNT(*) FROM serverSetting")
|
||||
suspend fun count(): Int?
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user