@@ -69,9 +69,9 @@ public boolean isdbEmpty() {
6969 return dB .getGlucoseReadings ().size () == 0 ;
7070 }
7171
72- public void loadDatabase () {
72+ public void loadDatabase (boolean isNewGraphEnabled ) {
7373 this .glucoseReadings = dB .getGlucoseReadings ();
74- this .glucoseGraphObjects = generateGlucoseGraphPoints ();
74+ this .glucoseGraphObjects = generateGlucoseGraphPoints (isNewGraphEnabled );
7575 this .glucoseReadingsMonth = dB .getAverageGlucoseReadingsByMonth ();
7676 this .glucoseReadingsWeek = dB .getAverageGlucoseReadingsByWeek ();
7777 this .glucoseDatetimeWeek = dB .getGlucoseDatetimesByWeek ();
@@ -240,35 +240,46 @@ public ArrayList<String> getCholesterolReadingsDateTime(){
240240 return dB .getCholesterolDateTimeAsArray ();
241241 }
242242
243- private List <IntGraphObject > generateGlucoseGraphPoints () {
244- DateTime minDateTime = DateTime .now ().minusMonths (1 ).minusDays (15 );
245- final List <GlucoseReading > glucoseReadings = dB .getLastMonthGlucoseReadings ();
246-
247- Collections .sort (glucoseReadings , new Comparator <GlucoseReading >() {
248- public int compare (GlucoseReading o1 , GlucoseReading o2 ) {
249- return o1 .getCreated ().compareTo (o2 .getCreated ());
250- }
251- });
252-
253- DateTime startDate = glucoseReadings .size () > 0 ?
254- minDateTime : DateTime .now ();
255- // This will contain final values
243+ private List <IntGraphObject > generateGlucoseGraphPoints (boolean isNewGraphEnabled ) {
256244 final ArrayList <IntGraphObject > finalGraphObjects = new ArrayList <>();
257- // Transfer values from database to ArrayList as GlucoseGraphObjects
258- for (int i =0 ; i <glucoseReadings .size (); i ++){
259- final GlucoseReading reading = glucoseReadings .get (i );
260- final DateTime createdDate = new DateTime (reading .getCreated ());
261- //add zero values between current value and last added value
262- addZeroReadings (finalGraphObjects , startDate , createdDate );
263- //add new value
264- finalGraphObjects .add (
265- new IntGraphObject (createdDate , reading .getReading ())
266- );
267- //update start date
268- startDate = createdDate ;
245+ if (isNewGraphEnabled ) {
246+ DateTime minDateTime = DateTime .now ().minusMonths (1 ).minusDays (15 );
247+ final List <GlucoseReading > glucoseReadings = dB .getLastMonthGlucoseReadings ();
248+
249+ Collections .sort (glucoseReadings , new Comparator <GlucoseReading >() {
250+ public int compare (GlucoseReading o1 , GlucoseReading o2 ) {
251+ return o1 .getCreated ().compareTo (o2 .getCreated ());
252+ }
253+ });
254+
255+ DateTime startDate = glucoseReadings .size () > 0 ?
256+ minDateTime : DateTime .now ();
257+ // Transfer values from database to ArrayList as GlucoseGraphObjects
258+ for (int i = 0 ; i < glucoseReadings .size (); i ++) {
259+ final GlucoseReading reading = glucoseReadings .get (i );
260+ final DateTime createdDate = new DateTime (reading .getCreated ());
261+ //add zero values between current value and last added value
262+ addZeroReadings (finalGraphObjects , startDate , createdDate );
263+ //add new value
264+ finalGraphObjects .add (
265+ new IntGraphObject (createdDate , reading .getReading ())
266+ );
267+ //update start date
268+ startDate = createdDate ;
269+ }
270+ //add last zeros till now
271+ addZeroReadings (finalGraphObjects , startDate , DateTime .now ());
272+ } else {
273+ Collections .sort (glucoseReadings , new Comparator <GlucoseReading >() {
274+ public int compare (GlucoseReading o1 , GlucoseReading o2 ) {
275+ return o1 .getCreated ().compareTo (o2 .getCreated ());
276+ }
277+ });
278+ for (int i = 0 ; i < glucoseReadings .size (); i ++){
279+ GlucoseReading glucoseReading = glucoseReadings .get (i );
280+ finalGraphObjects .add (new IntGraphObject (new DateTime (glucoseReading .getCreated ()), glucoseReading .getReading ()));
281+ }
269282 }
270- //add last zeros till now
271- addZeroReadings (finalGraphObjects , startDate , DateTime .now ());
272283
273284 return finalGraphObjects ;
274285 }
@@ -282,14 +293,6 @@ private void addZeroReadings(final ArrayList<IntGraphObject> graphObjects,
282293 }
283294 }
284295
285- public ArrayList <String > getGlucoseType () {
286- return glucoseType ;
287- }
288-
289- public ArrayList <String > getGlucoseDatetime () {
290- return dB .getGlucoseDateTimeAsArray ();
291- }
292-
293296 public ArrayList <String > getGraphGlucoseDateTime (){
294297 ArrayList <String > glucoseDatetime = new ArrayList <>();
295298 DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern ("yyyy-MM-dd HH:mm" );
0 commit comments