Skip to content

Commit f5ea5f1

Browse files
author
Paolo Rotolo
committed
Merge pull request #211 from Glucosio/develop
Releasing Glucosio 0.10.2
2 parents 4d177b4 + 51076f9 commit f5ea5f1

File tree

16 files changed

+255
-74
lines changed

16 files changed

+255
-74
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
defaultConfig {
1010
minSdkVersion 16
1111
targetSdkVersion 23
12-
versionCode 13
13-
versionName '0.10.1'
12+
versionCode 14
13+
versionName '0.10.2'
1414

1515
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
}

app/src/main/java/org/glucosio/android/fragment/HistoryFragment.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ public void updateToolbarBehaviour(){
166166
if (mAdapter!=null) {
167167
if (mLayoutManager.findLastCompletelyVisibleItemPosition() == mAdapter.getItemCount() - 1) {
168168
isToolbarScrolling = false;
169-
((MainActivity) getActivity()).turnOffToolbarScrolling();
169+
if (getActivity()!=null) {
170+
((MainActivity) getActivity()).turnOffToolbarScrolling();
171+
}
170172
} else {
171173
if (!isToolbarScrolling) {
172174
isToolbarScrolling = true;
@@ -186,7 +188,9 @@ public void notifyAdapter(){
186188
}
187189

188190
public void reloadFragmentAdapter(){
189-
((MainActivity)getActivity()).reloadFragmentAdapter();
190-
((MainActivity)getActivity()).checkIfEmptyLayout();
191+
if (getActivity()!= null) {
192+
((MainActivity) getActivity()).reloadFragmentAdapter();
193+
((MainActivity) getActivity()).checkIfEmptyLayout();
194+
}
191195
}
192196
}

app/src/main/java/org/glucosio/android/fragment/OverviewFragment.java

Lines changed: 110 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.widget.ImageButton;
1919
import android.widget.Spinner;
2020
import android.widget.TextView;
21+
import android.widget.Toast;
2122

2223
import com.github.mikephil.charting.animation.Easing;
2324
import com.github.mikephil.charting.charts.LineChart;
@@ -233,15 +234,17 @@ private void exportGraphToGallery() {
233234
}
234235

235236
private void setData() {
237+
// TODO: Refactor all this mess ASAP! -- @paolorotolo
236238
// int metricSpinnerPosition = graphSpinnerMetric.getSelectedItemPosition();
237239
// if (metricSpinnerPosition == 0) {
238240
ArrayList<String> xVals = new ArrayList<String>();
239241

242+
240243
if (graphSpinnerRange.getSelectedItemPosition() == 0) {
241244
// Day view
242245
for (int i = 0; i < presenter.getGlucoseDatetime().size(); i++) {
243246
String date = presenter.convertDate(presenter.getGlucoseDatetime().get(i));
244-
xVals.add(date + "");
247+
xVals.add(date + "");
245248
}
246249
} else if (graphSpinnerRange.getSelectedItemPosition() == 1){
247250
// Week view
@@ -258,50 +261,116 @@ private void setData() {
258261
}
259262

260263
GlucoseConverter converter = new GlucoseConverter();
264+
GlucoseRanges ranges = new GlucoseRanges(getActivity().getApplicationContext());
265+
266+
267+
ArrayList<Entry> yValsLow = new ArrayList<Entry>();
268+
ArrayList<Entry> yValsNormal = new ArrayList<Entry>();
269+
ArrayList<Entry> yValsHigh = new ArrayList<Entry>();
261270

262-
ArrayList<Entry> yVals = new ArrayList<Entry>();
263-
ArrayList<Integer> colors = new ArrayList<>();
264271

265-
if (graphSpinnerRange.getSelectedItemPosition() == 0) {
272+
if (graphSpinnerRange.getSelectedItemPosition() == 0) {
266273
// Day view
267274
for (int i = 0; i < presenter.getGlucoseReading().size(); i++) {
268275
if (presenter.getUnitMeasuerement().equals("mg/dL")) {
269276
float val = Float.parseFloat(presenter.getGlucoseReading().get(i).toString());
270-
yVals.add(new Entry(val, i));
277+
String range = ranges.colorFromReading(presenter.getGlucoseReading().get(i));
278+
279+
if (range.equals("purple") || range.equals("blue")){
280+
// low
281+
yValsLow.add(new Entry(val, i));
282+
} else if (range.equals("red") || range.equals("orange")){
283+
// high
284+
yValsHigh.add(new Entry(val, i));
285+
} else {
286+
// normal
287+
yValsNormal.add(new Entry(val, i));
288+
}
271289
} else {
272290
double val = converter.glucoseToMmolL(Double.parseDouble(presenter.getGlucoseReading().get(i).toString()));
273291
float converted = (float) val;
274-
yVals.add(new Entry(converted, i));
292+
String range = ranges.colorFromReading(presenter.getGlucoseReading().get(i));
293+
294+
if (range.equals("purple") || range.equals("blue")){
295+
// low
296+
yValsLow.add(new Entry(converted, i));
297+
} else if (range.equals("red") || range.equals("orange")){
298+
// high
299+
yValsHigh.add(new Entry(converted, i));
300+
} else {
301+
// normal
302+
yValsNormal.add(new Entry(converted, i));
303+
}
275304
}
276-
GlucoseRanges ranges = new GlucoseRanges(getActivity().getApplicationContext());
277-
colors.add(ranges.stringToColor(ranges.colorFromReading(presenter.getGlucoseReading().get(i))));
278305
}
279306
} else if (graphSpinnerRange.getSelectedItemPosition() == 1){
280307
// Week view
281308
for (int i = 0; i < presenter.getGlucoseReadingsWeek().size(); i++) {
282309
if (presenter.getUnitMeasuerement().equals("mg/dL")) {
283310
float val = Float.parseFloat(presenter.getGlucoseReadingsWeek().get(i)+"");
284-
yVals.add(new Entry(val, i));
311+
String range = ranges.colorFromReading(presenter.getGlucoseReadingsWeek().get(i));
312+
313+
if (range.equals("purple") || range.equals("blue")){
314+
// low
315+
yValsLow.add(new Entry(val, i));
316+
} else if (range.equals("red") || range.equals("orange")){
317+
// high
318+
yValsHigh.add(new Entry(val, i));
319+
} else {
320+
// normal
321+
yValsNormal.add(new Entry(val, i));
322+
}
323+
285324
} else {
286325
double val = converter.glucoseToMmolL(Double.parseDouble(presenter.getGlucoseReadingsWeek().get(i)+""));
287326
float converted = (float) val;
288-
yVals.add(new Entry(converted, i));
289-
}
327+
String range = ranges.colorFromReading(presenter.getGlucoseReadingsWeek().get(i));
328+
329+
if (range.equals("purple") && range.equals("blue")){
330+
// low
331+
yValsLow.add(new Entry(converted, i));
332+
} else if (range.equals("red") && range.equals("orange")){
333+
// high
334+
yValsHigh.add(new Entry(converted, i));
335+
} else {
336+
// normal
337+
yValsNormal.add(new Entry(converted, i));
338+
} }
290339
}
291-
colors.add(getResources().getColor(R.color.glucosio_pink));
292340
} else {
293341
// Month view
294342
for (int i = 0; i < presenter.getGlucoseReadingsMonth().size(); i++) {
295343
if (presenter.getUnitMeasuerement().equals("mg/dL")) {
296344
float val = Float.parseFloat(presenter.getGlucoseReadingsMonth().get(i)+"");
297-
yVals.add(new Entry(val, i));
345+
String range = ranges.colorFromReading(presenter.getGlucoseReadingsMonth().get(i));
346+
347+
if (range.equals("purple") && range.equals("blue")){
348+
// low
349+
yValsLow.add(new Entry(val, i));
350+
} else if (range.equals("red") && range.equals("orange")){
351+
// high
352+
yValsHigh.add(new Entry(val, i));
353+
} else {
354+
// normal
355+
yValsNormal.add(new Entry(val, i));
356+
}
298357
} else {
299358
double val = converter.glucoseToMmolL(Double.parseDouble(presenter.getGlucoseReadingsMonth().get(i)+""));
300359
float converted = (float) val;
301-
yVals.add(new Entry(converted, i));
360+
String range = ranges.colorFromReading(presenter.getGlucoseReadingsWeek().get(i));
361+
362+
if (range.equals("purple") && range.equals("blue")){
363+
// low
364+
yValsLow.add(new Entry(converted, i));
365+
} else if (range.equals("red") && range.equals("orange")){
366+
// high
367+
yValsHigh.add(new Entry(converted, i));
368+
} else {
369+
// normal
370+
yValsNormal.add(new Entry(converted, i));
371+
}
302372
}
303373
}
304-
colors.add(getResources().getColor(R.color.glucosio_pink));
305374
}
306375
/*} else if (metricSpinnerPosition == 1){
307376
// A1C
@@ -333,36 +402,20 @@ private void setData() {
333402
// Weight
334403
}*/
335404

336-
// create a dataset and give it a type
337-
LineDataSet set1 = new LineDataSet(yVals, "");
338-
set1.setColor(getResources().getColor(R.color.glucosio_pink));
339-
set1.setLineWidth(2.5f);
340-
set1.setCircleColor(getResources().getColor(R.color.glucosio_pink));
341-
set1.setCircleSize(4f);
342-
set1.setDrawCircleHole(true);
343-
set1.disableDashedLine();
344-
set1.setFillAlpha(255);
345-
set1.setDrawFilled(true);
346-
set1.setValueTextSize(0);
347-
set1.setValueTextColor(Color.parseColor("#FFFFFF"));
348-
set1.setFillColor(Color.parseColor("#FCE2EA"));
349-
350-
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2){
351-
set1.setDrawFilled(false);
352-
set1.setLineWidth(3f);
353-
set1.setCircleSize(4.5f);
354-
set1.setDrawCircleHole(true);
355-
}
356-
357405
// set1.setDrawFilled(true);
358406
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
359407
// Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));I
360408

361-
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
362-
dataSets.add(set1); // add the datasets
409+
// add the datasets
410+
ArrayList<ILineDataSet> dataSet = new ArrayList<ILineDataSet>();
411+
412+
dataSet.add(createLineDataSet(yValsLow, getResources().getColor(R.color.glucosio_reading_low), "low"));
413+
dataSet.add(createLineDataSet(yValsNormal, getResources().getColor(R.color.glucosio_reading_ok), "normal"));
414+
dataSet.add(createLineDataSet(yValsHigh, getResources().getColor(R.color.glucosio_reading_high), "high"));
415+
363416

364417
// create a data object with the datasets
365-
LineData data = new LineData(xVals, dataSets);
418+
LineData data = new LineData(xVals, dataSet);
366419

367420
// set data
368421
chart.setData(data);
@@ -376,6 +429,24 @@ private void setData() {
376429
chart.moveViewToX(data.getXValCount());
377430
}
378431

432+
private LineDataSet createLineDataSet(ArrayList<Entry> yVals, int color, String label) {
433+
// create a dataset and give it a type
434+
LineDataSet set1 = new LineDataSet(yVals, label);
435+
set1.setColor(color);
436+
set1.setDrawFilled(false);
437+
set1.setLineWidth(1f);
438+
set1.setCircleColor(color);
439+
set1.setCircleSize(4f);
440+
set1.setDrawCircleHole(true);
441+
set1.disableDashedLine();
442+
set1.setDrawCubic(true);
443+
set1.setCubicIntensity(0.2f);
444+
set1.setValueTextSize(0);
445+
set1.setValueTextColor(Color.parseColor("#FFFFFF"));
446+
447+
return set1;
448+
}
449+
379450
private void loadHB1AC(){
380451
if (!presenter.isdbEmpty()){
381452
HB1ACTextView.setText(presenter.getHB1AC());

app/src/main/java/org/glucosio/android/tools/GlucoseRanges.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public GlucoseRanges(Context context){
2222
this.customMax = dB.getUser(1).getCustom_range_max();
2323
}
2424
}
25+
2526
public String colorFromReading(int reading) {
2627
// Check for Hypo/Hyperglycemia
2728
if (reading < 70) {
@@ -65,7 +66,8 @@ public String colorFromReading(int reading) {
6566
}
6667
}
6768
}
68-
return "red";}
69+
return "red";
70+
}
6971

7072
public int stringToColor (String color){
7173
switch (color) {
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
3-
<solid android:color="@color/glucosio_reading_high"/>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
<corners android:radius="10dip"/>
5+
<stroke android:color="@color/glucosio_reading_high" android:width="2dip"/>
6+
<solid android:color="@android:color/transparent"/>
47
</shape>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
3+
<solid android:color="@color/glucosio_reading_high"/>
4+
</shape>
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
3-
<solid android:color="@color/glucosio_reading_low"/>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
<corners android:radius="10dip"/>
5+
<stroke android:color="@color/glucosio_reading_low" android:width="2dip"/>
6+
<solid android:color="@android:color/transparent"/>
47
</shape>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
3+
<solid android:color="@color/glucosio_reading_low"/>
4+
</shape>

0 commit comments

Comments
 (0)