RandomBgPlugin injection
This commit is contained in:
parent
2f59cd4f09
commit
716053229a
2 changed files with 21 additions and 14 deletions
|
@ -146,6 +146,7 @@ public class MainApp extends DaggerApplication {
|
||||||
@Inject OpenAPSAMAPlugin openAPSAMAPlugin;
|
@Inject OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||||
@Inject OpenAPSSMBPlugin openAPSSMBPlugin;
|
@Inject OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||||
@Inject OverviewPlugin overviewPlugin;
|
@Inject OverviewPlugin overviewPlugin;
|
||||||
|
@Inject RandomBgPlugin randomBgPlugin;
|
||||||
@Inject StatusLinePlugin statusLinePlugin;
|
@Inject StatusLinePlugin statusLinePlugin;
|
||||||
@Inject TidepoolPlugin tidepoolPlugin;
|
@Inject TidepoolPlugin tidepoolPlugin;
|
||||||
@Inject TreatmentsPlugin treatmentsPlugin;
|
@Inject TreatmentsPlugin treatmentsPlugin;
|
||||||
|
@ -244,7 +245,7 @@ public class MainApp extends DaggerApplication {
|
||||||
pluginsList.add(SourcePoctechPlugin.getPlugin());
|
pluginsList.add(SourcePoctechPlugin.getPlugin());
|
||||||
pluginsList.add(SourceTomatoPlugin.getPlugin());
|
pluginsList.add(SourceTomatoPlugin.getPlugin());
|
||||||
pluginsList.add(SourceEversensePlugin.getPlugin());
|
pluginsList.add(SourceEversensePlugin.getPlugin());
|
||||||
pluginsList.add(RandomBgPlugin.INSTANCE);
|
pluginsList.add(randomBgPlugin);
|
||||||
if (!Config.NSCLIENT) pluginsList.add(smsCommunicatorPlugin);
|
if (!Config.NSCLIENT) pluginsList.add(smsCommunicatorPlugin);
|
||||||
pluginsList.add(FoodPlugin.getPlugin());
|
pluginsList.add(FoodPlugin.getPlugin());
|
||||||
|
|
||||||
|
|
|
@ -9,29 +9,35 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.isRunningTest
|
import info.nightscout.androidaps.utils.isRunningTest
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
object RandomBgPlugin : PluginBase(PluginDescription()
|
@Singleton
|
||||||
|
class RandomBgPlugin @Inject constructor(
|
||||||
|
private val aapsLogger: AAPSLogger,
|
||||||
|
private var virtualPumpPlugin: VirtualPumpPlugin
|
||||||
|
) : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.BGSOURCE)
|
.mainType(PluginType.BGSOURCE)
|
||||||
.fragmentClass(BGSourceFragment::class.java.name)
|
.fragmentClass(BGSourceFragment::class.java.name)
|
||||||
.pluginName(R.string.randombg)
|
.pluginName(R.string.randombg)
|
||||||
.shortName(R.string.randombg_short)
|
.shortName(R.string.randombg_short)
|
||||||
.description(R.string.description_source_randombg)), BgSourceInterface {
|
.description(R.string.description_source_randombg)), BgSourceInterface {
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(L.BGSOURCE)
|
|
||||||
|
|
||||||
private val loopHandler = Handler()
|
private val loopHandler = Handler()
|
||||||
private lateinit var refreshLoop: Runnable
|
private lateinit var refreshLoop: Runnable
|
||||||
|
|
||||||
|
companion object {
|
||||||
const val interval = 5L // minutes
|
const val interval = 5L // minutes
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
refreshLoop = Runnable {
|
refreshLoop = Runnable {
|
||||||
|
@ -55,7 +61,7 @@ object RandomBgPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun specialEnableCondition(): Boolean {
|
override fun specialEnableCondition(): Boolean {
|
||||||
return VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP) && (MainApp.engineeringMode || isRunningTest())
|
return virtualPumpPlugin.isEnabled(PluginType.PUMP) && (MainApp.engineeringMode || isRunningTest())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleNewData(intent: Intent) {
|
override fun handleNewData(intent: Intent) {
|
||||||
|
@ -72,6 +78,6 @@ object RandomBgPlugin : PluginBase(PluginDescription()
|
||||||
bgReading.date = DateUtil.now()
|
bgReading.date = DateUtil.now()
|
||||||
bgReading.raw = bgMgdl
|
bgReading.raw = bgMgdl
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "RandomBG")
|
MainApp.getDbHelper().createIfNotExists(bgReading, "RandomBG")
|
||||||
log.debug("Generated BG: $bgReading")
|
aapsLogger.debug(LTag.BGSOURCE, "Generated BG: $bgReading")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue