optimize overview fragment
This commit is contained in:
parent
e94fe1f647
commit
da26ea5995
2 changed files with 23 additions and 96 deletions
|
@ -37,7 +37,7 @@
|
||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.Overview;
|
package info.nightscout.androidaps.plugins.Overview;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
@ -87,7 +88,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
Button setExtenedButton;
|
Button setExtenedButton;
|
||||||
Button acceptTempButton;
|
Button acceptTempButton;
|
||||||
|
|
||||||
boolean visibleNow = false;
|
|
||||||
Handler loopHandler = new Handler();
|
Handler loopHandler = new Handler();
|
||||||
Runnable refreshLoop = null;
|
Runnable refreshLoop = null;
|
||||||
|
|
||||||
|
@ -141,8 +141,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OverviewFragment newInstance() {
|
public static OverviewFragment newInstance() {
|
||||||
OverviewFragment fragment = new OverviewFragment();
|
return new OverviewFragment();
|
||||||
return fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -152,20 +151,11 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
refreshLoop = new Runnable() {
|
refreshLoop = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (visibleNow) {
|
updateGUIIfVisible();
|
||||||
Activity activity = getActivity();
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000l);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000l);
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +237,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
MainApp.getConfigBuilder().getActiveLoop().invoke(false);
|
MainApp.getConfigBuilder().getActiveLoop().invoke(false);
|
||||||
final LoopFragment.LastRun finalLastRun = MainApp.getConfigBuilder().getActiveLoop().lastRun;
|
final LoopFragment.LastRun finalLastRun = LoopFragment.lastRun;
|
||||||
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.changeRequested) {
|
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.changeRequested) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(getContext().getString(R.string.confirmation));
|
builder.setTitle(getContext().getString(R.string.confirmation));
|
||||||
|
@ -269,14 +259,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
objectivesFragment.saveProgress();
|
objectivesFragment.saveProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Activity activity = getActivity();
|
updateGUIIfVisible();
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -303,76 +286,35 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
Activity activity = getActivity();
|
updateGUIIfVisible();
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
else
|
|
||||||
log.debug("EventPreferenceChange: Activity is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventRefreshGui ev) {
|
public void onStatusEvent(final EventRefreshGui ev) {
|
||||||
Activity activity = getActivity();
|
updateGUIIfVisible();
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
else
|
|
||||||
log.debug("EventRefreshGui: Activity is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventTreatmentChange ev) {
|
public void onStatusEvent(final EventTreatmentChange ev) {
|
||||||
Activity activity = getActivity();
|
updateGUIIfVisible();
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
else
|
|
||||||
log.debug("EventTreatmentChange: Activity is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
public void onStatusEvent(final EventTempBasalChange ev) {
|
||||||
Activity activity = getActivity();
|
updateGUIIfVisible();
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
else
|
|
||||||
log.debug("EventTempBasalChange: Activity is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
Activity activity = getActivity();
|
updateGUIIfVisible();
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
else
|
|
||||||
log.debug("EventNewBG: Activity is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventRefreshOpenLoop ev) {
|
public void onStatusEvent(final EventRefreshOpenLoop ev) {
|
||||||
|
updateGUIIfVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateGUIIfVisible() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null)
|
if (activity != null)
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@ -381,22 +323,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
else
|
|
||||||
log.debug("EventNewBG: Activity is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
|
||||||
super.setUserVisibleHint(isVisibleToUser);
|
|
||||||
|
|
||||||
if (isVisibleToUser) {
|
|
||||||
updateGUI();
|
|
||||||
visibleNow = true;
|
|
||||||
} else {
|
|
||||||
visibleNow = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
public void updateGUI() {
|
public void updateGUI() {
|
||||||
BgReading actualBG = MainApp.getDbHelper().actualBg();
|
BgReading actualBG = MainApp.getDbHelper().actualBg();
|
||||||
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
||||||
|
@ -408,7 +337,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// open loop mode
|
// open loop mode
|
||||||
final LoopFragment.LastRun finalLastRun = MainApp.getConfigBuilder().getActiveLoop().lastRun;
|
final LoopFragment.LastRun finalLastRun = LoopFragment.lastRun;
|
||||||
if (Config.APS) {
|
if (Config.APS) {
|
||||||
apsModeView.setVisibility(View.VISIBLE);
|
apsModeView.setVisibility(View.VISIBLE);
|
||||||
if (MainApp.getConfigBuilder().isClosedModeEnabled())
|
if (MainApp.getConfigBuilder().isClosedModeEnabled())
|
||||||
|
@ -418,8 +347,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
apsModeView.setVisibility(View.GONE);
|
apsModeView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showAcceptButton = true;
|
boolean showAcceptButton = !MainApp.getConfigBuilder().isClosedModeEnabled(); // Open mode needed
|
||||||
showAcceptButton = showAcceptButton && !MainApp.getConfigBuilder().isClosedModeEnabled(); // Open mode needed
|
|
||||||
showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist
|
showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist
|
||||||
showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result
|
showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result
|
||||||
showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested
|
showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested
|
||||||
|
@ -465,7 +393,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
|
||||||
// **** BG value ****
|
// **** BG value ****
|
||||||
if (profile != null && lastBG != null && bgView != null) {
|
if (lastBG != null && bgView != null) {
|
||||||
bgView.setText(lastBG.valueToUnitsToString(profile.getUnits()));
|
bgView.setText(lastBG.valueToUnitsToString(profile.getUnits()));
|
||||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||||
if (glucoseStatus != null)
|
if (glucoseStatus != null)
|
||||||
|
@ -511,7 +439,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
|
|
||||||
int hoursToFetch = 6;
|
int hoursToFetch = 6;
|
||||||
long toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding
|
long toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding
|
||||||
long fromTime = toTime - hoursToFetch * 60 * 60 * 1000l;
|
long fromTime = toTime - hoursToFetch * 60 * 60 * 1000L;
|
||||||
|
|
||||||
Double lowLine = NSProfile.fromMgdlToUnits(bgTargetLow, units);
|
Double lowLine = NSProfile.fromMgdlToUnits(bgTargetLow, units);
|
||||||
Double highLine = NSProfile.fromMgdlToUnits(bgTargetHigh, units);
|
Double highLine = NSProfile.fromMgdlToUnits(bgTargetHigh, units);
|
||||||
|
@ -645,7 +573,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
List<Treatment> treatments = MainApp.getConfigBuilder().getActiveTreatments().getTreatments();
|
List<Treatment> treatments = MainApp.getConfigBuilder().getActiveTreatments().getTreatments();
|
||||||
List<Treatment> filteredTreatments = new ArrayList<Treatment>();
|
List<Treatment> filteredTreatments = new ArrayList<Treatment>();
|
||||||
|
|
||||||
for (int tx = 0; tx < treatments.size(); tx ++) {
|
for (int tx = 0; tx < treatments.size(); tx++) {
|
||||||
Treatment t = treatments.get(tx);
|
Treatment t = treatments.get(tx);
|
||||||
if (t.getTimeIndex() < fromTime || t.getTimeIndex() > now) continue;
|
if (t.getTimeIndex() < fromTime || t.getTimeIndex() > now) continue;
|
||||||
t.setYValue(bgReadingsArray);
|
t.setYValue(bgReadingsArray);
|
||||||
|
@ -672,7 +600,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
bgGraph.getViewport().setMinY(0);
|
bgGraph.getViewport().setMinY(0);
|
||||||
bgGraph.getViewport().setYAxisBoundsManual(true);
|
bgGraph.getViewport().setYAxisBoundsManual(true);
|
||||||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines);
|
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines);
|
||||||
// TODO: add treatments
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue