Skip to content

Commit 6928acc

Browse files
authored
Merge pull request #3707 from Navid200/Navid_2023_08_18
Statistics Customizable list of parameters
2 parents e6186b1 + 3860240 commit 6928acc

File tree

5 files changed

+427
-238
lines changed

5 files changed

+427
-238
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/stats/FirstPageFragment.java

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.eveningoutpost.dexdrip.stats;
22

3-
import static android.app.PendingIntent.getActivity;
4-
5-
63
import android.content.Context;
74
import android.content.SharedPreferences;
85
import android.os.Bundle;
96
import android.preference.PreferenceManager;
107
import androidx.annotation.NonNull;
118
import androidx.annotation.Nullable;
9+
import androidx.databinding.DataBindingUtil;
1210
import androidx.fragment.app.Fragment;
1311

12+
import com.eveningoutpost.dexdrip.databinding.StatsGeneralBinding;
13+
import com.eveningoutpost.dexdrip.models.UserError;
1414
import com.eveningoutpost.dexdrip.models.UserError.Log;
1515
import android.view.LayoutInflater;
1616
import android.view.View;
@@ -19,6 +19,7 @@
1919

2020
import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants;
2121
import com.eveningoutpost.dexdrip.R;
22+
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
2223

2324
import java.text.DecimalFormat;
2425
import java.util.ArrayList;
@@ -28,6 +29,7 @@
2829
* Created by adrian on 30/06/15.
2930
*/
3031
public class FirstPageFragment extends Fragment {
32+
private final static String TAG = FirstPageFragment.class.getSimpleName();
3133

3234
private View myView;
3335

@@ -36,8 +38,9 @@ public class FirstPageFragment extends Fragment {
3638
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
3739
Log.d("DrawStats", "FirstPageFragment onCreateView");
3840

39-
myView = inflater.inflate(
40-
R.layout.stats_general, container, false);
41+
StatsGeneralBinding binding = DataBindingUtil.inflate(inflater, R.layout.stats_general, container, false);
42+
myView = binding.getRoot();
43+
binding.setStatsview(new ViewStats());
4144

4245
myView.setTag(0);
4346

@@ -52,6 +55,56 @@ public View getView() {
5255
return myView;
5356
}
5457

58+
public class ViewStats { // Linking to stats_general layout
59+
public boolean viewAbsolutes() { // Show absolute numbers
60+
return Pref.getBoolean("show_statistics_absolutes", false);
61+
}
62+
63+
public boolean viewMedianBG() { // Show BG median
64+
return Pref.getBoolean("show_statistics_median", false);
65+
}
66+
67+
public boolean viewA1C() { // Show estimated A1C
68+
return Pref.getBoolean("show_statistics_a1cestimate", false);
69+
}
70+
71+
public boolean viewSD() { // Show standard deviation
72+
return Pref.getBoolean("show_statistics_sd", false);
73+
}
74+
75+
public boolean viewRelSD() { // Show relative standard deviation
76+
return Pref.getBoolean("show_statistics_relsd", false);
77+
}
78+
79+
public boolean viewGviLine() { // Show the GVI line, including GVI and PGS
80+
return Pref.getBoolean("show_statistics_gvi", false) || Pref.getBoolean("show_statistics_pgs", false);
81+
}
82+
}
83+
84+
public static void defineDefaults () { // This is where the defaults are defined.
85+
defineDefault("show_statistics_absolutes", true); // Show absolute values
86+
defineDefault("show_statistics_median", true); // Show median by default
87+
defineDefault("show_statistics_a1cestimate", true); // Show estimated A1C
88+
defineDefault("show_statistics_sd", true); // Show standard deviation
89+
defineDefault("show_statistics_relsd", true); // Show relative standard deviation
90+
defineDefault("show_statistics_pgs", true); // Show PGS
91+
defineDefault("show_statistics_gvi", true); // Show GVI
92+
}
93+
94+
public static void defineDefault (String pref, Boolean def) {
95+
if (!Pref.isPreferenceSet(pref)) { // If the value (of pref) has never been changed
96+
try {
97+
if (!def) { // If the default is false
98+
// There is no need to take any action if the default is false
99+
} else if (def) { // If the default is true
100+
Pref.setBoolean(pref, true); // Enable the setting
101+
}
102+
} catch (Exception e) {
103+
UserError.Log.wtf(TAG, "incorrect arguments");
104+
}
105+
}
106+
}
107+
55108
private class CalculationThread extends Thread {
56109

57110
private final View localView;
@@ -75,7 +128,7 @@ public void run() {
75128
return;
76129
}
77130

78-
//Ranges
131+
// Ranges
79132
long aboveRange = DBSearchUtil.noReadingsAboveRange(context);
80133
long belowRange = DBSearchUtil.noReadingsBelowRange(context);
81134
long inRange = DBSearchUtil.noReadingsInRange(context);
@@ -96,7 +149,7 @@ public void run() {
96149
double stats_high = Double.parseDouble(settings.getString("highValue", "170"));
97150
double stats_low = Double.parseDouble(settings.getString("lowValue", "70"));
98151
TextView rangeView = (TextView) localView.findViewById(R.id.textView_stats_range_set);
99-
//update stats_high/low
152+
// update stats_high/low
100153
if (!mgdl) {
101154
updateText(localView, rangeView, (Math.round(stats_low * 10) / 10d) + " - " + (Math.round(stats_high * 10) / 10d) + " mmol/l");
102155
} else {
@@ -127,14 +180,14 @@ public void run() {
127180
}
128181

129182
TextView meanView = (TextView) localView.findViewById(R.id.textView_mean);
130-
//update mean
183+
// update mean
131184
if (mgdl) {
132185
updateText(localView, meanView, (Math.round(mean * 10) / 10d) + " mg/dl");
133186
} else {
134187
updateText(localView, meanView, (Math.round(mean * Dex_Constants.MG_DL_TO_MMOL_L * 100) / 100d) + " mmol/l");
135188

136189
}
137-
//update A1c
190+
// update A1c
138191
TextView a1cView = (TextView) localView.findViewById(R.id.textView_a1c);
139192
int a1c_ifcc = (int) Math.round(((mean + 46.7) / 28.7 - 2.15) * 10.929);
140193
double a1c_dcct = Math.round(10 * (mean + 46.7) / 28.7) / 10d;
@@ -156,7 +209,7 @@ public void run() {
156209
updateText(localView, coefficientOfVariation, Math.round(1000d*stdev/mean)/10d + "%");
157210

158211

159-
//calculate BGI / PGS
212+
// calculate GVI / PGS
160213
// https://github.com/nightscout/cgm-remote-monitor/blob/master/lib/report_plugins/glucosedistribution.js#L150
161214
List<BgReadingStats> bgListByTime = DBSearchUtil.getFilteredReadingsWithFallback(false);
162215

@@ -193,7 +246,13 @@ public void run() {
193246
Log.d("DrawStats", "NormalReadingspct=" + normalReadingspct + " glucoseMean=" + glucoseMean + " tirMultiplier=" + tirMultiplier + " PGS=" + PGS);
194247
TextView gviView = (TextView) localView.findViewById(R.id.textView_gvi);
195248
DecimalFormat df = new DecimalFormat("#.00");
196-
updateText(localView, gviView, df.format(gvi) + " PGS: " + df.format(PGS));
249+
if (Pref.getBoolean("show_statistics_pgs", false) && Pref.getBoolean("show_statistics_gvi", true)) { // Show both GVI and PGS
250+
updateText(localView, gviView, "GVI: " + df.format(gvi) + " PGS: " + df.format(PGS));
251+
} else if (Pref.getBoolean("show_statistics_gvi", true)) { // Show only GVI
252+
updateText(localView, gviView, "GVI: " + df.format(gvi));
253+
} else if (Pref.getBoolean("show_statistics_pgs", false)) { // Show only PGS
254+
updateText(localView, gviView, "PGS: " + df.format(PGS));
255+
}
197256

198257
}
199258
}

app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsActivity.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,25 @@ public class StatsActivity extends ActivityWithMenu {
6262
private Button button90d;
6363
MenuItem menuItem;
6464
MenuItem menuItem2;
65+
MenuItem menuItem3;
66+
MenuItem menuItem4;
67+
MenuItem menuItem5;
68+
MenuItem menuItem6;
69+
MenuItem menuItem7;
70+
MenuItem menuItem8;
71+
MenuItem menuItem9;
6572
private View decorView;
6673
private String stateString;
6774
private final static int MY_PERMISSIONS_REQUEST_STORAGE_SCREENSHOT = 106;
6875
private static final String SHOW_STATISTICS_FULL_SCREEN = "show_statistics_full_screen";
6976
public static final String SHOW_STATISTICS_PRINT_COLOR = "show_statistics_print_color";
77+
public static final String SHOW_STATISTICS_Absolutes = "show_statistics_absolutes";
78+
public static final String SHOW_STATISTICS_Median_BG = "show_statistics_median";
79+
public static final String SHOW_STATISTICS_A1C = "show_statistics_a1cestimate";
80+
public static final String SHOW_STATISTICS_SD = "show_statistics_sd";
81+
public static final String SHOW_STATISTICS_Rel_SD = "show_statistics_relsd";
82+
public static final String SHOW_STATISTICS_GVI = "show_statistics_gvi";
83+
public static final String SHOW_STATISTICS_PGS = "show_statistics_pgs";
7084
private static final String TAG = "Statistics";
7185

7286
@Override
@@ -245,6 +259,13 @@ public boolean onCreateOptionsMenu(Menu menu) {
245259

246260
menuItem = menu.findItem(R.id.action_toggle_fullscreen);
247261
menuItem2 = menu.findItem(R.id.action_toggle_printing);
262+
menuItem3 = menu.findItem(R.id.action_show_absolutes);
263+
menuItem4 = menu.findItem(R.id.action_show_median);
264+
menuItem5 = menu.findItem(R.id.action_show_a1cestimate);
265+
menuItem6 = menu.findItem(R.id.action_show_sd);
266+
menuItem7 = menu.findItem(R.id.action_show_relsd);
267+
menuItem8 = menu.findItem(R.id.action_show_gvi);
268+
menuItem9 = menu.findItem(R.id.action_show_pgs);
248269

249270
updateMenuChecked();
250271

@@ -262,6 +283,13 @@ public void onWindowFocusChanged(boolean hasFocus) {
262283
private void updateMenuChecked() {
263284
menuItem.setChecked(Pref.getBoolean(SHOW_STATISTICS_FULL_SCREEN, false));
264285
menuItem2.setChecked(Pref.getBoolean(SHOW_STATISTICS_PRINT_COLOR, false));
286+
menuItem3.setChecked(Pref.getBoolean(SHOW_STATISTICS_Absolutes, false));
287+
menuItem4.setChecked(Pref.getBoolean(SHOW_STATISTICS_Median_BG, false));
288+
menuItem5.setChecked(Pref.getBoolean(SHOW_STATISTICS_A1C, false));
289+
menuItem6.setChecked(Pref.getBoolean(SHOW_STATISTICS_SD, false));
290+
menuItem7.setChecked(Pref.getBoolean(SHOW_STATISTICS_Rel_SD, false));
291+
menuItem8.setChecked(Pref.getBoolean(SHOW_STATISTICS_GVI, false));
292+
menuItem9.setChecked(Pref.getBoolean(SHOW_STATISTICS_PGS, false));
265293
}
266294

267295
private void evaluateColors(boolean recreate) {
@@ -291,6 +319,56 @@ public void toggleStatisticsPrintingMode(MenuItem m)
291319
evaluateColors(true);
292320
updateMenuChecked();
293321
}
322+
323+
public void toggleStatisticsShowAbsolutes(MenuItem m) // Toggle visibility of absolute numbers
324+
{
325+
Pref.toggleBoolean(SHOW_STATISTICS_Absolutes);
326+
evaluateColors(true);
327+
updateMenuChecked();
328+
}
329+
330+
public void toggleStatisticsShowMedianBG(MenuItem m) // Toggle visibility of median
331+
{
332+
Pref.toggleBoolean(SHOW_STATISTICS_Median_BG);
333+
evaluateColors(true);
334+
updateMenuChecked();
335+
}
336+
337+
public void toggleStatisticsShowA1C(MenuItem m) // Toggle visibility of estimated A1C
338+
{
339+
Pref.toggleBoolean(SHOW_STATISTICS_A1C);
340+
evaluateColors(true);
341+
updateMenuChecked();
342+
}
343+
344+
public void toggleStatisticsShowSD(MenuItem m) // Toggle visibility of standard deviation
345+
{
346+
Pref.toggleBoolean(SHOW_STATISTICS_SD);
347+
evaluateColors(true);
348+
updateMenuChecked();
349+
}
350+
351+
public void toggleStatisticsShowRelSD(MenuItem m) // Toggle visibility of relative standard deviation
352+
{
353+
Pref.toggleBoolean(SHOW_STATISTICS_Rel_SD);
354+
evaluateColors(true);
355+
updateMenuChecked();
356+
}
357+
358+
public void toggleStatisticsShowGVI(MenuItem m) // Toggle visibility of GVI
359+
{
360+
Pref.toggleBoolean(SHOW_STATISTICS_GVI);
361+
evaluateColors(true);
362+
updateMenuChecked();
363+
}
364+
365+
public void toggleStatisticsShowPGS(MenuItem m) // Toggle visibility of PGS
366+
{
367+
Pref.toggleBoolean(SHOW_STATISTICS_PGS);
368+
evaluateColors(true);
369+
updateMenuChecked();
370+
}
371+
294372
public void statisticsDisableFullScreen(View v)
295373
{
296374
toggleStatisticsFullScreenMode(null);

app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.eveningoutpost.dexdrip.models.UserNotification;
2424
import com.eveningoutpost.dexdrip.R;
2525
import com.eveningoutpost.dexdrip.SnoozeActivity;
26+
import com.eveningoutpost.dexdrip.stats.FirstPageFragment;
2627
import com.eveningoutpost.dexdrip.utils.Preferences;
2728

2829
import java.util.ArrayList;
@@ -64,6 +65,7 @@ public void performAll() {
6465
IncompatibleApps.notifyAboutIncompatibleApps();
6566
CompatibleApps.notifyAboutCompatibleApps();
6667
legacySettingsMoveLanguageFromNoToNb();
68+
FirstPageFragment.defineDefaults(); // Define the statistics page visibility defaults.
6769
prefSettingRangeVerification();
6870
inheritPrefSettingsAfterUpdate();
6971

0 commit comments

Comments
 (0)