Merge branch 'dev' of https://github.com/nightscout/AndroidAPS into dev
This commit is contained in:
commit
22bf7120d5
|
@ -14,6 +14,7 @@ import app.aaps.core.interfaces.plugin.PluginDescription
|
||||||
import app.aaps.core.interfaces.plugin.PluginType
|
import app.aaps.core.interfaces.plugin.PluginType
|
||||||
import app.aaps.core.interfaces.pump.VirtualPump
|
import app.aaps.core.interfaces.pump.VirtualPump
|
||||||
import app.aaps.core.interfaces.resources.ResourceHelper
|
import app.aaps.core.interfaces.resources.ResourceHelper
|
||||||
|
import app.aaps.core.interfaces.sharedPreferences.SP
|
||||||
import app.aaps.core.interfaces.source.BgSource
|
import app.aaps.core.interfaces.source.BgSource
|
||||||
import app.aaps.core.interfaces.utils.T
|
import app.aaps.core.interfaces.utils.T
|
||||||
import app.aaps.core.utils.isRunningTest
|
import app.aaps.core.utils.isRunningTest
|
||||||
|
@ -40,13 +41,14 @@ class RandomBgPlugin @Inject constructor(
|
||||||
aapsLogger: AAPSLogger,
|
aapsLogger: AAPSLogger,
|
||||||
private val repository: AppRepository,
|
private val repository: AppRepository,
|
||||||
private val virtualPump: VirtualPump,
|
private val virtualPump: VirtualPump,
|
||||||
|
private val sp: SP,
|
||||||
private val config: Config
|
private val config: Config
|
||||||
) : PluginBase(
|
) : PluginBase(
|
||||||
PluginDescription()
|
PluginDescription()
|
||||||
.mainType(PluginType.BGSOURCE)
|
.mainType(PluginType.BGSOURCE)
|
||||||
.fragmentClass(BGSourceFragment::class.java.name)
|
.fragmentClass(BGSourceFragment::class.java.name)
|
||||||
.pluginIcon(R.drawable.ic_dice)
|
.pluginIcon(R.drawable.ic_dice)
|
||||||
.preferencesId(R.xml.pref_bgsource)
|
.preferencesId(R.xml.pref_randombg)
|
||||||
.pluginName(R.string.random_bg)
|
.pluginName(R.string.random_bg)
|
||||||
.shortName(R.string.random_bg_short)
|
.shortName(R.string.random_bg_short)
|
||||||
.description(R.string.description_source_random_bg),
|
.description(R.string.description_source_random_bg),
|
||||||
|
@ -56,10 +58,10 @@ class RandomBgPlugin @Inject constructor(
|
||||||
private val handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
private val handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||||
private lateinit var refreshLoop: Runnable
|
private lateinit var refreshLoop: Runnable
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
private var interval = 5L // minutes
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val interval = 5L // minutes
|
|
||||||
const val min = 70 // mgdl
|
const val min = 70 // mgdl
|
||||||
const val max = 190 // mgdl
|
const val max = 190 // mgdl
|
||||||
const val period = 120.0 // minutes
|
const val period = 120.0 // minutes
|
||||||
|
@ -67,11 +69,16 @@ class RandomBgPlugin @Inject constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
refreshLoop = Runnable {
|
refreshLoop = Runnable {
|
||||||
|
updateInterval()
|
||||||
handler.postDelayed(refreshLoop, T.mins(interval).msecs())
|
handler.postDelayed(refreshLoop, T.mins(interval).msecs())
|
||||||
handleNewData()
|
handleNewData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateInterval() {
|
||||||
|
interval = sp.getInt("randombg_interval_min", 5).toLong()
|
||||||
|
}
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
override fun advancedFilteringSupported(): Boolean = true
|
override fun advancedFilteringSupported(): Boolean = true
|
||||||
|
@ -79,11 +86,12 @@ class RandomBgPlugin @Inject constructor(
|
||||||
@SuppressLint("WakelockTimeout")
|
@SuppressLint("WakelockTimeout")
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
updateInterval()
|
||||||
val cal = GregorianCalendar()
|
val cal = GregorianCalendar()
|
||||||
cal[Calendar.MILLISECOND] = 0
|
cal[Calendar.MILLISECOND] = 0
|
||||||
cal[Calendar.SECOND] = 0
|
cal[Calendar.SECOND] = 0
|
||||||
cal[Calendar.MINUTE] -= cal[Calendar.MINUTE] % 5
|
cal[Calendar.MINUTE] -= cal[Calendar.MINUTE] % interval.toInt()
|
||||||
handler.postAtTime(refreshLoop, SystemClock.uptimeMillis() + cal.timeInMillis + T.mins(5).msecs() + 1000 - System.currentTimeMillis())
|
handler.postAtTime(refreshLoop, SystemClock.uptimeMillis() + cal.timeInMillis + T.mins(interval).msecs() + 1000 - System.currentTimeMillis())
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS:RandomBgPlugin")
|
wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS:RandomBgPlugin")
|
||||||
wakeLock?.acquire()
|
wakeLock?.acquire()
|
||||||
|
@ -108,7 +116,7 @@ class RandomBgPlugin @Inject constructor(
|
||||||
|
|
||||||
cal[Calendar.MILLISECOND] = 0
|
cal[Calendar.MILLISECOND] = 0
|
||||||
cal[Calendar.SECOND] = 0
|
cal[Calendar.SECOND] = 0
|
||||||
cal[Calendar.MINUTE] -= cal[Calendar.MINUTE] % 5
|
cal[Calendar.MINUTE] -= cal[Calendar.MINUTE] % interval.toInt()
|
||||||
val glucoseValues = mutableListOf<TransactionGlucoseValue>()
|
val glucoseValues = mutableListOf<TransactionGlucoseValue>()
|
||||||
glucoseValues += TransactionGlucoseValue(
|
glucoseValues += TransactionGlucoseValue(
|
||||||
timestamp = cal.timeInMillis,
|
timestamp = cal.timeInMillis,
|
||||||
|
|
23
plugins/source/src/main/res/xml/pref_randombg.xml
Normal file
23
plugins/source/src/main/res/xml/pref_randombg.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="randombg_settings"
|
||||||
|
app:initialExpandedChildrenCount="0"
|
||||||
|
android:title="Random BG">
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="@string/key_do_ns_upload"
|
||||||
|
android:title="@string/do_ns_upload_title" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="5"
|
||||||
|
android:digits="0123456789"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:key="randombg_interval_min"
|
||||||
|
android:title="BG generation interval minutes" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
</PreferenceScreen>
|
Loading…
Reference in a new issue