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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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?
|
||||||
|
|
||||||
|
@ -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,6 +198,8 @@ 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;
|
||||||
|
|
||||||
|
@ -198,7 +209,6 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public static boolean isEnabled() {
|
||||||
return fragmentEnabled;
|
return fragmentEnabled;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue