aps status

This commit is contained in:
Milos Kozak 2020-04-30 23:33:13 +02:00
parent 585b45fb97
commit 9a929e4bcb
24 changed files with 135 additions and 85 deletions

View file

@ -106,7 +106,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
} }
public String age(boolean useShortText, ResourceHelper resourceHelper) { public String age(boolean useShortText, ResourceHelper resourceHelper) {
Map<TimeUnit, Long> diff = computeDiff(date, System.currentTimeMillis()); Map<TimeUnit, Long> diff = DateUtil.computeDiff(date, System.currentTimeMillis());
String days = " " + resourceHelper.gs(R.string.days) + " "; String days = " " + resourceHelper.gs(R.string.days) + " ";
String hours = " " + resourceHelper.gs(R.string.hours) + " "; String hours = " " + resourceHelper.gs(R.string.hours) + " ";
@ -135,23 +135,6 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
"}"; "}";
} }
//Map:{DAYS=1, HOURS=3, MINUTES=46, SECONDS=40, MILLISECONDS=0, MICROSECONDS=0, NANOSECONDS=0}
private static Map<TimeUnit, Long> computeDiff(long date1, long date2) {
long diffInMillies = date2 - date1;
List<TimeUnit> units = new ArrayList<>(EnumSet.allOf(TimeUnit.class));
Collections.reverse(units);
Map<TimeUnit, Long> result = new LinkedHashMap<>();
long milliesRest = diffInMillies;
for (TimeUnit unit : units) {
long diff = unit.convert(milliesRest, TimeUnit.MILLISECONDS);
long diffInMilliesForUnit = unit.toMillis(diff);
milliesRest = milliesRest - diffInMilliesForUnit;
result.put(unit, diff);
}
return result;
}
public boolean isEvent5minBack(List<CareportalEvent> list, long time) { public boolean isEvent5minBack(List<CareportalEvent> list, long time) {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
CareportalEvent event = list.get(i); CareportalEvent event = list.get(i);

View file

@ -69,6 +69,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.overview_fragment.* import kotlinx.android.synthetic.main.overview_fragment.*
import kotlinx.android.synthetic.main.overview_fragment.overview_apsmode
import kotlinx.android.synthetic.main.overview_fragment.careportal_canulaage import kotlinx.android.synthetic.main.overview_fragment.careportal_canulaage
import kotlinx.android.synthetic.main.overview_fragment.careportal_insulinage import kotlinx.android.synthetic.main.overview_fragment.careportal_insulinage
import kotlinx.android.synthetic.main.overview_fragment.careportal_reservoirlevel import kotlinx.android.synthetic.main.overview_fragment.careportal_reservoirlevel
@ -76,7 +77,6 @@ import kotlinx.android.synthetic.main.overview_fragment.careportal_sensorage
import kotlinx.android.synthetic.main.overview_fragment.careportal_pbage import kotlinx.android.synthetic.main.overview_fragment.careportal_pbage
import kotlinx.android.synthetic.main.overview_fragment.careportal_batterylevel import kotlinx.android.synthetic.main.overview_fragment.careportal_batterylevel
import kotlinx.android.synthetic.main.overview_fragment.overview_activeprofile import kotlinx.android.synthetic.main.overview_fragment.overview_activeprofile
import kotlinx.android.synthetic.main.overview_fragment.overview_apsmode
import kotlinx.android.synthetic.main.overview_fragment.overview_arrow import kotlinx.android.synthetic.main.overview_fragment.overview_arrow
import kotlinx.android.synthetic.main.overview_fragment.overview_basebasal import kotlinx.android.synthetic.main.overview_fragment.overview_basebasal
import kotlinx.android.synthetic.main.overview_fragment.overview_bg import kotlinx.android.synthetic.main.overview_fragment.overview_bg
@ -329,10 +329,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
R.id.overview_quickwizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, Runnable { onClickQuickWizard() }) R.id.overview_quickwizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, Runnable { onClickQuickWizard() })
R.id.overview_carbsbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, Runnable { CarbsDialog().show(manager, "Overview") }) R.id.overview_carbsbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, Runnable { CarbsDialog().show(manager, "Overview") })
R.id.overview_pumpstatus -> {
if (activePlugin.activePump.isSuspended || !activePlugin.activePump.isInitialized) commandQueue.readStatus("RefreshClicked", null)
}
R.id.overview_cgmbutton -> { R.id.overview_cgmbutton -> {
if (xdripPlugin.isEnabled(PluginType.BGSOURCE)) if (xdripPlugin.isEnabled(PluginType.BGSOURCE))
openCgmApp("com.eveningoutpost.dexdrip") openCgmApp("com.eveningoutpost.dexdrip")
@ -597,44 +593,64 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
if (Config.APS && pump.pumpDescription.isTempBasalCapable) { if (Config.APS && pump.pumpDescription.isTempBasalCapable) {
overview_apsmode?.visibility = View.VISIBLE overview_apsmode?.visibility = View.VISIBLE
when { when {
loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuperBolus -> { loopPlugin.isEnabled() && loopPlugin.isSuperBolus -> {
overview_apsmode?.text = String.format(resourceHelper.gs(R.string.loopsuperbolusfor), loopPlugin.minutesToEndOfSuspend()) overview_apsmode.setImageResource(R.drawable.remove)
overview_apsmode?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_apsmode_text?.text = DateUtil.age(loopPlugin.minutesToEndOfSuspend() * 60000L, true, resourceHelper)
overview_apsmode?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) //overview_apsmode_text?.text = String.format(resourceHelper.gs(R.string.loopsuperbolusfor), loopPlugin.minutesToEndOfSuspend())
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning))
} }
loopPlugin.isDisconnected -> { loopPlugin.isDisconnected -> {
overview_apsmode?.text = String.format(resourceHelper.gs(R.string.loopdisconnectedfor), loopPlugin.minutesToEndOfSuspend()) overview_apsmode.setImageResource(R.drawable.closedloop_disconnected)
overview_apsmode?.setBackgroundColor(resourceHelper.gc(R.color.ribbonCritical)) overview_apsmode_text?.text = DateUtil.age(loopPlugin.minutesToEndOfSuspend() * 60000L, true, resourceHelper)
overview_apsmode?.setTextColor(resourceHelper.gc(R.color.ribbonTextCritical)) // overview_apsmode_text?.text = String.format(resourceHelper.gs(R.string.loopdisconnectedfor), loopPlugin.minutesToEndOfSuspend())
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonCritical))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextCritical))
} }
loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuspended -> { loopPlugin.isEnabled() && loopPlugin.isSuspended -> {
overview_apsmode?.text = String.format(resourceHelper.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()) overview_apsmode.setImageResource(R.drawable.closedloop_pause)
overview_apsmode?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_apsmode_text?.text = DateUtil.age(loopPlugin.minutesToEndOfSuspend() * 60000L, true, resourceHelper)
overview_apsmode?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) // overview_apsmode_text?.text = String.format(resourceHelper.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend())
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning))
} }
pump.isSuspended -> { pump.isSuspended -> {
overview_apsmode?.text = resourceHelper.gs(R.string.pumpsuspended) overview_apsmode.setImageResource(R.drawable.closedloop_pause)
overview_apsmode?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_apsmode_text?.text = ""
overview_apsmode?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) // overview_apsmode_text?.text = resourceHelper.gs(R.string.pumpsuspended)
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning))
} }
loopPlugin.isEnabled(PluginType.LOOP) -> { loopPlugin.isEnabled() && closedLoopEnabled.value() -> {
overview_apsmode?.text = if (closedLoopEnabled.value()) resourceHelper.gs(R.string.closedloop) else resourceHelper.gs(R.string.openloop) overview_apsmode.setImageResource(R.drawable.closedloop)
overview_apsmode?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) overview_apsmode_text?.text = ""
overview_apsmode?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) // overview_apsmode_text?.text = resourceHelper.gs(R.string.closedloop)
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault))
} }
else -> { loopPlugin.isEnabled() && !closedLoopEnabled.value() -> {
overview_apsmode?.text = resourceHelper.gs(R.string.disabledloop) overview_apsmode.setImageResource(R.drawable.openloop)
overview_apsmode?.setBackgroundColor(resourceHelper.gc(R.color.ribbonCritical)) overview_apsmode_text?.text = ""
overview_apsmode?.setTextColor(resourceHelper.gc(R.color.ribbonTextCritical)) // overview_apsmode_text?.text = resourceHelper.gs(R.string.openloop)
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault))
}
else -> {
overview_apsmode.setImageResource(R.drawable.remove)
overview_apsmode_text?.text = ""
// overview_apsmode_text?.text = resourceHelper.gs(R.string.disabledloop)
// overview_apsmode_text?.setBackgroundColor(resourceHelper.gc(R.color.ribbonCritical))
// overview_apsmode_text?.setTextColor(resourceHelper.gc(R.color.ribbonTextCritical))
} }
} }
} else { } else {
overview_apsmode?.visibility = View.GONE overview_apsmode_text?.visibility = View.GONE
} }
// temp target // temp target

View file

@ -11,11 +11,18 @@ import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.EnumSet;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -270,6 +277,42 @@ public class DateUtil {
return TimeZone.getDefault().getOffset(timestamp) / 60000; return TimeZone.getDefault().getOffset(timestamp) / 60000;
} }
//Map:{DAYS=1, HOURS=3, MINUTES=46, SECONDS=40, MILLISECONDS=0, MICROSECONDS=0, NANOSECONDS=0}
public static Map<TimeUnit, Long> computeDiff(long date1, long date2) {
long diffInMillies = date2 - date1;
List<TimeUnit> units = new ArrayList<>(EnumSet.allOf(TimeUnit.class));
Collections.reverse(units);
Map<TimeUnit, Long> result = new LinkedHashMap<>();
long milliesRest = diffInMillies;
for (TimeUnit unit : units) {
long diff = unit.convert(milliesRest, TimeUnit.MILLISECONDS);
long diffInMilliesForUnit = unit.toMillis(diff);
milliesRest = milliesRest - diffInMilliesForUnit;
result.put(unit, diff);
}
return result;
}
public static String age(long milliseconds, boolean useShortText, ResourceHelper resourceHelper) {
Map<TimeUnit, Long> diff = computeDiff(0L, milliseconds);
String days = " " + resourceHelper.gs(R.string.days) + " ";
String hours = " " + resourceHelper.gs(R.string.hours) + " ";
String minutes = " " + resourceHelper.gs(R.string.unit_minutes) + " ";
if (useShortText) {
days = resourceHelper.gs(R.string.shortday);
hours = resourceHelper.gs(R.string.shorthour);
minutes = resourceHelper.gs(R.string.shortminute);
}
String result = "";
if (diff.get(TimeUnit.DAYS) > 0) result += diff.get(TimeUnit.DAYS) + days;
if (diff.get(TimeUnit.HOURS) > 0) result += diff.get(TimeUnit.HOURS) + hours;
if (diff.get(TimeUnit.DAYS) == 0) result += diff.get(TimeUnit.MINUTES) + minutes;
return result;
}
public static String niceTimeScalar(long t, ResourceHelper resourceHelper) { public static String niceTimeScalar(long t, ResourceHelper resourceHelper) {
String unit = resourceHelper.gs(R.string.unit_second); String unit = resourceHelper.gs(R.string.unit_second);
t = t / 1000; t = t / 1000;

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -31,62 +31,43 @@
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
<androidx.constraintlayout.widget.ConstraintLayout <LinearLayout
android:id="@+id/overview_looplayout" android:id="@+id/overview_looplayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/overview_pumpstatuslayout" app:layout_constraintBottom_toTopOf="@+id/overview_pumpstatuslayout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/overview_notifications"> app:layout_constraintTop_toBottomOf="@+id/overview_notifications">
<TextView
android:id="@+id/overview_apsmode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:gravity="center_vertical|center_horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="@string/openloop"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/overview_activeprofile"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/overview_activeprofile" android:id="@+id/overview_activeprofile"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="5dp" android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal" android:gravity="center_vertical|center_horizontal"
android:paddingTop="3dp" android:paddingTop="3dp"
android:paddingBottom="3dp" android:paddingBottom="3dp"
android:text="@string/profile" android:text="Profile"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/overview_temptarget"
app:layout_constraintStart_toEndOf="@+id/overview_apsmode"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/overview_temptarget" android:id="@+id/overview_temptarget"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal" android:gravity="center_vertical|center_horizontal"
android:paddingTop="3dp" android:paddingTop="3dp"
android:paddingBottom="3dp" android:paddingBottom="3dp"
android:text="@string/temptargetshort" android:text="TempTarget"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/mdtp_white" android:textColor="@color/mdtp_white" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/overview_activeprofile"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/overview_pumpstatuslayout" android:id="@+id/overview_pumpstatuslayout"
@ -291,7 +272,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:text="0.50U/h @17:35 1/30min" android:text="0.50U/h"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/overview_basebasal_label" app:layout_constraintBottom_toBottomOf="@+id/overview_basebasal_label"
@ -322,7 +303,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:text="0.50U/h @17:35 1/30min" android:text="0.50U/h"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/overview_extendedbolus_label" app:layout_constraintBottom_toBottomOf="@+id/overview_extendedbolus_label"
@ -359,6 +340,33 @@
app:layout_constraintBottom_toBottomOf="@+id/overview_sensitivity_label" app:layout_constraintBottom_toBottomOf="@+id/overview_sensitivity_label"
app:layout_constraintStart_toEndOf="@+id/overview_sensitivity_colon" /> app:layout_constraintStart_toEndOf="@+id/overview_sensitivity_colon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/overview_apsmode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/closedloop" />
<TextView
android:id="@+id/overview_apsmode_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="Open Loop"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout <LinearLayout
@ -518,11 +526,11 @@
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:text="@string/setbasalquestion" android:text="@string/setbasalquestion"
android:textColor="@color/colorAcceptTempButton" android:textColor="@color/colorAcceptTempButton"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/overview_buttons_layout" app:layout_constraintBottom_toTopOf="@id/overview_buttons_layout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/overview_toppart_scrollbar" app:layout_constraintTop_toBottomOf="@id/overview_toppart_scrollbar" />
android:visibility="gone"/>
<LinearLayout <LinearLayout
android:id="@+id/overview_buttons_layout" android:id="@+id/overview_buttons_layout"