Fixed migration to check for empty database at every start

This commit is contained in:
Nite 2020-09-22 17:03:04 +02:00
parent e8310b2ac8
commit cc954e4d5a
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
4 changed files with 12 additions and 12 deletions

View File

@ -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))
{

View File

@ -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);
}

View File

@ -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")

View File

@ -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?
}