APSPlugins, SafetyPlugin -> dagger

This commit is contained in:
Milos Kozak 2019-12-28 01:14:04 +01:00
parent fca775a4e7
commit 7805fbc5db
13 changed files with 171 additions and 123 deletions

View file

@ -126,7 +126,11 @@ public class MainApp extends DaggerApplication {
@Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin; @Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
@Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin; @Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin;
@Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin; @Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
@Inject SafetyPlugin safetyPlugin;
@Inject SmsCommunicatorPlugin smsCommunicatorPlugin; @Inject SmsCommunicatorPlugin smsCommunicatorPlugin;
@Inject OpenAPSMAPlugin openAPSMAPlugin;
@Inject OpenAPSAMAPlugin openAPSAMAPlugin;
@Inject OpenAPSSMBPlugin openAPSSMBPlugin;
@Override @Override
public void onCreate() { public void onCreate() {
@ -201,13 +205,13 @@ public class MainApp extends DaggerApplication {
pluginsList.add(VirtualPumpPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin());
pluginsList.add(CareportalPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin());
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(openAPSMAPlugin);
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(openAPSAMAPlugin);
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin()); if (Config.APS) pluginsList.add(openAPSSMBPlugin);
pluginsList.add(NSProfilePlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin());
if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.INSTANCE); if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.INSTANCE);
pluginsList.add(TreatmentsPlugin.getPlugin()); pluginsList.add(TreatmentsPlugin.getPlugin());
if (!Config.NSCLIENT) pluginsList.add(SafetyPlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(safetyPlugin);
if (!Config.NSCLIENT) pluginsList.add(VersionCheckerPlugin.INSTANCE); if (!Config.NSCLIENT) pluginsList.add(VersionCheckerPlugin.INSTANCE);
if (Config.APS) pluginsList.add(StorageConstraintPlugin.getPlugin()); if (Config.APS) pluginsList.add(StorageConstraintPlugin.getPlugin());
if (Config.APS) pluginsList.add(SignatureVerifierPlugin.getPlugin()); if (Config.APS) pluginsList.add(SignatureVerifierPlugin.getPlugin());

View file

@ -50,9 +50,21 @@ public class MyPreferenceFragment extends PreferenceFragment implements HasAndro
@Inject @Inject
DispatchingAndroidInjector<Object> androidInjector; DispatchingAndroidInjector<Object> androidInjector;
@Inject
OpenAPSAMAPlugin openAPSAMAPlugin;
@Inject
OpenAPSMAPlugin openAPSMAPlugin;
@Inject
OpenAPSSMBPlugin openAPSSMBPlugin;
@Inject @Inject
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin; InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
@Inject
SafetyPlugin safetyPlugin;
@Inject @Inject
SmsCommunicatorPlugin smsCommunicatorPlugin; SmsCommunicatorPlugin smsCommunicatorPlugin;
@ -97,12 +109,12 @@ public class MyPreferenceFragment extends PreferenceFragment implements HasAndro
addPreferencesFromResourceIfEnabled(SourceDexcomPlugin.INSTANCE, PluginType.BGSOURCE); addPreferencesFromResourceIfEnabled(SourceDexcomPlugin.INSTANCE, PluginType.BGSOURCE);
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginType.GENERAL); addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginType.GENERAL);
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginType.CONSTRAINTS); addPreferencesFromResourceIfEnabled(safetyPlugin, PluginType.CONSTRAINTS);
if (Config.APS) { if (Config.APS) {
addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginType.LOOP); addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginType.LOOP);
addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginType.APS); addPreferencesFromResourceIfEnabled(openAPSMAPlugin, PluginType.APS);
addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginType.APS); addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, PluginType.APS);
addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginType.APS); addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, PluginType.APS);
} }
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY);

View file

@ -5,6 +5,7 @@ import dagger.Component
import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5
import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS
import info.nightscout.androidaps.queue.commands.CommandSetProfile import info.nightscout.androidaps.queue.commands.CommandSetProfile
import info.nightscout.androidaps.services.DataService import info.nightscout.androidaps.services.DataService
@ -27,6 +28,8 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectActionSendSMS(actionSendSMS: ActionSendSMS) fun injectActionSendSMS(actionSendSMS: ActionSendSMS)
fun injectObjective5(objective5: Objective5)
@Component.Builder @Component.Builder
interface Builder { interface Builder {

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5
import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS
import info.nightscout.androidaps.queue.commands.CommandSetProfile import info.nightscout.androidaps.queue.commands.CommandSetProfile
import info.nightscout.androidaps.services.DataService import info.nightscout.androidaps.services.DataService
@ -58,6 +59,9 @@ class AppModule {
@ContributesAndroidInjector @ContributesAndroidInjector
fun bindActionSendSMS(): ActionSendSMS fun bindActionSendSMS(): ActionSendSMS
@ContributesAndroidInjector
fun bindObjective5(): Objective5
@Binds @Binds
fun bindContext(mainApp: MainApp): Context fun bindContext(mainApp: MainApp): Context
} }

View file

@ -4,6 +4,9 @@ import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.activities.MyPreferenceFragment import info.nightscout.androidaps.activities.MyPreferenceFragment
import info.nightscout.androidaps.dialogs.* import info.nightscout.androidaps.dialogs.*
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAFragment
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAFragment
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorFragment import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorFragment
@Module @Module
@ -12,6 +15,15 @@ abstract class FragmentsModule {
@ContributesAndroidInjector @ContributesAndroidInjector
abstract fun contributesPreferencesFragment(): MyPreferenceFragment abstract fun contributesPreferencesFragment(): MyPreferenceFragment
@ContributesAndroidInjector
abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
@ContributesAndroidInjector
abstract fun contributesOpenAPSMAFragment(): OpenAPSMAFragment
@ContributesAndroidInjector
abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
@ContributesAndroidInjector @ContributesAndroidInjector
abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment

View file

@ -5,7 +5,7 @@ import android.text.TextUtils
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
@ -22,11 +22,15 @@ import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import javax.inject.Inject
class OpenAPSAMAFragment : Fragment() { class OpenAPSAMAFragment : DaggerFragment() {
private val log = LoggerFactory.getLogger(L.APS) private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@Inject
lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsama_fragment, container, false) return inflater.inflate(R.layout.openapsama_fragment, container, false)
@ -36,7 +40,7 @@ class OpenAPSAMAFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
openapsma_run.setOnClickListener { openapsma_run.setOnClickListener {
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false) openAPSAMAPlugin.invoke("OpenAPSAMA button", false)
} }
} }
@ -45,21 +49,21 @@ class OpenAPSAMAFragment : Fragment() {
super.onResume() super.onResume()
disposable += RxBus disposable += RxBus
.toObservable(EventOpenAPSUpdateGui::class.java) .toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
updateGUI() updateGUI()
}, { }, {
FabricPrivacy.logException(it) FabricPrivacy.logException(it)
}) })
disposable += RxBus disposable += RxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java) .toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
updateResultGUI(it.text) updateResultGUI(it.text)
}, { }, {
FabricPrivacy.logException(it) FabricPrivacy.logException(it)
}) })
updateGUI() updateGUI()
} }
@ -73,11 +77,11 @@ class OpenAPSAMAFragment : Fragment() {
@Synchronized @Synchronized
private fun updateGUI() { private fun updateGUI() {
if (openapsma_result == null) return if (openapsma_result == null) return
OpenAPSAMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult -> openAPSAMAPlugin.lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json) openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned() openapsma_request.text = lastAPSResult.toSpanned()
} }
OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS?.let { determineBasalAdapterAMAJS -> openAPSAMAPlugin.lastDetermineBasalAdapterAMAJS?.let { determineBasalAdapterAMAJS ->
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterAMAJS.glucoseStatusParam) openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterAMAJS.glucoseStatusParam)
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterAMAJS.currentTempParam) openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterAMAJS.currentTempParam)
try { try {
@ -92,10 +96,10 @@ class OpenAPSAMAFragment : Fragment() {
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterAMAJS.mealDataParam) openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterAMAJS.mealDataParam)
openapsma_scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug openapsma_scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug
} }
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != 0L) { if (openAPSAMAPlugin.lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(OpenAPSAMAPlugin.getPlugin().lastAPSRun) openapsma_lastrun.text = DateUtil.dateAndTimeFullString(openAPSAMAPlugin.lastAPSRun)
} }
OpenAPSAMAPlugin.getPlugin().lastAutosensResult?.let { openAPSAMAPlugin.lastAutosensResult?.let {
openapsma_autosensdata.text = JSONFormatter.format(it.json()) openapsma_autosensdata.text = JSONFormatter.format(it.json())
} }
} }

View file

@ -4,6 +4,9 @@ import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -35,28 +38,18 @@ import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.Profiler; import info.nightscout.androidaps.utils.Profiler;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
/** @Singleton
* Created by mike on 05.08.2016.
*/
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(L.APS); private static Logger log = LoggerFactory.getLogger(L.APS);
private static OpenAPSAMAPlugin openAPSAMAPlugin;
public static OpenAPSAMAPlugin getPlugin() {
if (openAPSAMAPlugin == null) {
openAPSAMAPlugin = new OpenAPSAMAPlugin();
}
return openAPSAMAPlugin;
}
// last values // last values
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null; DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
long lastAPSRun = 0; long lastAPSRun = 0;
DetermineBasalResultAMA lastAPSResult = null; DetermineBasalResultAMA lastAPSResult = null;
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
private OpenAPSAMAPlugin() { @Inject
public OpenAPSAMAPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSAMAFragment.class.getName()) .fragmentClass(OpenAPSAMAFragment.class.getName())

View file

@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
@ -18,11 +18,15 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.openapsama_fragment.* import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import javax.inject.Inject
class OpenAPSMAFragment : Fragment() { class OpenAPSMAFragment : DaggerFragment() {
private val log = LoggerFactory.getLogger(L.APS) private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@Inject
lateinit var openAPSMAPlugin: OpenAPSMAPlugin
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsma_fragment, container, false) return inflater.inflate(R.layout.openapsma_fragment, container, false)
@ -32,7 +36,7 @@ class OpenAPSMAFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
openapsma_run.setOnClickListener { openapsma_run.setOnClickListener {
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false) openAPSMAPlugin.invoke("OpenAPSMA button", false)
} }
} }
@ -42,21 +46,21 @@ class OpenAPSMAFragment : Fragment() {
super.onResume() super.onResume()
disposable += RxBus disposable += RxBus
.toObservable(EventOpenAPSUpdateGui::class.java) .toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
updateGUI() updateGUI()
}, { }, {
FabricPrivacy.logException(it) FabricPrivacy.logException(it)
}) })
disposable += RxBus disposable += RxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java) .toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
updateResultGUI(it.text) updateResultGUI(it.text)
}, { }, {
FabricPrivacy.logException(it) FabricPrivacy.logException(it)
}) })
updateGUI() updateGUI()
} }
@ -69,19 +73,19 @@ class OpenAPSMAFragment : Fragment() {
@Synchronized @Synchronized
private fun updateGUI() { private fun updateGUI() {
if (openapsma_result == null) return if (openapsma_result == null) return
OpenAPSMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult -> openAPSMAPlugin.lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json) openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned() openapsma_request.text = lastAPSResult.toSpanned()
} }
OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS?.let { determineBasalAdapterMAJS -> openAPSMAPlugin.lastDetermineBasalAdapterMAJS?.let { determineBasalAdapterMAJS ->
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterMAJS.glucoseStatusParam) openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterMAJS.glucoseStatusParam)
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterMAJS.currentTempParam) openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterMAJS.currentTempParam)
openapsma_iobdata.text = JSONFormatter.format(determineBasalAdapterMAJS.iobDataParam) openapsma_iobdata.text = JSONFormatter.format(determineBasalAdapterMAJS.iobDataParam)
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterMAJS.profileParam) openapsma_profile.text = JSONFormatter.format(determineBasalAdapterMAJS.profileParam)
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterMAJS.mealDataParam) openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterMAJS.mealDataParam)
} }
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != 0L) { if (openAPSMAPlugin.lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeString(OpenAPSMAPlugin.getPlugin().lastAPSRun) openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSMAPlugin.lastAPSRun)
} }
} }

View file

@ -4,6 +4,9 @@ import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
@ -35,27 +38,17 @@ import info.nightscout.androidaps.utils.Round;
import static info.nightscout.androidaps.utils.HardLimits.checkOnlyHardLimits; import static info.nightscout.androidaps.utils.HardLimits.checkOnlyHardLimits;
import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits; import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
/** @Singleton
* Created by mike on 05.08.2016.
*/
public class OpenAPSMAPlugin extends PluginBase implements APSInterface { public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(L.APS); private static Logger log = LoggerFactory.getLogger(L.APS);
private static OpenAPSMAPlugin openAPSMAPlugin;
public static OpenAPSMAPlugin getPlugin() {
if (openAPSMAPlugin == null) {
openAPSMAPlugin = new OpenAPSMAPlugin();
}
return openAPSMAPlugin;
}
// last values // last values
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null; DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
long lastAPSRun = 0; long lastAPSRun = 0;
DetermineBasalResultMA lastAPSResult = null; DetermineBasalResultMA lastAPSResult = null;
private OpenAPSMAPlugin() { @Inject
public OpenAPSMAPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSMAFragment.class.getName()) .fragmentClass(OpenAPSMAFragment.class.getName())

View file

@ -6,7 +6,7 @@ import android.text.TextUtils
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
@ -23,11 +23,15 @@ import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import javax.inject.Inject
class OpenAPSSMBFragment : Fragment() { class OpenAPSSMBFragment : DaggerFragment() {
private val log = LoggerFactory.getLogger(L.APS) private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@Inject
lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsama_fragment, container, false) return inflater.inflate(R.layout.openapsama_fragment, container, false)
@ -37,7 +41,7 @@ class OpenAPSSMBFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
openapsma_run.setOnClickListener { openapsma_run.setOnClickListener {
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false) openAPSSMBPlugin.invoke("OpenAPSSMB button", false)
} }
} }
@ -45,21 +49,21 @@ class OpenAPSSMBFragment : Fragment() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
disposable += RxBus disposable += RxBus
.toObservable(EventOpenAPSUpdateGui::class.java) .toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
updateGUI() updateGUI()
}, { }, {
FabricPrivacy.logException(it) FabricPrivacy.logException(it)
}) })
disposable += RxBus disposable += RxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java) .toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
updateResultGUI(it.text) updateResultGUI(it.text)
}, { }, {
FabricPrivacy.logException(it) FabricPrivacy.logException(it)
}) })
updateGUI() updateGUI()
} }
@ -73,12 +77,11 @@ class OpenAPSSMBFragment : Fragment() {
@Synchronized @Synchronized
fun updateGUI() { fun updateGUI() {
if (openapsma_result == null) return if (openapsma_result == null) return
val plugin = OpenAPSSMBPlugin.getPlugin() openAPSSMBPlugin.lastAPSResult?.let { lastAPSResult ->
plugin.lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json) openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned() openapsma_request.text = lastAPSResult.toSpanned()
} }
plugin.lastDetermineBasalAdapterSMBJS?.let { determineBasalAdapterSMBJS -> openAPSSMBPlugin.lastDetermineBasalAdapterSMBJS?.let { determineBasalAdapterSMBJS ->
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterSMBJS.glucoseStatusParam) openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterSMBJS.glucoseStatusParam)
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterSMBJS.currentTempParam) openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterSMBJS.currentTempParam)
try { try {
@ -93,14 +96,14 @@ class OpenAPSSMBFragment : Fragment() {
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterSMBJS.profileParam) openapsma_profile.text = JSONFormatter.format(determineBasalAdapterSMBJS.profileParam)
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterSMBJS.mealDataParam) openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterSMBJS.mealDataParam)
openapsma_scriptdebugdata.text = determineBasalAdapterSMBJS.scriptDebug openapsma_scriptdebugdata.text = determineBasalAdapterSMBJS.scriptDebug
plugin.lastAPSResult?.inputConstraints?.let { openAPSSMBPlugin.lastAPSResult?.inputConstraints?.let {
openapsma_constraints.text = it.reasons openapsma_constraints.text = it.reasons
} }
} }
if (plugin.lastAPSRun != 0L) { if (openAPSSMBPlugin.lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(plugin.lastAPSRun) openapsma_lastrun.text = DateUtil.dateAndTimeFullString(openAPSSMBPlugin.lastAPSRun)
} }
plugin.lastAutosensResult?.let { openAPSSMBPlugin.lastAutosensResult?.let {
openapsma_autosensdata.text = JSONFormatter.format(it.json()) openapsma_autosensdata.text = JSONFormatter.format(it.json())
} }
} }

View file

@ -5,6 +5,9 @@ import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
@ -40,18 +43,19 @@ import info.nightscout.androidaps.utils.Profiler;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.ToastUtils; import info.nightscout.androidaps.utils.ToastUtils;
/** @Singleton
* Created by mike on 05.08.2016.
*/
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface { public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(L.APS); private static Logger log = LoggerFactory.getLogger(L.APS);
private static OpenAPSSMBPlugin openAPSSMBPlugin; private static OpenAPSSMBPlugin openAPSSMBPlugin;
public static OpenAPSSMBPlugin getPlugin() { /**
if (openAPSSMBPlugin == null) { * @deprecated Use dagger to get an instance
openAPSSMBPlugin = new OpenAPSSMBPlugin(); */
} @Deprecated
static public OpenAPSSMBPlugin getPlugin() {
if (openAPSSMBPlugin == null)
throw new IllegalStateException("Accessing OpenAPSSMBPlugin before first instantiation");
return openAPSSMBPlugin; return openAPSSMBPlugin;
} }
@ -61,7 +65,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
DetermineBasalResultSMB lastAPSResult = null; DetermineBasalResultSMB lastAPSResult = null;
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
private OpenAPSSMBPlugin() { @Inject
public OpenAPSSMBPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSSMBFragment.class.getName()) .fragmentClass(OpenAPSSMBFragment.class.getName())
@ -70,6 +75,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
.preferencesId(R.xml.pref_openapssmb) .preferencesId(R.xml.pref_openapssmb)
.description(R.string.description_smb) .description(R.string.description_smb)
); );
this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger
} }
@Override @Override

View file

@ -2,6 +2,9 @@ package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
@ -9,8 +12,12 @@ import info.nightscout.androidaps.utils.T;
public class Objective5 extends Objective { public class Objective5 extends Objective {
@Inject
SafetyPlugin safetyPlugin;
public Objective5() { public Objective5() {
super("maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate); super("maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate);
MainApp.instance().androidInjector().inject(this); // TODO inject or pass itno constructor once AutomationPlugin is prepared for Dagger
} }
@Override @Override
@ -20,7 +27,7 @@ public class Objective5 extends Objective {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true); Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
SafetyPlugin.getPlugin().isClosedLoopAllowed(closedLoopEnabled); safetyPlugin.isClosedLoopAllowed(closedLoopEnabled);
return closedLoopEnabled.value(); return closedLoopEnabled.value();
} }
}); });

View file

@ -1,5 +1,8 @@
package info.nightscout.androidaps.plugins.constraints.safety; package info.nightscout.androidaps.plugins.constraints.safety;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -26,19 +29,19 @@ import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
/** @Singleton
* Created by mike on 05.08.2016.
*/
public class SafetyPlugin extends PluginBase implements ConstraintsInterface { public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
static SafetyPlugin plugin = null; @Inject
OpenAPSAMAPlugin openAPSAMAPlugin;
public static SafetyPlugin getPlugin() { @Inject
if (plugin == null) OpenAPSMAPlugin openAPSMAPlugin;
plugin = new SafetyPlugin();
return plugin;
}
@Inject
OpenAPSSMBPlugin openAPSSMBPlugin;
@Inject
public SafetyPlugin() { public SafetyPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
@ -236,17 +239,17 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@Override @Override
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) { public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
double maxIobPref; double maxIobPref;
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) if (openAPSSMBPlugin.isEnabled(PluginType.APS))
maxIobPref = SP.getDouble(R.string.key_openapssmb_max_iob, 3d); maxIobPref = SP.getDouble(R.string.key_openapssmb_max_iob, 3d);
else else
maxIobPref = SP.getDouble(R.string.key_openapsma_max_iob, 1.5d); maxIobPref = SP.getDouble(R.string.key_openapsma_max_iob, 1.5d);
maxIob.setIfSmaller(maxIobPref, String.format(MainApp.gs(R.string.limitingiob), maxIobPref, MainApp.gs(R.string.maxvalueinpreferences)), this); maxIob.setIfSmaller(maxIobPref, String.format(MainApp.gs(R.string.limitingiob), maxIobPref, MainApp.gs(R.string.maxvalueinpreferences)), this);
if (OpenAPSMAPlugin.getPlugin().isEnabled(PluginType.APS)) if (openAPSMAPlugin.isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this); maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this);
if (OpenAPSAMAPlugin.getPlugin().isEnabled(PluginType.APS)) if (openAPSAMAPlugin.isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this); maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this);
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) if (openAPSSMBPlugin.isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobSMB(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobSMB(), MainApp.gs(R.string.hardlimit)), this); maxIob.setIfSmaller(HardLimits.maxIobSMB(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobSMB(), MainApp.gs(R.string.hardlimit)), this);
return maxIob; return maxIob;
} }