Auto-select newly created profiles
Previously, profiles were only auto-selected when no profile was selected. Now any new profile (created manually or imported) is immediately selected, improving user experience.
This commit is contained in:
@@ -9,7 +9,6 @@ import io.nekohasekai.sfa.R
|
|||||||
import io.nekohasekai.sfa.bg.UpdateProfileWork
|
import io.nekohasekai.sfa.bg.UpdateProfileWork
|
||||||
import io.nekohasekai.sfa.database.Profile
|
import io.nekohasekai.sfa.database.Profile
|
||||||
import io.nekohasekai.sfa.database.ProfileManager
|
import io.nekohasekai.sfa.database.ProfileManager
|
||||||
import io.nekohasekai.sfa.database.Settings
|
|
||||||
import io.nekohasekai.sfa.database.TypedProfile
|
import io.nekohasekai.sfa.database.TypedProfile
|
||||||
import io.nekohasekai.sfa.utils.HTTPClient
|
import io.nekohasekai.sfa.utils.HTTPClient
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -258,13 +257,8 @@ class NewProfileViewModel(application: Application) : AndroidViewModel(applicati
|
|||||||
Libbox.checkConfig(configContent)
|
Libbox.checkConfig(configContent)
|
||||||
configFile.writeText(configContent)
|
configFile.writeText(configContent)
|
||||||
|
|
||||||
// Create profile in database
|
// Create profile in database and select it
|
||||||
ProfileManager.create(profile)
|
ProfileManager.create(profile, andSelect = true)
|
||||||
|
|
||||||
// If no profile is currently selected, select this one
|
|
||||||
if (Settings.selectedProfile == -1L) {
|
|
||||||
Settings.selectedProfile = profile.id
|
|
||||||
}
|
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
}
|
}
|
||||||
@@ -297,13 +291,8 @@ class NewProfileViewModel(application: Application) : AndroidViewModel(applicati
|
|||||||
|
|
||||||
configFile.writeText(configContent)
|
configFile.writeText(configContent)
|
||||||
|
|
||||||
// Create profile in database
|
// Create profile in database and select it
|
||||||
ProfileManager.create(profile)
|
ProfileManager.create(profile, andSelect = true)
|
||||||
|
|
||||||
// If no profile is currently selected, select this one
|
|
||||||
if (Settings.selectedProfile == -1L) {
|
|
||||||
Settings.selectedProfile = profile.id
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reconfigure updater if auto-update is enabled
|
// Reconfigure updater if auto-update is enabled
|
||||||
if (state.autoUpdate) {
|
if (state.autoUpdate) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import io.nekohasekai.libbox.ProfileContent
|
|||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
import io.nekohasekai.sfa.database.Profile
|
import io.nekohasekai.sfa.database.Profile
|
||||||
import io.nekohasekai.sfa.database.ProfileManager
|
import io.nekohasekai.sfa.database.ProfileManager
|
||||||
import io.nekohasekai.sfa.database.Settings
|
|
||||||
import io.nekohasekai.sfa.database.TypedProfile
|
import io.nekohasekai.sfa.database.TypedProfile
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -178,13 +177,8 @@ class ProfileImportHandler(private val context: Context) {
|
|||||||
configFile.writeText(content.config)
|
configFile.writeText(content.config)
|
||||||
typedProfile.path = configFile.path
|
typedProfile.path = configFile.path
|
||||||
|
|
||||||
// Create profile in database
|
// Create profile in database and select it
|
||||||
ProfileManager.create(profile)
|
ProfileManager.create(profile, andSelect = true)
|
||||||
|
|
||||||
// If no profile is currently selected, select this one
|
|
||||||
if (Settings.selectedProfile == -1L) {
|
|
||||||
Settings.selectedProfile = profile.id
|
|
||||||
}
|
|
||||||
|
|
||||||
return ImportResult.Success(profile)
|
return ImportResult.Success(profile)
|
||||||
}
|
}
|
||||||
@@ -213,12 +207,8 @@ class ProfileImportHandler(private val context: Context) {
|
|||||||
configFile.writeText("{}")
|
configFile.writeText("{}")
|
||||||
typedProfile.path = configFile.path
|
typedProfile.path = configFile.path
|
||||||
|
|
||||||
ProfileManager.create(profile)
|
// Create profile in database and select it
|
||||||
|
ProfileManager.create(profile, andSelect = true)
|
||||||
// If no profile is currently selected, select this one
|
|
||||||
if (Settings.selectedProfile == -1L) {
|
|
||||||
Settings.selectedProfile = profile.id
|
|
||||||
}
|
|
||||||
|
|
||||||
return ImportResult.Success(profile)
|
return ImportResult.Success(profile)
|
||||||
}
|
}
|
||||||
@@ -324,8 +314,8 @@ class ProfileImportHandler(private val context: Context) {
|
|||||||
configFile.writeText(jsonContent)
|
configFile.writeText(jsonContent)
|
||||||
typedProfile.path = configFile.path
|
typedProfile.path = configFile.path
|
||||||
|
|
||||||
// Create profile in database
|
// Create profile in database and select it
|
||||||
ProfileManager.create(profile)
|
ProfileManager.create(profile, andSelect = true)
|
||||||
|
|
||||||
ImportResult.Success(profile)
|
ImportResult.Success(profile)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -47,8 +47,11 @@ object ProfileManager {
|
|||||||
return instance.profileDao().get(id)
|
return instance.profileDao().get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun create(profile: Profile): Profile {
|
suspend fun create(profile: Profile, andSelect: Boolean = false): Profile {
|
||||||
profile.id = instance.profileDao().insert(profile)
|
profile.id = instance.profileDao().insert(profile)
|
||||||
|
if (andSelect) {
|
||||||
|
Settings.selectedProfile = profile.id
|
||||||
|
}
|
||||||
for (callback in callbacks.toList()) {
|
for (callback in callbacks.toList()) {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user