Add a setting for sensor change upload to xDrip BG source

This commit is contained in:
Jakub Kuczys 2023-12-01 18:32:36 +01:00
parent faeddef68e
commit 13f06ef110
No known key found for this signature in database
GPG key ID: 9F02686F15FCBCD3
5 changed files with 37 additions and 6 deletions

View file

@ -50,6 +50,7 @@
<string name="key_insight_local_settings" translatable="false">insight_local_settings</string>
<string name="key_data_choices_settings" translatable="false">data_choices_settings</string>
<string name="key_dexcom_settings" translatable="false">dexcom_settings</string>
<string name="key_xdrip_settings" translatable="false">xdrip_settings</string>
<string name="key_active_pump_change_timestamp" translatable="false">active_pump_change_timestamp</string>
<string name="key_active_pump_type" translatable="false">active_pump_type</string>
<string name="key_active_pump_serial_number" translatable="false">active_pump_serial_number</string>

View file

@ -11,6 +11,7 @@ import app.aaps.core.interfaces.plugin.PluginDescription
import app.aaps.core.interfaces.plugin.PluginType
import app.aaps.core.interfaces.receivers.Intents
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.XDripSource
import app.aaps.core.interfaces.utils.DateUtil
@ -41,7 +42,7 @@ class XdripSourcePlugin @Inject constructor(
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment::class.java.name)
.pluginIcon((app.aaps.core.main.R.drawable.ic_blooddrop_48))
.preferencesId(R.xml.pref_bgsource)
.preferencesId(R.xml.pref_xdrip)
.pluginName(R.string.source_xdrip)
.description(R.string.description_source_xdrip),
aapsLogger, rh, injector
@ -70,6 +71,7 @@ class XdripSourcePlugin @Inject constructor(
) : LoggingWorker(context, params, Dispatchers.IO) {
@Inject lateinit var xdripSourcePlugin: XdripSourcePlugin
@Inject lateinit var sp: SP
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var repository: AppRepository
@Inject lateinit var dataWorkerStorage: DataWorkerStorage
@ -96,7 +98,11 @@ class XdripSourcePlugin @Inject constructor(
)
)
val now = dateUtil.now()
var sensorStartTime: Long? = bundle.getLong(Intents.EXTRA_SENSOR_STARTED_AT, 0)
var sensorStartTime: Long? = if (sp.getBoolean(R.string.key_xdrip_log_ns_sensor_change, false)) {
bundle.getLong(Intents.EXTRA_SENSOR_STARTED_AT, 0)
} else {
null
}
// check start time validity
sensorStartTime?.let {
if (abs(it - now) > T.months(1).msecs() || it > now) sensorStartTime = null

View file

@ -2,6 +2,7 @@
<resources>
<!-- Source -->
<string name="key_dexcom_log_ns_sensor_change" translatable="false">dexcom_lognssensorchange</string>
<string name="key_xdrip_log_ns_sensor_change" translatable="false">xdrip_lognssensorchange</string>
<string name="key_last_processed_glunovo_timestamp" translatable="false">last_processed_glunovo_timestamp</string>
<string name="key_last_processed_intelligo_timestamp" translatable="false">last_processed_intelligo_timestamp</string>
@ -39,8 +40,8 @@
<string name="do_xdrip_upload_title">Send BG data to xDrip+</string>
<string name="do_xdrip_upload_summary">In xDrip+ select 640g/Eversense data source</string>
<string name="bgsource_upload">BG upload settings</string>
<string name="dexcom_log_ns_sensor_change_title">Log sensor change to NS</string>
<string name="dexcom_log_ns_sensor_change_summary">Create event \"Sensor Change\" in NS automatically on sensor start</string>
<string name="log_ns_sensor_change_title">Log sensor change to NS</string>
<string name="log_ns_sensor_change_summary">Create event \"Sensor Change\" in NS automatically on sensor start</string>
<string name="direction">direction</string>

View file

@ -15,8 +15,8 @@
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_dexcom_log_ns_sensor_change"
android:summary="@string/dexcom_log_ns_sensor_change_summary"
android:title="@string/dexcom_log_ns_sensor_change_title" />
android:summary="@string/log_ns_sensor_change_summary"
android:title="@string/log_ns_sensor_change_title" />
</PreferenceCategory>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="@string/key_xdrip_settings"
android:title="@string/bgsource_upload"
app:initialExpandedChildrenCount="0">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_do_ns_upload"
android:title="@string/do_ns_upload_title" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_xdrip_log_ns_sensor_change"
android:summary="@string/log_ns_sensor_change_summary"
android:title="@string/log_ns_sensor_change_title" />
</PreferenceCategory>
</androidx.preference.PreferenceScreen>