Unify OpenAPS fragments
This commit is contained in:
parent
bfb0e1f6a1
commit
b0016b0221
6 changed files with 120 additions and 229 deletions
|
@ -3,15 +3,39 @@ package info.nightscout.androidaps.di
|
|||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.activities.MyPreferenceFragment
|
||||
import info.nightscout.androidaps.dialogs.*
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsBolusCarbsFragment
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsCareportalFragment
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsExtendedBolusesFragment
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsProfileSwitchFragment
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTempTargetFragment
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTemporaryBasalsFragment
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsUserEntryFragment
|
||||
import info.nightscout.androidaps.dialogs.CalibrationDialog
|
||||
import info.nightscout.androidaps.dialogs.CarbsDialog
|
||||
import info.nightscout.androidaps.dialogs.CareDialog
|
||||
import info.nightscout.androidaps.dialogs.ExtendedBolusDialog
|
||||
import info.nightscout.androidaps.dialogs.FillDialog
|
||||
import info.nightscout.androidaps.dialogs.InsulinDialog
|
||||
import info.nightscout.androidaps.dialogs.LoopDialog
|
||||
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
||||
import info.nightscout.androidaps.dialogs.TempBasalDialog
|
||||
import info.nightscout.androidaps.dialogs.TempTargetDialog
|
||||
import info.nightscout.androidaps.dialogs.TreatmentDialog
|
||||
import info.nightscout.androidaps.dialogs.WizardDialog
|
||||
import info.nightscout.androidaps.dialogs.WizardInfoDialog
|
||||
import info.nightscout.androidaps.plugins.aps.OpenAPSFragment
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopFragment
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAFragment
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog
|
||||
import info.nightscout.androidaps.plugins.general.actions.ActionsFragment
|
||||
import info.nightscout.androidaps.plugins.general.automation.AutomationFragment
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseActionDialog
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseOperationDialog
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditTriggerDialog
|
||||
import info.nightscout.androidaps.plugins.general.autotune.AutotuneFragment
|
||||
import info.nightscout.androidaps.plugins.general.food.FoodFragment
|
||||
import info.nightscout.androidaps.plugins.general.maintenance.MaintenanceFragment
|
||||
|
@ -25,8 +49,6 @@ import info.nightscout.androidaps.plugins.insulin.InsulinFragment
|
|||
import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment
|
||||
import info.nightscout.androidaps.plugins.source.BGSourceFragment
|
||||
import info.nightscout.androidaps.activities.fragments.*
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.*
|
||||
import info.nightscout.androidaps.utils.protection.PasswordCheck
|
||||
|
||||
@Module
|
||||
|
@ -46,8 +68,7 @@ abstract class FragmentsModule {
|
|||
@ContributesAndroidInjector abstract fun contributesInsulinFragment(): InsulinFragment
|
||||
@ContributesAndroidInjector abstract fun contributesLocalProfileFragment(): LocalProfileFragment
|
||||
@ContributesAndroidInjector abstract fun contributesObjectivesFragment(): ObjectivesFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSFragment(): OpenAPSFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOverviewFragment(): OverviewFragment
|
||||
@ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment
|
||||
@ContributesAndroidInjector abstract fun contributesMaintenanceFragment(): MaintenanceFragment
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.aps.openAPSSMB
|
||||
package info.nightscout.androidaps.plugins.aps
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
|
@ -15,7 +14,7 @@ import androidx.core.view.MenuProvider
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding
|
||||
import info.nightscout.androidaps.databinding.OpenapsFragmentBinding
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
|
@ -33,7 +32,7 @@ import org.json.JSONArray
|
|||
import org.json.JSONException
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
||||
class OpenAPSFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -49,7 +48,7 @@ class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
|||
@Suppress("PrivatePropertyName")
|
||||
private val ID_MENU_RUN = 503
|
||||
|
||||
private var _binding: OpenapsamaFragmentBinding? = null
|
||||
private var _binding: OpenapsFragmentBinding? = null
|
||||
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
|
@ -57,7 +56,7 @@ class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
|||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
OpenapsamaFragmentBinding.inflate(inflater, container, false).also {
|
||||
OpenapsFragmentBinding.inflate(inflater, container, false).also {
|
||||
_binding = it
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
@ -65,12 +64,10 @@ class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
with(binding.swipeRefresh) {
|
||||
setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
|
||||
setOnRefreshListener {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
handler.post { activePlugin.activeAPS.invoke("OpenAPSSMB swipe refresh", false) }
|
||||
}
|
||||
binding.swipeRefresh.setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
|
||||
binding.swipeRefresh.setOnRefreshListener {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
handler.post { activePlugin.activeAPS.invoke("OpenAPS swipe refresh", false) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +80,7 @@ class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
|||
when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
handler.post { activePlugin.activeAPS.invoke("OpenAPSSMB menu", false) }
|
||||
handler.post { activePlugin.activeAPS.invoke("OpenAPS menu", false) }
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -93,6 +90,7 @@ class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
|||
@Synchronized
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
|
@ -123,36 +121,36 @@ class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
|||
}
|
||||
|
||||
@Synchronized
|
||||
fun updateGUI() {
|
||||
private fun updateGUI() {
|
||||
if (_binding == null) return
|
||||
val openAPSSMBPlugin = activePlugin.activeAPS
|
||||
openAPSSMBPlugin.lastAPSResult?.let { lastAPSResult ->
|
||||
val openAPSPlugin = activePlugin.activeAPS
|
||||
openAPSPlugin.lastAPSResult?.let { lastAPSResult ->
|
||||
binding.result.text = jsonFormatter.format(lastAPSResult.json)
|
||||
binding.request.text = lastAPSResult.toSpanned()
|
||||
}
|
||||
openAPSSMBPlugin.lastDetermineBasalAdapter?.let { determineBasalAdapterSMBJS ->
|
||||
binding.glucosestatus.text = jsonFormatter.format(determineBasalAdapterSMBJS.glucoseStatusParam)
|
||||
binding.currenttemp.text = jsonFormatter.format(determineBasalAdapterSMBJS.currentTempParam)
|
||||
openAPSPlugin.lastDetermineBasalAdapter?.let { determineBasalAdapter ->
|
||||
binding.glucosestatus.text = jsonFormatter.format(determineBasalAdapter.glucoseStatusParam)
|
||||
binding.currenttemp.text = jsonFormatter.format(determineBasalAdapter.currentTempParam)
|
||||
try {
|
||||
val iobArray = JSONArray(determineBasalAdapterSMBJS.iobDataParam)
|
||||
val iobArray = JSONArray(determineBasalAdapter.iobDataParam)
|
||||
binding.iobdata.text = TextUtils.concat(rh.gs(R.string.array_of_elements, iobArray.length()) + "\n", jsonFormatter.format(iobArray.getString(0)))
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e)
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Suppress("SetTextI18n")
|
||||
binding.iobdata.text = "JSONException see log for details"
|
||||
}
|
||||
|
||||
binding.profile.text = jsonFormatter.format(determineBasalAdapterSMBJS.profileParam)
|
||||
binding.mealdata.text = jsonFormatter.format(determineBasalAdapterSMBJS.mealDataParam)
|
||||
binding.scriptdebugdata.text = determineBasalAdapterSMBJS.scriptDebug.replace("\\s+".toRegex(), " ")
|
||||
openAPSSMBPlugin.lastAPSResult?.inputConstraints?.let {
|
||||
binding.profile.text = jsonFormatter.format(determineBasalAdapter.profileParam)
|
||||
binding.mealdata.text = jsonFormatter.format(determineBasalAdapter.mealDataParam)
|
||||
binding.scriptdebugdata.text = determineBasalAdapter.scriptDebug.replace("\\s+".toRegex(), " ")
|
||||
openAPSPlugin.lastAPSResult?.inputConstraints?.let {
|
||||
binding.constraints.text = it.getReasons(aapsLogger)
|
||||
}
|
||||
}
|
||||
if (openAPSSMBPlugin.lastAPSRun != 0L) {
|
||||
binding.lastrun.text = dateUtil.dateAndTimeString(openAPSSMBPlugin.lastAPSRun)
|
||||
if (openAPSPlugin.lastAPSRun != 0L) {
|
||||
binding.lastrun.text = dateUtil.dateAndTimeString(openAPSPlugin.lastAPSRun)
|
||||
}
|
||||
openAPSSMBPlugin.lastAutosensResult.let {
|
||||
openAPSPlugin.lastAutosensResult.let {
|
||||
binding.autosensdata.text = jsonFormatter.format(it.json())
|
||||
}
|
||||
binding.swipeRefresh.isRefreshing = false
|
|
@ -1,170 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.aps.openAPSAMA
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.JSONFormatter
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSAMAFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var rh: ResourceHelper
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
@Inject lateinit var jsonFormatter: JSONFormatter
|
||||
|
||||
@Suppress("PrivatePropertyName")
|
||||
private val ID_MENU_RUN = 502
|
||||
|
||||
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||
private var _binding: OpenapsamaFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
OpenapsamaFragmentBinding.inflate(inflater, container, false).also {
|
||||
_binding = it
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
with(binding.swipeRefresh) {
|
||||
setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
|
||||
setOnRefreshListener {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
handler.post { openAPSAMAPlugin.invoke("OpenAPSAMA swipe refresh", false) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
handler.post { openAPSAMAPlugin.invoke("OpenAPSAMA menu", false) }
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, fabricPrivacy::logException)
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun updateGUI() {
|
||||
if (_binding == null) return
|
||||
openAPSAMAPlugin.lastAPSResult?.let { lastAPSResult ->
|
||||
binding.result.text = jsonFormatter.format(lastAPSResult.json)
|
||||
binding.request.text = lastAPSResult.toSpanned()
|
||||
}
|
||||
openAPSAMAPlugin.lastDetermineBasalAdapter?.let { determineBasalAdapterAMAJS ->
|
||||
binding.glucosestatus.text = jsonFormatter.format(determineBasalAdapterAMAJS.glucoseStatusParam)
|
||||
binding.currenttemp.text = jsonFormatter.format(determineBasalAdapterAMAJS.currentTempParam)
|
||||
try {
|
||||
val iobArray = JSONArray(determineBasalAdapterAMAJS.iobDataParam)
|
||||
binding.iobdata.text = TextUtils.concat(rh.gs(R.string.array_of_elements, iobArray.length()) + "\n", jsonFormatter.format(iobArray.getString(0)))
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e)
|
||||
@Suppress("SetTextI18n")
|
||||
binding.iobdata.text = "JSONException see log for details"
|
||||
}
|
||||
|
||||
binding.profile.text = jsonFormatter.format(determineBasalAdapterAMAJS.profileParam)
|
||||
binding.mealdata.text = jsonFormatter.format(determineBasalAdapterAMAJS.mealDataParam)
|
||||
binding.scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug.replace("\\s+".toRegex(), " ")
|
||||
}
|
||||
if (openAPSAMAPlugin.lastAPSRun != 0L) {
|
||||
binding.lastrun.text = dateUtil.dateAndTimeString(openAPSAMAPlugin.lastAPSRun)
|
||||
}
|
||||
openAPSAMAPlugin.lastAutosensResult.let {
|
||||
binding.autosensdata.text = jsonFormatter.format(it.json())
|
||||
}
|
||||
binding.swipeRefresh.isRefreshing = false
|
||||
}
|
||||
|
||||
private fun updateResultGUI(text: String) {
|
||||
binding.result.text = text
|
||||
binding.glucosestatus.text = ""
|
||||
binding.currenttemp.text = ""
|
||||
binding.iobdata.text = ""
|
||||
binding.profile.text = ""
|
||||
binding.mealdata.text = ""
|
||||
binding.autosensdata.text = ""
|
||||
binding.scriptdebugdata.text = ""
|
||||
binding.request.text = ""
|
||||
binding.lastrun.text = ""
|
||||
binding.swipeRefresh.isRefreshing = false
|
||||
}
|
||||
}
|
|
@ -4,12 +4,21 @@ import android.content.Context
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.annotations.OpenForTesting
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.extensions.target
|
||||
import info.nightscout.androidaps.interfaces.APS
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.interfaces.DetermineBasalAdapterInterface
|
||||
import info.nightscout.androidaps.interfaces.IobCobCalculator
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.OpenAPSFragment
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader
|
||||
|
@ -22,8 +31,8 @@ import info.nightscout.androidaps.utils.FabricPrivacy
|
|||
import info.nightscout.androidaps.utils.HardLimits
|
||||
import info.nightscout.androidaps.utils.Profiler
|
||||
import info.nightscout.androidaps.utils.Round
|
||||
import info.nightscout.androidaps.extensions.target
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import org.json.JSONException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -46,14 +55,15 @@ class OpenAPSAMAPlugin @Inject constructor(
|
|||
private val dateUtil: DateUtil,
|
||||
private val repository: AppRepository,
|
||||
private val glucoseStatusProvider: GlucoseStatusProvider
|
||||
) : PluginBase(PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSAMAFragment::class.java.name)
|
||||
.pluginIcon(R.drawable.ic_generic_icon)
|
||||
.pluginName(R.string.openapsama)
|
||||
.shortName(R.string.oaps_shortname)
|
||||
.preferencesId(R.xml.pref_openapsama)
|
||||
.description(R.string.description_ama),
|
||||
) : PluginBase(
|
||||
PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSFragment::class.java.name)
|
||||
.pluginIcon(R.drawable.ic_generic_icon)
|
||||
.pluginName(R.string.openapsama)
|
||||
.shortName(R.string.oaps_shortname)
|
||||
.preferencesId(R.xml.pref_openapsama)
|
||||
.description(R.string.description_ama),
|
||||
aapsLogger, rh, injector
|
||||
), APS {
|
||||
|
||||
|
@ -115,15 +125,34 @@ class OpenAPSAMAPlugin @Inject constructor(
|
|||
inputConstraints.copyReasons(maxIOBAllowedConstraint)
|
||||
}.value()
|
||||
var minBg = hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetLowMgdl(), 0.1), R.string.profile_low_target, HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1])
|
||||
var maxBg = hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetHighMgdl(), 0.1), R.string.profile_high_target, HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1])
|
||||
var maxBg =
|
||||
hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetHighMgdl(), 0.1), R.string.profile_high_target, HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1])
|
||||
var targetBg = hardLimits.verifyHardLimits(profile.getTargetMgdl(), R.string.temp_target_value, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1])
|
||||
var isTempTarget = false
|
||||
val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()
|
||||
if (tempTarget is ValueWrapper.Existing) {
|
||||
isTempTarget = true
|
||||
minBg = hardLimits.verifyHardLimits(tempTarget.value.lowTarget, R.string.temp_target_low_target, HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1].toDouble())
|
||||
maxBg = hardLimits.verifyHardLimits(tempTarget.value.highTarget, R.string.temp_target_high_target, HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1].toDouble())
|
||||
targetBg = hardLimits.verifyHardLimits(tempTarget.value.target(), R.string.temp_target_value, HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[1].toDouble())
|
||||
minBg =
|
||||
hardLimits.verifyHardLimits(
|
||||
tempTarget.value.lowTarget,
|
||||
R.string.temp_target_low_target,
|
||||
HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0].toDouble(),
|
||||
HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1].toDouble()
|
||||
)
|
||||
maxBg =
|
||||
hardLimits.verifyHardLimits(
|
||||
tempTarget.value.highTarget,
|
||||
R.string.temp_target_high_target,
|
||||
HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0].toDouble(),
|
||||
HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1].toDouble()
|
||||
)
|
||||
targetBg =
|
||||
hardLimits.verifyHardLimits(
|
||||
tempTarget.value.target(),
|
||||
R.string.temp_target_value,
|
||||
HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[0].toDouble(),
|
||||
HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[1].toDouble()
|
||||
)
|
||||
}
|
||||
if (!hardLimits.checkHardLimits(profile.dia, R.string.profile_dia, hardLimits.minDia(), hardLimits.maxDia())) return
|
||||
if (!hardLimits.checkHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), R.string.profile_carbs_ratio_value, hardLimits.minIC(), hardLimits.maxIC())) return
|
||||
|
@ -145,7 +174,8 @@ class OpenAPSAMAPlugin @Inject constructor(
|
|||
profiler.log(LTag.APS, "AMA data gathering", start)
|
||||
start = System.currentTimeMillis()
|
||||
try {
|
||||
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, activePlugin.activePump.baseBasalRate, iobArray, glucoseStatus, mealData,
|
||||
determineBasalAdapterAMAJS.setData(
|
||||
profile, maxIob, maxBasal, minBg, maxBg, targetBg, activePlugin.activePump.baseBasalRate, iobArray, glucoseStatus, mealData,
|
||||
lastAutosensResult.ratio,
|
||||
isTempTarget
|
||||
)
|
||||
|
@ -162,7 +192,8 @@ class OpenAPSAMAPlugin @Inject constructor(
|
|||
lastAPSResult = null
|
||||
lastAPSRun = 0
|
||||
} else {
|
||||
if (determineBasalResultAMA.rate == 0.0 && determineBasalResultAMA.duration == 0 && iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now()) == null) determineBasalResultAMA.tempBasalRequested = false
|
||||
if (determineBasalResultAMA.rate == 0.0 && determineBasalResultAMA.duration == 0 && iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now()) == null) determineBasalResultAMA.tempBasalRequested =
|
||||
false
|
||||
determineBasalResultAMA.iob = iobArray[0]
|
||||
val now = System.currentTimeMillis()
|
||||
determineBasalResultAMA.json?.put("timestamp", dateUtil.toISOString(now))
|
||||
|
|
|
@ -9,7 +9,19 @@ import info.nightscout.androidaps.annotations.OpenForTesting
|
|||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.extensions.target
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.interfaces.APS
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.interfaces.Constraints
|
||||
import info.nightscout.androidaps.interfaces.DetermineBasalAdapterInterface
|
||||
import info.nightscout.androidaps.interfaces.IobCobCalculator
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.OpenAPSFragment
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader
|
||||
|
@ -21,7 +33,6 @@ import info.nightscout.androidaps.utils.DateUtil
|
|||
import info.nightscout.androidaps.utils.HardLimits
|
||||
import info.nightscout.androidaps.utils.Profiler
|
||||
import info.nightscout.androidaps.utils.Round
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -49,7 +60,7 @@ class OpenAPSSMBPlugin @Inject constructor(
|
|||
) : PluginBase(
|
||||
PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSSMBFragment::class.java.name)
|
||||
.fragmentClass(OpenAPSFragment::class.java.name)
|
||||
.pluginIcon(R.drawable.ic_generic_icon)
|
||||
.pluginName(R.string.openapssmb)
|
||||
.shortName(R.string.smb_shortname)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
android:id="@+id/swipeRefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".plugins.aps.openAPSAMA.OpenAPSAMAFragment">
|
||||
tools:context=".plugins.aps.OpenAPSFragment">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
Loading…
Reference in a new issue