Merge pull request #1120 from schmitzn/sync-butterknife-eventbus

Synchronize Butterknife / Eventbus (#1090)
This commit is contained in:
Milos Kozak 2018-06-22 17:45:55 +02:00 committed by GitHub
commit 9dc667817b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 197 additions and 125 deletions

View file

@ -176,13 +176,19 @@ public class HistoryBrowseActivity extends AppCompatActivity {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateGUI("EventAutosensCalculationFinished");
synchronized (HistoryBrowseActivity.this) {
updateGUI("EventAutosensCalculationFinished");
}
}
});
}
}
void updateGUI(String from) {
if (noProfile == null || buttonDate == null || buttonZoom == null || bgGraph == null || iobGraph == null || seekBar == null)
return;
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
final Profile profile = MainApp.getConfigBuilder().getProfile();

View file

@ -80,7 +80,7 @@ public class LoopFragment extends SubscriberFragment {
clearGUI();
final Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> lastRunView.setText(ev.text));
activity.runOnUiThread(() -> { synchronized (LoopFragment.this) { if (lastRunView != null) lastRunView.setText(ev.text); } });
}
@ -89,26 +89,29 @@ public class LoopFragment extends SubscriberFragment {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
if (lastRun != null) {
requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : "");
constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toSpanned() : "");
sourceView.setText(lastRun.source != null ? lastRun.source : "");
lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : "");
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : "");
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : "");
synchronized (LoopFragment.this) {
if (!isBound()) return;
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
if (lastRun != null) {
requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : "");
constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toSpanned() : "");
sourceView.setText(lastRun.source != null ? lastRun.source : "");
lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : "");
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : "");
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : "");
String constraints = "";
if (lastRun.constraintsProcessed != null) {
Constraint<Double> allConstraints = new Constraint<>(0d);
if (lastRun.constraintsProcessed.rateConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.rateConstraint);
if (lastRun.constraintsProcessed.smbConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.smbConstraint);
constraints = allConstraints.getMostLimitedReasons();
String constraints = "";
if (lastRun.constraintsProcessed != null) {
Constraint<Double> allConstraints = new Constraint<>(0d);
if (lastRun.constraintsProcessed.rateConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.rateConstraint);
if (lastRun.constraintsProcessed.smbConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.smbConstraint);
constraints = allConstraints.getMostLimitedReasons();
}
constraintsView.setText(constraints);
}
constraintsView.setText(constraints);
}
});
}
@ -117,13 +120,29 @@ public class LoopFragment extends SubscriberFragment {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
requestView.setText("");
constraintsProcessedView.setText("");
sourceView.setText("");
lastRunView.setText("");
lastEnactView.setText("");
tbrSetByPumpView.setText("");
smbSetByPumpView.setText("");
synchronized (LoopFragment.this) {
if (isBound()) {
requestView.setText("");
constraintsProcessedView.setText("");
sourceView.setText("");
lastRunView.setText("");
lastEnactView.setText("");
tbrSetByPumpView.setText("");
smbSetByPumpView.setText("");
}
}
});
}
boolean isBound() {
return requestView != null
&& constraintsProcessedView != null
&& sourceView != null
&& lastRunView != null
&& lastEnactView != null
&& tbrSetByPumpView != null
&& smbSetByPumpView != null
&& constraintsView != null
&& runNowButton != null;
}
}

View file

@ -87,34 +87,37 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException see log for details");
synchronized (OpenAPSSMBFragment.this) {
if (!isBound()) return;
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException see log for details");
}
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
}
if (plugin.lastAPSRun != null) {
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim());
}
if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
}
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
}
if (plugin.lastAPSRun != null) {
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim());
}
if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
}
}
});
@ -126,17 +129,36 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
resultView.setText(text);
glucoseStatusView.setText("");
currentTempView.setText("");
iobDataView.setText("");
profileView.setText("");
mealDataView.setText("");
autosensDataView.setText("");
scriptdebugView.setText("");
requestView.setText("");
lastRunView.setText("");
synchronized (OpenAPSSMBFragment.this) {
if (isBound()) {
resultView.setText(text);
glucoseStatusView.setText("");
currentTempView.setText("");
iobDataView.setText("");
profileView.setText("");
mealDataView.setText("");
autosensDataView.setText("");
scriptdebugView.setText("");
requestView.setText("");
lastRunView.setText("");
}
}
}
});
}
private boolean isBound() {
return run != null
&& lastRunView != null
&& constraintsView != null
&& glucoseStatusView != null
&& currentTempView != null
&& iobDataView != null
&& profileView != null
&& mealDataView != null
&& autosensDataView != null
&& resultView != null
&& scriptdebugView != null
&& requestView != null;
}
}

View file

@ -79,11 +79,14 @@ public class NSProfileFragment extends SubscriberFragment {
public void onStatusEvent(final EventNSProfileUpdateGUI ev) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> updateGUI());
activity.runOnUiThread(() -> { synchronized (NSProfileFragment.this) { updateGUI(); } });
}
@Override
protected void updateGUI() {
if (noProfile == null || profileSpinner == null)
return;
ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile();
if (profileStore != null) {
ArrayList<CharSequence> profileList = profileStore.getProfileList();

View file

@ -216,74 +216,96 @@ public class DanaRFragment extends SubscriberFragment {
@SuppressLint("SetTextI18n")
@Override
public void run() {
DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
int agoMin = (int) (agoMsec / 60d / 1000d);
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")");
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
}
if (pump.lastBolusTime.getTime() != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText("");
}
synchronized(DanaRFragment.this) {
if (!isBound()) return;
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
// DanaRPlugin, DanaRKoreanPlugin
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
int agoMin = (int) (agoMsec / 60d / 1000d);
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")");
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
}
} else {
// v2 plugin
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
if (pump.lastBolusTime.getTime() != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText("");
}
}
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
if (activeExtendedBolus != null) {
extendedBolusView.setText(activeExtendedBolus.toString());
} else {
extendedBolusView.setText("");
}
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U");
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");
SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d);
iobView.setText(pump.iob + " U");
if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) {
firmwareView.setText(String.format(MainApp.gs(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
} else {
firmwareView.setText("OLD");
}
basalStepView.setText("" + pump.basalStep);
bolusStepView.setText("" + pump.bolusStep);
serialNumberView.setText("" + pump.serialNumber);
if (queueView != null) {
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
if (status.toString().equals("")) {
queueView.setVisibility(View.GONE);
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
// DanaRPlugin, DanaRKoreanPlugin
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
} else {
queueView.setVisibility(View.VISIBLE);
queueView.setText(status);
// v2 plugin
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
}
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
if (activeExtendedBolus != null) {
extendedBolusView.setText(activeExtendedBolus.toString());
} else {
extendedBolusView.setText("");
}
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U");
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");
SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d);
iobView.setText(pump.iob + " U");
if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) {
firmwareView.setText(String.format(MainApp.gs(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
} else {
firmwareView.setText("OLD");
}
basalStepView.setText("" + pump.basalStep);
bolusStepView.setText("" + pump.bolusStep);
serialNumberView.setText("" + pump.serialNumber);
if (queueView != null) {
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
if (status.toString().equals("")) {
queueView.setVisibility(View.GONE);
} else {
queueView.setVisibility(View.VISIBLE);
queueView.setText(status);
}
}
//hide user options button if not an RS pump
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
if (isKorean) {
danar_user_options.setVisibility(View.GONE);
}
}
//hide user options button if not an RS pump
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
if (isKorean ) {
danar_user_options.setVisibility(View.GONE);
}
}
});
}
private boolean isBound() {
return lastConnectionView != null
&& lastBolusView != null
&& dailyUnitsView != null
&& basaBasalRateView != null
&& tempBasalView != null
&& extendedBolusView != null
&& reservoirView != null
&& batteryView != null
&& iobView != null
&& firmwareView != null
&& basalStepView != null
&& bolusStepView != null
&& serialNumberView != null
&& danar_user_options != null
&& queueView != null;
}
}