exclude invalid profiles from ProfileSwitchDialog
This commit is contained in:
parent
b177af4ad7
commit
760261e258
1 changed files with 21 additions and 9 deletions
|
@ -38,6 +38,7 @@ import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ProfileSwitchDialog : DialogFragmentWithDate() {
|
class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@ -113,7 +114,17 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
context?.let { context ->
|
context?.let { context ->
|
||||||
val profileStore = activePlugin.activeProfileSource.profile
|
val profileStore = activePlugin.activeProfileSource.profile
|
||||||
?: return
|
?: return
|
||||||
val profileList = profileStore.getProfileList()
|
val profileListToCheck = profileStore.getProfileList()
|
||||||
|
val profileList = ArrayList<CharSequence>()
|
||||||
|
for (profileName in profileListToCheck) {
|
||||||
|
val profileToCheck = activePlugin.activeProfileSource.profile?.getSpecificProfile(profileName.toString())
|
||||||
|
if (profileToCheck != null && ProfileSealed.Pure(profileToCheck).isValid("ProfileSwitch", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false).isValid)
|
||||||
|
profileList.add(profileName)
|
||||||
|
}
|
||||||
|
if (profileList.isEmpty()) {
|
||||||
|
dismiss()
|
||||||
|
return
|
||||||
|
}
|
||||||
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
||||||
binding.profile.adapter = adapter
|
binding.profile.adapter = adapter
|
||||||
// set selected to actual profile
|
// set selected to actual profile
|
||||||
|
@ -123,7 +134,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
for (p in profileList.indices)
|
for (p in profileList.indices)
|
||||||
if (profileList[p] == profileFunction.getOriginalProfileName())
|
if (profileList[p] == profileFunction.getOriginalProfileName())
|
||||||
binding.profile.setSelection(p)
|
binding.profile.setSelection(p)
|
||||||
} ?: return
|
}
|
||||||
|
|
||||||
profileFunction.getProfile()?.let { profile ->
|
profileFunction.getProfile()?.let { profile ->
|
||||||
if (profile is ProfileSealed.EPS)
|
if (profile is ProfileSealed.EPS)
|
||||||
|
@ -189,7 +200,8 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
percentage = percent,
|
percentage = percent,
|
||||||
timeShiftInHours = timeShift,
|
timeShiftInHours = timeShift,
|
||||||
timestamp = eventTime
|
timestamp = eventTime
|
||||||
)) {
|
)
|
||||||
|
) {
|
||||||
uel.log(Action.PROFILE_SWITCH,
|
uel.log(Action.PROFILE_SWITCH,
|
||||||
Sources.ProfileSwitchDialog,
|
Sources.ProfileSwitchDialog,
|
||||||
notes,
|
notes,
|
||||||
|
|
Loading…
Reference in a new issue