Merge remote-tracking branch 'origin/dagger3c' into dagger3
This commit is contained in:
commit
6752cbae94
|
@ -129,14 +129,14 @@ public class MainApp extends DaggerApplication {
|
|||
@Inject
|
||||
ConfigBuilderPlugin configBuilderPlugin;
|
||||
|
||||
@Inject
|
||||
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
|
||||
@Inject
|
||||
InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin;
|
||||
@Inject
|
||||
InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
|
||||
@Inject
|
||||
SmsCommunicatorPlugin smsCommunicatorPlugin;
|
||||
@Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
|
||||
@Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin;
|
||||
@Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
|
||||
@Inject SafetyPlugin safetyPlugin;
|
||||
@Inject SmsCommunicatorPlugin smsCommunicatorPlugin;
|
||||
@Inject OpenAPSMAPlugin openAPSMAPlugin;
|
||||
@Inject OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||
@Inject OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -211,13 +211,13 @@ public class MainApp extends DaggerApplication {
|
|||
pluginsList.add(VirtualPumpPlugin.getPlugin());
|
||||
pluginsList.add(CareportalPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(openAPSMAPlugin);
|
||||
if (Config.APS) pluginsList.add(openAPSAMAPlugin);
|
||||
if (Config.APS) pluginsList.add(openAPSSMBPlugin);
|
||||
pluginsList.add(NSProfilePlugin.getPlugin());
|
||||
if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.INSTANCE);
|
||||
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.APS) pluginsList.add(StorageConstraintPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(SignatureVerifierPlugin.getPlugin());
|
||||
|
|
|
@ -50,9 +50,21 @@ public class MyPreferenceFragment extends PreferenceFragment implements HasAndro
|
|||
@Inject
|
||||
DispatchingAndroidInjector<Object> androidInjector;
|
||||
|
||||
@Inject
|
||||
OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||
|
||||
@Inject
|
||||
OpenAPSMAPlugin openAPSMAPlugin;
|
||||
|
||||
@Inject
|
||||
OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
|
||||
@Inject
|
||||
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
|
||||
|
||||
@Inject
|
||||
SafetyPlugin safetyPlugin;
|
||||
|
||||
@Inject
|
||||
SmsCommunicatorPlugin smsCommunicatorPlugin;
|
||||
|
||||
|
@ -97,12 +109,12 @@ public class MyPreferenceFragment extends PreferenceFragment implements HasAndro
|
|||
|
||||
addPreferencesFromResourceIfEnabled(SourceDexcomPlugin.INSTANCE, PluginType.BGSOURCE);
|
||||
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginType.GENERAL);
|
||||
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginType.CONSTRAINTS);
|
||||
addPreferencesFromResourceIfEnabled(safetyPlugin, PluginType.CONSTRAINTS);
|
||||
if (Config.APS) {
|
||||
addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginType.LOOP);
|
||||
addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginType.APS);
|
||||
addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginType.APS);
|
||||
addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginType.APS);
|
||||
addPreferencesFromResourceIfEnabled(openAPSMAPlugin, PluginType.APS);
|
||||
addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, PluginType.APS);
|
||||
addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, PluginType.APS);
|
||||
}
|
||||
|
||||
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY);
|
||||
|
|
|
@ -5,6 +5,7 @@ import dagger.Component
|
|||
import dagger.android.AndroidInjectionModule
|
||||
import dagger.android.AndroidInjector
|
||||
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.queue.commands.CommandSetProfile
|
||||
import info.nightscout.androidaps.services.DataService
|
||||
|
@ -27,6 +28,8 @@ interface AppComponent : AndroidInjector<MainApp> {
|
|||
|
||||
fun injectActionSendSMS(actionSendSMS: ActionSendSMS)
|
||||
|
||||
fun injectObjective5(objective5: Objective5)
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import info.nightscout.androidaps.logging.AAPSLoggerProduction
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
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.queue.commands.CommandSetProfile
|
||||
import info.nightscout.androidaps.services.DataService
|
||||
|
@ -72,6 +73,9 @@ class AppModule {
|
|||
@ContributesAndroidInjector
|
||||
fun bindActionSendSMS(): ActionSendSMS
|
||||
|
||||
@ContributesAndroidInjector
|
||||
fun bindObjective5(): Objective5
|
||||
|
||||
@Binds
|
||||
fun bindContext(mainApp: MainApp): Context
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import dagger.Module
|
|||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.activities.MyPreferenceFragment
|
||||
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
|
||||
|
||||
@Module
|
||||
|
@ -12,6 +15,15 @@ abstract class FragmentsModule {
|
|||
@ContributesAndroidInjector
|
||||
abstract fun contributesPreferencesFragment(): MyPreferenceFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesOpenAPSMAFragment(): OpenAPSMAFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.text.TextUtils
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.L
|
||||
|
@ -22,11 +22,15 @@ import kotlinx.android.synthetic.main.openapsama_fragment.*
|
|||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSAMAFragment : Fragment() {
|
||||
class OpenAPSAMAFragment : DaggerFragment() {
|
||||
private val log = LoggerFactory.getLogger(L.APS)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.openapsama_fragment, container, false)
|
||||
|
@ -36,7 +40,7 @@ class OpenAPSAMAFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
openapsma_run.setOnClickListener {
|
||||
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false)
|
||||
openAPSAMAPlugin.invoke("OpenAPSAMA button", false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,21 +49,21 @@ class OpenAPSAMAFragment : Fragment() {
|
|||
super.onResume()
|
||||
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
@ -73,11 +77,11 @@ class OpenAPSAMAFragment : Fragment() {
|
|||
@Synchronized
|
||||
private fun updateGUI() {
|
||||
if (openapsma_result == null) return
|
||||
OpenAPSAMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
|
||||
openAPSAMAPlugin.lastAPSResult?.let { lastAPSResult ->
|
||||
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
|
||||
openapsma_request.text = lastAPSResult.toSpanned()
|
||||
}
|
||||
OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS?.let { determineBasalAdapterAMAJS ->
|
||||
openAPSAMAPlugin.lastDetermineBasalAdapterAMAJS?.let { determineBasalAdapterAMAJS ->
|
||||
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterAMAJS.glucoseStatusParam)
|
||||
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterAMAJS.currentTempParam)
|
||||
try {
|
||||
|
@ -92,10 +96,10 @@ class OpenAPSAMAFragment : Fragment() {
|
|||
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterAMAJS.mealDataParam)
|
||||
openapsma_scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug
|
||||
}
|
||||
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != 0L) {
|
||||
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(OpenAPSAMAPlugin.getPlugin().lastAPSRun)
|
||||
if (openAPSAMAPlugin.lastAPSRun != 0L) {
|
||||
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(openAPSAMAPlugin.lastAPSRun)
|
||||
}
|
||||
OpenAPSAMAPlugin.getPlugin().lastAutosensResult?.let {
|
||||
openAPSAMAPlugin.lastAutosensResult?.let {
|
||||
openapsma_autosensdata.text = JSONFormatter.format(it.json())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import org.json.JSONException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
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.Round;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
@Singleton
|
||||
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||
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
|
||||
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
||||
long lastAPSRun = 0;
|
||||
DetermineBasalResultAMA lastAPSResult = null;
|
||||
AutosensResult lastAutosensResult = null;
|
||||
|
||||
private OpenAPSAMAPlugin() {
|
||||
@Inject
|
||||
public OpenAPSAMAPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSAMAFragment.class.getName())
|
||||
|
|
|
@ -4,7 +4,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.L
|
||||
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 kotlinx.android.synthetic.main.openapsama_fragment.*
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSMAFragment : Fragment() {
|
||||
class OpenAPSMAFragment : DaggerFragment() {
|
||||
private val log = LoggerFactory.getLogger(L.APS)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
lateinit var openAPSMAPlugin: OpenAPSMAPlugin
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.openapsma_fragment, container, false)
|
||||
|
@ -32,7 +36,7 @@ class OpenAPSMAFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
openapsma_run.setOnClickListener {
|
||||
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false)
|
||||
openAPSMAPlugin.invoke("OpenAPSMA button", false)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,21 +46,21 @@ class OpenAPSMAFragment : Fragment() {
|
|||
super.onResume()
|
||||
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
|
@ -69,19 +73,19 @@ class OpenAPSMAFragment : Fragment() {
|
|||
@Synchronized
|
||||
private fun updateGUI() {
|
||||
if (openapsma_result == null) return
|
||||
OpenAPSMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
|
||||
openAPSMAPlugin.lastAPSResult?.let { lastAPSResult ->
|
||||
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
|
||||
openapsma_request.text = lastAPSResult.toSpanned()
|
||||
}
|
||||
OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS?.let { determineBasalAdapterMAJS ->
|
||||
openAPSMAPlugin.lastDetermineBasalAdapterMAJS?.let { determineBasalAdapterMAJS ->
|
||||
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterMAJS.glucoseStatusParam)
|
||||
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterMAJS.currentTempParam)
|
||||
openapsma_iobdata.text = JSONFormatter.format(determineBasalAdapterMAJS.iobDataParam)
|
||||
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterMAJS.profileParam)
|
||||
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterMAJS.mealDataParam)
|
||||
}
|
||||
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != 0L) {
|
||||
openapsma_lastrun.text = DateUtil.dateAndTimeString(OpenAPSMAPlugin.getPlugin().lastAPSRun)
|
||||
if (openAPSMAPlugin.lastAPSRun != 0L) {
|
||||
openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSMAPlugin.lastAPSRun)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@ import org.json.JSONException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
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.verifyHardLimits;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
@Singleton
|
||||
public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||
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
|
||||
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
|
||||
long lastAPSRun = 0;
|
||||
DetermineBasalResultMA lastAPSResult = null;
|
||||
|
||||
private OpenAPSMAPlugin() {
|
||||
@Inject
|
||||
public OpenAPSMAPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSMAFragment.class.getName())
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.text.TextUtils
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.L
|
||||
|
@ -23,11 +23,15 @@ import kotlinx.android.synthetic.main.openapsama_fragment.*
|
|||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSSMBFragment : Fragment() {
|
||||
class OpenAPSSMBFragment : DaggerFragment() {
|
||||
private val log = LoggerFactory.getLogger(L.APS)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.openapsama_fragment, container, false)
|
||||
|
@ -37,7 +41,7 @@ class OpenAPSSMBFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
openapsma_run.setOnClickListener {
|
||||
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false)
|
||||
openAPSSMBPlugin.invoke("OpenAPSSMB button", false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,21 +49,21 @@ class OpenAPSSMBFragment : Fragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateGUI()
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateResultGUI(it.text)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
@ -73,12 +77,11 @@ class OpenAPSSMBFragment : Fragment() {
|
|||
@Synchronized
|
||||
fun updateGUI() {
|
||||
if (openapsma_result == null) return
|
||||
val plugin = OpenAPSSMBPlugin.getPlugin()
|
||||
plugin.lastAPSResult?.let { lastAPSResult ->
|
||||
openAPSSMBPlugin.lastAPSResult?.let { lastAPSResult ->
|
||||
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
|
||||
openapsma_request.text = lastAPSResult.toSpanned()
|
||||
}
|
||||
plugin.lastDetermineBasalAdapterSMBJS?.let { determineBasalAdapterSMBJS ->
|
||||
openAPSSMBPlugin.lastDetermineBasalAdapterSMBJS?.let { determineBasalAdapterSMBJS ->
|
||||
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterSMBJS.glucoseStatusParam)
|
||||
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterSMBJS.currentTempParam)
|
||||
try {
|
||||
|
@ -93,14 +96,14 @@ class OpenAPSSMBFragment : Fragment() {
|
|||
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterSMBJS.profileParam)
|
||||
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterSMBJS.mealDataParam)
|
||||
openapsma_scriptdebugdata.text = determineBasalAdapterSMBJS.scriptDebug
|
||||
plugin.lastAPSResult?.inputConstraints?.let {
|
||||
openAPSSMBPlugin.lastAPSResult?.inputConstraints?.let {
|
||||
openapsma_constraints.text = it.reasons
|
||||
}
|
||||
}
|
||||
if (plugin.lastAPSRun != 0L) {
|
||||
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(plugin.lastAPSRun)
|
||||
if (openAPSSMBPlugin.lastAPSRun != 0L) {
|
||||
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(openAPSSMBPlugin.lastAPSRun)
|
||||
}
|
||||
plugin.lastAutosensResult?.let {
|
||||
openAPSSMBPlugin.lastAutosensResult?.let {
|
||||
openapsma_autosensdata.text = JSONFormatter.format(it.json())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ import org.json.JSONException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
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.ToastUtils;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
@Singleton
|
||||
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
|
||||
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
|
||||
public static OpenAPSSMBPlugin getPlugin() {
|
||||
if (openAPSSMBPlugin == null) {
|
||||
openAPSSMBPlugin = new OpenAPSSMBPlugin();
|
||||
}
|
||||
/**
|
||||
* @deprecated Use dagger to get an instance
|
||||
*/
|
||||
@Deprecated
|
||||
static public OpenAPSSMBPlugin getPlugin() {
|
||||
if (openAPSSMBPlugin == null)
|
||||
throw new IllegalStateException("Accessing OpenAPSSMBPlugin before first instantiation");
|
||||
return openAPSSMBPlugin;
|
||||
}
|
||||
|
||||
|
@ -61,7 +65,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
DetermineBasalResultSMB lastAPSResult = null;
|
||||
AutosensResult lastAutosensResult = null;
|
||||
|
||||
private OpenAPSSMBPlugin() {
|
||||
@Inject
|
||||
public OpenAPSSMBPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSSMBFragment.class.getName())
|
||||
|
@ -70,6 +75,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
.preferencesId(R.xml.pref_openapssmb)
|
||||
.description(R.string.description_smb)
|
||||
);
|
||||
this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,9 @@ package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
|
||||
|
@ -9,8 +12,12 @@ import info.nightscout.androidaps.utils.T;
|
|||
|
||||
public class Objective5 extends Objective {
|
||||
|
||||
@Inject
|
||||
SafetyPlugin safetyPlugin;
|
||||
|
||||
public Objective5() {
|
||||
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
|
||||
|
@ -20,7 +27,7 @@ public class Objective5 extends Objective {
|
|||
@Override
|
||||
public boolean isCompleted() {
|
||||
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
|
||||
SafetyPlugin.getPlugin().isClosedLoopAllowed(closedLoopEnabled);
|
||||
safetyPlugin.isClosedLoopAllowed(closedLoopEnabled);
|
||||
return closedLoopEnabled.value();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.safety;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
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.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
@Singleton
|
||||
public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||
|
||||
static SafetyPlugin plugin = null;
|
||||
@Inject
|
||||
OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||
|
||||
public static SafetyPlugin getPlugin() {
|
||||
if (plugin == null)
|
||||
plugin = new SafetyPlugin();
|
||||
return plugin;
|
||||
}
|
||||
@Inject
|
||||
OpenAPSMAPlugin openAPSMAPlugin;
|
||||
|
||||
@Inject
|
||||
OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
|
||||
@Inject
|
||||
public SafetyPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.CONSTRAINTS)
|
||||
|
@ -236,17 +239,17 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
|||
@Override
|
||||
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
||||
double maxIobPref;
|
||||
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS))
|
||||
if (openAPSSMBPlugin.isEnabled(PluginType.APS))
|
||||
maxIobPref = SP.getDouble(R.string.key_openapssmb_max_iob, 3d);
|
||||
else
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
return maxIob;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue