Merge pull request #1651 from osodebailar/feature/cardview_for_nsclient_overview

Feature cardview for nsclient overview
This commit is contained in:
Milos Kozak 2022-04-19 22:43:30 +02:00 committed by GitHub
commit 8a1c112218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 15 deletions

View file

@ -4,8 +4,6 @@ import android.text.Spanned
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.aps.loop.APSResult import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
@ -14,6 +12,8 @@ import info.nightscout.androidaps.utils.JsonHelper
import info.nightscout.androidaps.utils.Round import info.nightscout.androidaps.utils.Round
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
@ -88,7 +88,7 @@ class NSDeviceStatus @Inject constructor(
fun handleNewData(deviceStatuses: JSONArray) { fun handleNewData(deviceStatuses: JSONArray) {
aapsLogger.debug(LTag.NSCLIENT, "Got NS deviceStatus: \$deviceStatuses") aapsLogger.debug(LTag.NSCLIENT, "Got NS deviceStatus: \$deviceStatuses")
try { try {
for (i in deviceStatuses.length() -1 downTo 0) { for (i in deviceStatuses.length() - 1 downTo 0) {
val devicestatusJson = deviceStatuses.getJSONObject(i) val devicestatusJson = deviceStatuses.getJSONObject(i)
if (devicestatusJson != null) { if (devicestatusJson != null) {
setData(devicestatusJson) setData(devicestatusJson)
@ -157,7 +157,7 @@ class NSDeviceStatus @Inject constructor(
//String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"}; //String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"};
val string = StringBuilder() val string = StringBuilder()
.append("<span style=\"color:${rh.gcs(R.color.defaultText)}\">") .append("<span style=\"color:${rh.gac(R.attr.nsTitleColor)}\">")
.append(rh.gs(R.string.pump)) .append(rh.gs(R.string.pump))
.append(": </span>") .append(": </span>")
@ -165,13 +165,13 @@ class NSDeviceStatus @Inject constructor(
val level = when { val level = when {
pumpData.clock + nsSettingsStatus.extendedPumpSettings("urgentClock") * 60 * 1000L < dateUtil.now() -> Levels.URGENT pumpData.clock + nsSettingsStatus.extendedPumpSettings("urgentClock") * 60 * 1000L < dateUtil.now() -> Levels.URGENT
pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("urgentRes") -> Levels.URGENT pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("urgentRes") -> Levels.URGENT
pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("urgentBattP") -> Levels.URGENT pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("urgentBattP") -> Levels.URGENT
!pumpData.isPercent && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("urgentBattV") -> Levels.URGENT !pumpData.isPercent && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("urgentBattV") -> Levels.URGENT
pumpData.clock + nsSettingsStatus.extendedPumpSettings("warnClock") * 60 * 1000L < dateUtil.now() -> Levels.WARN pumpData.clock + nsSettingsStatus.extendedPumpSettings("warnClock") * 60 * 1000L < dateUtil.now() -> Levels.WARN
pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("warnRes") -> Levels.WARN pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("warnRes") -> Levels.WARN
pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("warnBattP") -> Levels.WARN pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("warnBattP") -> Levels.WARN
!pumpData.isPercent && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("warnBattV") -> Levels.WARN !pumpData.isPercent && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("warnBattV") -> Levels.WARN
else -> Levels.INFO else -> Levels.INFO
} }
string.append("<span style=\"color:${level.toColor()}\">") string.append("<span style=\"color:${level.toColor()}\">")
val fields = nsSettingsStatus.pumpExtendedSettingsFields() val fields = nsSettingsStatus.pumpExtendedSettingsFields()
@ -248,7 +248,7 @@ class NSDeviceStatus @Inject constructor(
val openApsStatus: Spanned val openApsStatus: Spanned
get() { get() {
val string = StringBuilder() val string = StringBuilder()
.append("<span style=\"color:${rh.gcs(R.color.defaultText)}\">") .append("<span style=\"color:${rh.gac(R.attr.nsTitleColor)}\">")
.append(rh.gs(R.string.openaps_short)) .append(rh.gs(R.string.openaps_short))
.append(": </span>") .append(": </span>")
@ -256,7 +256,7 @@ class NSDeviceStatus @Inject constructor(
val level = when { val level = when {
deviceStatusData.openAPSData.clockSuggested + T.mins(sp.getLong(R.string.key_nsalarm_urgent_staledatavalue, 31)).msecs() < dateUtil.now() -> Levels.URGENT deviceStatusData.openAPSData.clockSuggested + T.mins(sp.getLong(R.string.key_nsalarm_urgent_staledatavalue, 31)).msecs() < dateUtil.now() -> Levels.URGENT
deviceStatusData.openAPSData.clockSuggested + T.mins(sp.getLong(R.string.key_nsalarm_staledatavalue, 16)).msecs() < dateUtil.now() -> Levels.WARN deviceStatusData.openAPSData.clockSuggested + T.mins(sp.getLong(R.string.key_nsalarm_staledatavalue, 16)).msecs() < dateUtil.now() -> Levels.WARN
else -> Levels.INFO else -> Levels.INFO
} }
string.append("<span style=\"color:${level.toColor()}\">") string.append("<span style=\"color:${level.toColor()}\">")
if (deviceStatusData.openAPSData.clockSuggested != 0L) string.append(dateUtil.minAgo(rh, deviceStatusData.openAPSData.clockSuggested)).append(" ") if (deviceStatusData.openAPSData.clockSuggested != 0L) string.append(dateUtil.minAgo(rh, deviceStatusData.openAPSData.clockSuggested)).append(" ")
@ -268,8 +268,10 @@ class NSDeviceStatus @Inject constructor(
get() { get() {
val string = StringBuilder() val string = StringBuilder()
try { try {
if (deviceStatusData.openAPSData.enacted != null && deviceStatusData.openAPSData.clockEnacted != deviceStatusData.openAPSData.clockSuggested) string.append("<b>").append(dateUtil.minAgo(rh, deviceStatusData.openAPSData.clockEnacted)).append("</b> ").append(deviceStatusData.openAPSData.enacted!!.getString("reason")).append("<br>") if (deviceStatusData.openAPSData.enacted != null && deviceStatusData.openAPSData.clockEnacted != deviceStatusData.openAPSData.clockSuggested) string.append("<b>")
if (deviceStatusData.openAPSData.suggested != null) string.append("<b>").append(dateUtil.minAgo(rh, deviceStatusData.openAPSData.clockSuggested)).append("</b> ").append(deviceStatusData.openAPSData.suggested!!.getString("reason")).append("<br>") .append(dateUtil.minAgo(rh, deviceStatusData.openAPSData.clockEnacted)).append("</b> ").append(deviceStatusData.openAPSData.enacted!!.getString("reason")).append("<br>")
if (deviceStatusData.openAPSData.suggested != null) string.append("<b>").append(dateUtil.minAgo(rh, deviceStatusData.openAPSData.clockSuggested)).append("</b> ")
.append(deviceStatusData.openAPSData.suggested!!.getString("reason")).append("<br>")
return fromHtml(string.toString()) return fromHtml(string.toString())
} catch (e: JSONException) { } catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e) aapsLogger.error("Unhandled exception", e)
@ -321,7 +323,7 @@ class NSDeviceStatus @Inject constructor(
val uploaderStatusSpanned: Spanned val uploaderStatusSpanned: Spanned
get() { get() {
val string = StringBuilder() val string = StringBuilder()
string.append("<span style=\"color:${rh.gcs(R.color.defaultText)}\">") string.append("<span style=\"color:${rh.gac(R.attr.nsTitleColor)}\">")
string.append(rh.gs(R.string.uploader_short)) string.append(rh.gs(R.string.uploader_short))
string.append(": </span>") string.append(": </span>")
val iterator: Iterator<*> = deviceStatusData.uploaderMap.entries.iterator() val iterator: Iterator<*> = deviceStatusData.uploaderMap.entries.iterator()

View file

@ -135,7 +135,6 @@
android:id="@+id/nsclient" android:id="@+id/nsclient"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/colorControlHighlight"
app:alignContent="stretch" app:alignContent="stretch"
app:alignItems="stretch" app:alignItems="stretch"
app:flexDirection="row" app:flexDirection="row"

View file

@ -239,6 +239,8 @@
<item name="separatorColor">@color/sphere_plastic_grey</item> <item name="separatorColor">@color/sphere_plastic_grey</item>
<item name="isCompletedColor">@color/isCompleted</item> <item name="isCompletedColor">@color/isCompleted</item>
<item name="isNotCompletedColor">@color/isNotCompleted</item> <item name="isNotCompletedColor">@color/isNotCompleted</item>
<!---Nightscout client TitelColor -->
<item name="nsTitleColor">@color/defaulttext</item>
</style> </style>
<style name="Aaps_ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar"> <style name="Aaps_ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">

View file

@ -213,4 +213,6 @@
<attr name="separatorColor" format="reference|color" /> <attr name="separatorColor" format="reference|color" />
<attr name="isCompletedColor" format="reference|color" /> <attr name="isCompletedColor" format="reference|color" />
<attr name="isNotCompletedColor" format="reference|color" /> <attr name="isNotCompletedColor" format="reference|color" />
<!---Nightscout client TitelColor -->
<attr name="nsTitleColor" format="reference|color" />
</resources> </resources>

View file

@ -60,7 +60,7 @@
<color name="errorAlertHeaderText">#FF000000</color> <color name="errorAlertHeaderText">#FF000000</color>
<color name="helperProfile">#C803A9F4</color> <color name="helperProfile">#C803A9F4</color>
<color name="examinedProfile">#FFFF5555</color> <color name="examinedProfile">#FFFF5555</color>
<color name="defaultText">#BBBBBB</color> <color name="defaulttext">#666666</color>
<!-- Datepicker--> <!-- Datepicker-->
<color name="dateTimePickerBackground">@color/white</color> <color name="dateTimePickerBackground">@color/white</color>

View file

@ -242,6 +242,8 @@
<item name="separatorColor">@color/sphere_plastic_grey</item> <item name="separatorColor">@color/sphere_plastic_grey</item>
<item name="isCompletedColor">@color/isCompleted</item> <item name="isCompletedColor">@color/isCompleted</item>
<item name="isNotCompletedColor">@color/isNotCompleted</item> <item name="isNotCompletedColor">@color/isNotCompleted</item>
<!---Nightscout client TitelColor -->
<item name="nsTitleColor">@color/defaulttext</item>
</style> </style>
<style name="Aaps_ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar"> <style name="Aaps_ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">