xdrip statusline reformat
This commit is contained in:
parent
67f21537ea
commit
da0334eb19
1 changed files with 62 additions and 52 deletions
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
@ -21,7 +22,6 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by adrian on 17/11/16.
|
* Created by adrian on 17/11/16.
|
||||||
|
@ -29,6 +29,12 @@ import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
public class StatuslinePlugin implements PluginBase {
|
public class StatuslinePlugin implements PluginBase {
|
||||||
|
|
||||||
|
//broadcast related constants
|
||||||
|
public static final String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline";
|
||||||
|
public static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
|
||||||
|
public static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
|
||||||
|
|
||||||
|
|
||||||
static boolean fragmentEnabled = false;
|
static boolean fragmentEnabled = false;
|
||||||
private static boolean lastLoopStatus;
|
private static boolean lastLoopStatus;
|
||||||
|
|
||||||
|
@ -38,6 +44,8 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
StatuslinePlugin(Context ctx) {
|
StatuslinePlugin(Context ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
|
|
||||||
|
if (fragmentEnabled)
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +67,7 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.xdripstatus_shortname);
|
String name = MainApp.sResources.getString(R.string.xdripstatus_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +104,11 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
if (type == GENERAL) {
|
if (type == GENERAL) {
|
||||||
this.fragmentEnabled = fragmentEnabled;
|
this.fragmentEnabled = fragmentEnabled;
|
||||||
|
|
||||||
|
if (fragmentEnabled)
|
||||||
|
MainApp.bus().register(this);
|
||||||
|
else
|
||||||
|
MainApp.bus().unregister(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,10 +118,21 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void sendStatus() {
|
private void sendStatus() {
|
||||||
if(!fragmentEnabled) return;
|
|
||||||
|
|
||||||
|
String status = buildStatusString();
|
||||||
|
|
||||||
|
//sendData
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(EXTRA_STATUSLINE, status);
|
||||||
|
Intent intent = new Intent(ACTION_NEW_EXTERNAL_STATUSLINE);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
ctx.sendBroadcast(intent, RECEIVER_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private String buildStatusString() {
|
||||||
String status = "";
|
String status = "";
|
||||||
boolean shortString = true; // make setting?
|
boolean shortString = true; // make setting?
|
||||||
|
|
||||||
|
@ -138,7 +162,7 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||||
status += (shortString?"":(ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
||||||
|
|
||||||
|
|
||||||
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
|
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
|
||||||
|
@ -146,25 +170,10 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
+ DecimalFormatter.to2Decimal(bolusIob.iob) + "|"
|
+ DecimalFormatter.to2Decimal(bolusIob.iob) + "|"
|
||||||
+ DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
|
+ DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
//constants
|
|
||||||
String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline";
|
|
||||||
String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
|
|
||||||
String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
|
|
||||||
//sendData
|
|
||||||
final Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(EXTRA_STATUSLINE, status);
|
|
||||||
Intent intent = new Intent(ACTION_NEW_EXTERNAL_STATUSLINE);
|
|
||||||
intent.putExtras(bundle);
|
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
|
||||||
ctx.sendBroadcast(intent, RECEIVER_PERMISSION);
|
|
||||||
|
|
||||||
ToastUtils.showToastInUiThread(ctx, "status: " + status);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
// status may be formated differently
|
// status may be formated differently
|
||||||
|
@ -189,16 +198,17 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventRefreshGui ev) {
|
public void onStatusEvent(final EventRefreshGui ev) {
|
||||||
|
|
||||||
|
//Filter events where loop is (de)activated
|
||||||
|
|
||||||
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||||
if (activeloop == null) return;
|
if (activeloop == null) return;
|
||||||
|
|
||||||
if((lastLoopStatus != activeloop.isEnabled(PluginBase.LOOP))) {
|
if ((lastLoopStatus != activeloop.isEnabled(PluginBase.LOOP))) {
|
||||||
sendStatus();
|
sendStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public static boolean isEnabled() {
|
||||||
return fragmentEnabled;
|
return fragmentEnabled;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue