Merge branch 'dev' of https://github.com/nightscout/AndroidAPS into avereha/merge-dev-11

This commit is contained in:
Andrei Vereha 2021-10-05 22:56:41 +02:00
commit 4a3cff1688
16 changed files with 214 additions and 8 deletions

View file

@ -109,7 +109,7 @@ android {
defaultConfig { defaultConfig {
multiDexEnabled true multiDexEnabled true
versionCode 1500 versionCode 1500
version "2.8.2.3-dev" version "2.8.2.5-dev"
buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.dialogs package info.nightscout.androidaps.dialogs
import android.os.Bundle import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -10,22 +12,30 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.androidaps.databinding.DialogProfileswitchBinding import info.nightscout.androidaps.databinding.DialogProfileswitchBinding
import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import java.text.DecimalFormat import java.text.DecimalFormat
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
class ProfileSwitchDialog : DialogFragmentWithDate() { class ProfileSwitchDialog : DialogFragmentWithDate() {
@ -38,6 +48,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var hardLimits: HardLimits @Inject lateinit var hardLimits: HardLimits
@Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var defaultValueHelper: DefaultValueHelper
private var profileIndex: Int? = null private var profileIndex: Int? = null
@ -49,6 +60,17 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
// onDestroyView. // onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
private val textWatcher: TextWatcher = object : TextWatcher {
override fun afterTextChanged(s: Editable) {
val isDuration = binding.duration.value > 0
val isLowerPercentage = binding.percentage.value < 100
binding.ttLayout.visibility = (isDuration && isLowerPercentage).toVisibility()
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
}
override fun onSaveInstanceState(savedInstanceState: Bundle) { override fun onSaveInstanceState(savedInstanceState: Bundle) {
super.onSaveInstanceState(savedInstanceState) super.onSaveInstanceState(savedInstanceState)
savedInstanceState.putDouble("duration", binding.duration.value) savedInstanceState.putDouble("duration", binding.duration.value)
@ -70,9 +92,11 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.duration.setParams(savedInstanceState?.getDouble("duration") binding.duration.setParams(savedInstanceState?.getDouble("duration")
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok) ?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok,
textWatcher)
binding.percentage.setParams(savedInstanceState?.getDouble("percentage") binding.percentage.setParams(savedInstanceState?.getDouble("percentage")
?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0, DecimalFormat("0"), false, binding.okcancel.ok) ?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0,
DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
binding.timeshift.setParams(savedInstanceState?.getDouble("timeshift") binding.timeshift.setParams(savedInstanceState?.getDouble("timeshift")
?: 0.0, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok) ?: 0.0, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok)
@ -104,6 +128,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
binding.reuselayout.visibility = View.GONE binding.reuselayout.visibility = View.GONE
} }
} }
binding.ttLayout.visibility = View.GONE
} }
override fun onDestroyView() { override fun onDestroyView() {
@ -135,6 +160,12 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
if (eventTimeChanged) if (eventTimeChanged)
actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime)) actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(eventTime))
val isTT = binding.duration.value > 0 && binding.percentage.value < 100 && binding.tt.isChecked
val target = defaultValueHelper.determineActivityTT()
val units = profileFunction.getUnits()
if (isTT)
actions.add(resourceHelper.gs(R.string.careportal_temporarytarget) + ": " + resourceHelper.gs(R.string.activity))
activity?.let { activity -> activity?.let { activity ->
val ps = profileFunction.buildProfileSwitch(profileStore, profileName, duration, percent, timeShift, eventTime) val ps = profileFunction.buildProfileSwitch(profileStore, profileName, duration, percent, timeShift, eventTime)
val validity = ProfileSealed.PS(ps).isValid(resourceHelper.gs(R.string.careportal_profileswitch), activePlugin.activePump, config, resourceHelper, rxBus, hardLimits) val validity = ProfileSealed.PS(ps).isValid(resourceHelper.gs(R.string.careportal_profileswitch), activePlugin.activePump, config, resourceHelper, rxBus, hardLimits)
@ -154,6 +185,24 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
ValueWithUnit.Percent(percent), ValueWithUnit.Percent(percent),
ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 }, ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 },
ValueWithUnit.Minute(duration).takeIf { duration != 0 }) ValueWithUnit.Minute(duration).takeIf { duration != 0 })
if (isTT) {
disposable += repository.runTransactionForResult(
InsertAndCancelCurrentTemporaryTargetTransaction(
timestamp = eventTime,
duration = TimeUnit.MINUTES.toMillis(duration.toLong()),
reason = TemporaryTarget.Reason.ACTIVITY,
lowTarget = Profile.toMgdl(target, profileFunction.getUnits()),
highTarget = Profile.toMgdl(target, profileFunction.getUnits())
)
).subscribe({ result ->
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
}, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
})
uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
TemporaryTarget.Reason.ACTIVITY), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration))
}
}) })
else { else {
OKDialog.show( OKDialog.show(

View file

@ -166,6 +166,9 @@ class PluginStore @Inject constructor(
override val activeOverview: Overview override val activeOverview: Overview
get() = getSpecificPluginsListByInterface(Overview::class.java).first() as Overview get() = getSpecificPluginsListByInterface(Overview::class.java).first() as Overview
override val activeSafety: Safety
get() = getSpecificPluginsListByInterface(Safety::class.java).first() as Safety
override fun getPluginsList(): ArrayList<PluginBase> = ArrayList(plugins) override fun getPluginsList(): ArrayList<PluginBase> = ArrayList(plugins)
} }

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.constraints.safety
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.extensions.*
import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -20,6 +21,7 @@ import info.nightscout.androidaps.utils.Round
import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.math.floor import kotlin.math.floor
@ -49,7 +51,7 @@ class SafetyPlugin @Inject constructor(
.pluginName(R.string.safety) .pluginName(R.string.safety)
.preferencesId(R.xml.pref_safety), .preferencesId(R.xml.pref_safety),
aapsLogger, resourceHelper, injector aapsLogger, resourceHelper, injector
), Constraints { ), Constraints, Safety {
/** /**
* Constraints interface * Constraints interface
@ -193,4 +195,16 @@ class SafetyPlugin @Inject constructor(
if (apsMode == "lgs") maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.MAX_IOB_LGS, resourceHelper.gs(R.string.lowglucosesuspend)), this) if (apsMode == "lgs") maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.MAX_IOB_LGS, resourceHelper.gs(R.string.lowglucosesuspend)), this)
return maxIob return maxIob
} }
override fun configuration(): JSONObject =
JSONObject()
.putString(R.string.key_age, sp, resourceHelper)
.putDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper)
.putDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper)
override fun applyConfiguration(configuration: JSONObject) {
configuration.storeString(R.string.key_age, sp, resourceHelper)
configuration.storeDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper)
configuration.storeDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper)
}
} }

View file

@ -176,6 +176,7 @@ class OverviewPlugin @Inject constructor(
override fun configuration(): JSONObject = override fun configuration(): JSONObject =
JSONObject() JSONObject()
.putInt(R.string.key_units, sp, resourceHelper)
.putString(R.string.key_quickwizard, sp, resourceHelper) .putString(R.string.key_quickwizard, sp, resourceHelper)
.putInt(R.string.key_eatingsoon_duration, sp, resourceHelper) .putInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
.putDouble(R.string.key_eatingsoon_target, sp, resourceHelper) .putDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
@ -202,6 +203,7 @@ class OverviewPlugin @Inject constructor(
override fun applyConfiguration(configuration: JSONObject) { override fun applyConfiguration(configuration: JSONObject) {
configuration configuration
.storeInt(R.string.key_units, sp, resourceHelper)
.storeString(R.string.key_quickwizard, sp, resourceHelper) .storeString(R.string.key_quickwizard, sp, resourceHelper)
.storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper) .storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
.storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper) .storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper)

View file

@ -210,6 +210,33 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/tt_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="120dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/careportal_temporarytarget"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="bold" />
<CheckBox
android:id="@+id/tt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/activity" />
</LinearLayout>
<include <include
android:id="@+id/notes_layout" android:id="@+id/notes_layout"
layout="@layout/notes" /> layout="@layout/notes" />

View file

@ -0,0 +1,20 @@
package info.nightscout.androidaps.plugins.constraints.versionChecker
import org.junit.Assert.*
import org.junit.Test
class AllowedVersionsTest {
@Test
fun generateSupportedVersionsTest() {
val definition = AllowedVersions().generateSupportedVersions()
assertNull(AllowedVersions().findByApi(definition, 0))
assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true)
assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true)
assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported"))
assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported"))
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported"))
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported"))
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported"))
}
}

View file

@ -46,6 +46,12 @@ interface ActivePlugin {
*/ */
val activeOverview: Overview val activeOverview: Overview
/**
* Currently selected Safety plugin
* Always SafetyPlugin
*/
val activeSafety: Safety
/** /**
* List of all registered plugins * List of all registered plugins
*/ */

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.interfaces
interface Safety : ConfigExportImport

View file

@ -36,12 +36,14 @@ class RunningConfiguration @Inject constructor(
val sensitivityInterface = activePlugin.activeSensitivity val sensitivityInterface = activePlugin.activeSensitivity
val pumpInterface = activePlugin.activePump val pumpInterface = activePlugin.activePump
val overviewInterface = activePlugin.activeOverview val overviewInterface = activePlugin.activeOverview
val safetyInterface = activePlugin.activeSafety
json.put("insulin", insulinInterface.id.value) json.put("insulin", insulinInterface.id.value)
json.put("insulinConfiguration", insulinInterface.configuration()) json.put("insulinConfiguration", insulinInterface.configuration())
json.put("sensitivity", sensitivityInterface.id.value) json.put("sensitivity", sensitivityInterface.id.value)
json.put("sensitivityConfiguration", sensitivityInterface.configuration()) json.put("sensitivityConfiguration", sensitivityInterface.configuration())
json.put("overviewConfiguration", overviewInterface.configuration()) json.put("overviewConfiguration", overviewInterface.configuration())
json.put("safetyConfiguration", safetyInterface.configuration())
json.put("pump", pumpInterface.model().description) json.put("pump", pumpInterface.model().description)
} catch (e: JSONException) { } catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e) aapsLogger.error("Unhandled exception", e)
@ -88,5 +90,8 @@ class RunningConfiguration @Inject constructor(
if (configuration.has("overviewConfiguration")) if (configuration.has("overviewConfiguration"))
activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration")) activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration"))
if (configuration.has("safetyConfiguration"))
activePlugin.activeSafety.applyConfiguration(configuration.getJSONObject("safetyConfiguration"))
} }
} }

View file

@ -0,0 +1,45 @@
package info.nightscout.androidaps.plugins.constraints.versionChecker
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
class AllowedVersions {
fun generateSupportedVersions(): String =
JSONArray()
.put(JSONObject().apply {
put("minAndroid", 1) // 1.0
put("maxAndroid", 23) // 6.0.1
})
.put(JSONObject().apply {
put("minAndroid", 24) // 7.0
put("maxAndroid", 25) // 7.1.2
put("supported", "2.6.2")
})
.put(JSONObject().apply {
put("minAndroid", 26) // 8.0
put("maxAndroid", 27) // 8.1
put("supported", "2.8.2")
})
.put(JSONObject().apply {
put("minAndroid", 28) // 9.0
put("maxAndroid", 99)
put("supported", "2.8.2")
})
.toString()
fun findByApi(definition: String?, api: Int): JSONObject? {
if (definition == null) return null
try {
val array = JSONArray(definition)
for (i in 0 until array.length()) {
val record = array[i] as JSONObject
if (api in record.getInt("minAndroid")..record.getInt("maxAndroid")) return record
}
} catch (e: JSONException) {
}
return null
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.constraints.versionChecker package info.nightscout.androidaps.plugins.constraints.versionChecker
import android.content.Context import android.content.Context
import android.os.Build
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -53,8 +54,8 @@ class VersionCheckerUtils @Inject constructor(
private fun checkVersion() = if (isConnected()) { private fun checkVersion() = if (isConnected()) {
Thread { Thread {
try { try {
val version: String? = val definition: String = URL("https://raw.githubusercontent.com/nightscout/AndroidAPS/versions/definition.json").readText()
findVersion(URL("https://raw.githubusercontent.com/nightscout/AndroidAPS/master/app/build.gradle").readText()) val version: String? = AllowedVersions().findByApi(definition, Build.VERSION.SDK_INT)?.optString("supported")
compareWithCurrentVersion(version, config.VERSION_NAME) compareWithCurrentVersion(version, config.VERSION_NAME)
} catch (e: IOException) { } catch (e: IOException) {
aapsLogger.error(LTag.CORE, "Github master version check error: $e") aapsLogger.error(LTag.CORE, "Github master version check error: $e")

View file

@ -1,7 +1,7 @@
android { android {
compileSdkVersion 30 compileSdkVersion 30
defaultConfig { defaultConfig {
minSdkVersion 26 minSdkVersion 28
targetSdkVersion 28 targetSdkVersion 28
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -178,6 +178,7 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick
getTDDItems(statusItems); getTDDItems(statusItems);
getBaseBasalRateItem(statusItems); getBaseBasalRateItem(statusItems);
getTBRItem(statusItems); getTBRItem(statusItems);
getLastBolusItem(statusItems);
getBolusItems(statusItems); getBolusItems(statusItems);
for (int i = 0; i < statusItems.size(); i++) { for (int i = 0; i < statusItems.size(); i++) {
statusItemContainer.addView(statusItems.get(i)); statusItemContainer.addView(statusItems.get(i));
@ -239,7 +240,16 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick
default: default:
long lastConnection = localInsightPlugin.getConnectionService().getLastConnected(); long lastConnection = localInsightPlugin.getConnectionService().getLastConnected();
if (lastConnection == 0) return; if (lastConnection == 0) return;
statusItems.add(getStatusItem(resourceHelper.gs(R.string.last_connected), dateUtil.timeString(lastConnection))); long agoMsc = System.currentTimeMillis() - lastConnection;
double lastConnectionMinAgo = agoMsc / 60d / 1000d;
String ago;
if (lastConnectionMinAgo < 60) {
ago = dateUtil.minAgo(resourceHelper, lastConnection);
} else {
ago = dateUtil.hourAgo(lastConnection, resourceHelper);
}
statusItems.add(getStatusItem(resourceHelper.gs(R.string.last_connected),
dateUtil.timeString(lastConnection) + " (" + ago + ")"));
} }
} }
@ -306,6 +316,21 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick
resourceHelper.gs(R.string.tbr_formatter, activeTBR.getPercentage(), activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration()))); resourceHelper.gs(R.string.tbr_formatter, activeTBR.getPercentage(), activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration())));
} }
private void getLastBolusItem(List<View> statusItems) {
if (localInsightPlugin.lastBolusAmount == 0 || localInsightPlugin.lastBolusTimestamp == 0) return;
long agoMsc = System.currentTimeMillis() - localInsightPlugin.lastBolusTimestamp;
double bolusMinAgo = agoMsc / 60d / 1000d;
String unit = resourceHelper.gs(R.string.insulin_unit_shortname);
String ago;
if (bolusMinAgo < 60) {
ago = dateUtil.minAgo(resourceHelper, localInsightPlugin.lastBolusTimestamp);
} else {
ago = dateUtil.hourAgo(localInsightPlugin.lastBolusTimestamp, resourceHelper);
}
statusItems.add(getStatusItem(resourceHelper.gs(R.string.insight_last_bolus),
resourceHelper.gs(R.string.insight_last_bolus_formater, localInsightPlugin.lastBolusAmount, unit, ago)));
}
private void getBolusItems(List<View> statusItems) { private void getBolusItems(List<View> statusItems) {
if (localInsightPlugin.getActiveBoluses() == null) return; if (localInsightPlugin.getActiveBoluses() == null) return;
for (ActiveBolus activeBolus : localInsightPlugin.getActiveBoluses()) { for (ActiveBolus activeBolus : localInsightPlugin.getActiveBoluses()) {

View file

@ -190,6 +190,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
private List<ActiveBolus> activeBoluses; private List<ActiveBolus> activeBoluses;
private boolean statusLoaded; private boolean statusLoaded;
private TBROverNotificationBlock tbrOverNotificationBlock; private TBROverNotificationBlock tbrOverNotificationBlock;
public double lastBolusAmount = 0;
public long lastBolusTimestamp = 0L;
@Inject @Inject
public LocalInsightPlugin( public LocalInsightPlugin(
@ -1439,6 +1441,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
bolusID.getId(), bolusID.getId(),
PumpType.ACCU_CHEK_INSIGHT, PumpType.ACCU_CHEK_INSIGHT,
serial); serial);
lastBolusTimestamp = bolusID.getTimestamp();
lastBolusAmount = event.getImmediateAmount();
} }
if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) { if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) {
if (event.getDuration() > 0 && profileFunction.getProfile(bolusID.getTimestamp()) != null) if (event.getDuration() > 0 && profileFunction.getProfile(bolusID.getTimestamp()) != null)

View file

@ -21,6 +21,8 @@
<string name="tbr_formatter">%1$d%% for %2$d / %3$d min</string> <string name="tbr_formatter">%1$d%% for %2$d / %3$d min</string>
<string name="multiwave_bolus">Multiwave bolus</string> <string name="multiwave_bolus">Multiwave bolus</string>
<string name="eb_formatter">%1$.2f / %2$.2f U for %3$d min</string> <string name="eb_formatter">%1$.2f / %2$.2f U for %3$d min</string>
<string name="insight_last_bolus" >Last Bolus</string>
<string name="insight_last_bolus_formater" translatable="false">%1$.1f %2$s (%3$s)</string>
<string name="searching_for_devices">Searching for devices…</string> <string name="searching_for_devices">Searching for devices…</string>
<string name="pairing_completed">Pairing completed</string> <string name="pairing_completed">Pairing completed</string>
<string name="code_compare">Do the codes displayed on this device and on your pump match?</string> <string name="code_compare">Do the codes displayed on this device and on your pump match?</string>