activate correct profile

This commit is contained in:
Milos Kozak 2020-06-22 22:19:27 +02:00
parent 500de5fa2d
commit 6a1394b7b9
2 changed files with 14 additions and 4 deletions
app/src/main/java/info/nightscout/androidaps

View file

@ -28,6 +28,8 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var treatmentsPlugin: TreatmentsPlugin
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
var profileIndex: Int? = null
override fun onSaveInstanceState(savedInstanceState: Bundle) { override fun onSaveInstanceState(savedInstanceState: Bundle) {
super.onSaveInstanceState(savedInstanceState) super.onSaveInstanceState(savedInstanceState)
savedInstanceState.putDouble("overview_profileswitch_duration", overview_profileswitch_duration.value) savedInstanceState.putDouble("overview_profileswitch_duration", overview_profileswitch_duration.value)
@ -38,6 +40,9 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
onCreateViewGeneral() onCreateViewGeneral()
arguments?.let { bundle ->
profileIndex = bundle.getInt("profileIndex", 0)
}
return inflater.inflate(R.layout.dialog_profileswitch, container, false) return inflater.inflate(R.layout.dialog_profileswitch, container, false)
} }
@ -59,9 +64,12 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList) val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
overview_profileswitch_profile.adapter = adapter overview_profileswitch_profile.adapter = adapter
// set selected to actual profile // set selected to actual profile
for (p in profileList.indices) if (profileIndex != null)
if (profileList[p] == profileFunction.getProfileName(false)) overview_profileswitch_profile.setSelection(profileIndex as Int)
overview_profileswitch_profile.setSelection(p) else
for (p in profileList.indices)
if (profileList[p] == profileFunction.getProfileName(false))
overview_profileswitch_profile.setSelection(p)
} ?: return } ?: return
treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now())?.let { ps -> treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now())?.let { ps ->

View file

@ -181,7 +181,9 @@ class LocalProfileFragment : DaggerFragment() {
localprofile_profileswitch.setOnClickListener { localprofile_profileswitch.setOnClickListener {
// TODO: select in dialog localProfilePlugin.currentProfileIndex // TODO: select in dialog localProfilePlugin.currentProfileIndex
ProfileSwitchDialog().show(childFragmentManager, "NewNSTreatmentDialog") ProfileSwitchDialog()
.also { it.arguments = Bundle().also { bundle -> bundle.putInt("profileIndex", localProfilePlugin.currentProfileIndex) }}
.show(childFragmentManager, "NewNSTreatmentDialog")
} }
localprofile_reset.setOnClickListener { localprofile_reset.setOnClickListener {