diff --git a/lib/android/components/meal_page_text/days_component.dart b/lib/android/components/meal_page_text/days_component.dart index 00451e3..b7ade1e 100644 --- a/lib/android/components/meal_page_text/days_component.dart +++ b/lib/android/components/meal_page_text/days_component.dart @@ -23,11 +23,11 @@ class _DaysMealPageState extends State { setState(() { activatedIndex = index; if(activatedIndex == 0){ - StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day); + StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day); }else if(activatedIndex == 1){ - StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.week); + StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.week); }else if(activatedIndex == 2){ - StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.month); + StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.month); } }); } diff --git a/lib/android/config/statistics.dart b/lib/android/config/statistics.dart index 5790811..25f1831 100644 --- a/lib/android/config/statistics.dart +++ b/lib/android/config/statistics.dart @@ -35,7 +35,7 @@ class StatisticsService { putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []); putIfKeyNotExists([reducedBox,progressBox], 'MITTAGESSEN', []); putIfKeyNotExists([reducedBox,progressBox], 'ABENDESSEN', []); - updateReducedBoxByTimespan(TimeSpan.day); + updateStatisticsTodayBoxByTimespan(TimeSpan.day); } void putIfKeyNotExists(List boxes, String key, dynamic value) { @@ -46,10 +46,10 @@ class StatisticsService { } } - updateReducedBoxByTimespan(TimeSpan timeSpan){ - clearReducedBoxBeforeUpdate(); + updateStatisticsTodayBoxByTimespan(TimeSpan timespan){ + clearBoxByBox(Hive.box(todayStatisticsBoxName)); int timestamp = getTimestampFromNow(); - switch(timeSpan){ + switch(timespan){ case TimeSpan.day: getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName)); break; @@ -99,8 +99,7 @@ class StatisticsService { return timestampsForWeekdays; } - clearReducedBoxBeforeUpdate(){ - Box box = Hive.box(todayStatisticsBoxName); + clearBoxByBox(Box box){ for(int i = 0; i < box.keys.length;i++){ box.put(box.keys.elementAt(i), []); } @@ -419,6 +418,12 @@ class StatisticsService { return now.millisecondsSinceEpoch.toInt() ~/ 1000; } + List getMealsOfTodayByMealtype(String mealtype){ + int timestamp = getTimestampFromNow(); + return getFoodMapForGivenTimestampFromMainBox(timestamp)[mealtype] ?? []; + + } + showItems(){ print("Statistics.dart - showItems() - ITEMS"); //Hive.box(boxName).clear(); diff --git a/lib/android/pages/nav_pages/main_page.dart b/lib/android/pages/nav_pages/main_page.dart index 2543c92..6945c05 100644 --- a/lib/android/pages/nav_pages/main_page.dart +++ b/lib/android/pages/nav_pages/main_page.dart @@ -25,7 +25,7 @@ class MainPageState extends State { setState(() { currentIndex = index; if(currentIndex == 1){ - StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day); + StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day); }else if(currentIndex == 2){ StatisticsService.instance.updateProgressBoxValues(); } diff --git a/lib/android/pages/nav_pages/today_page.dart b/lib/android/pages/nav_pages/today_page.dart index 34e39e0..4f894e6 100644 --- a/lib/android/pages/nav_pages/today_page.dart +++ b/lib/android/pages/nav_pages/today_page.dart @@ -1,4 +1,5 @@ import 'package:ernaehrung/android/components/card/card_component.dart'; +import 'package:ernaehrung/android/config/statistics.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive_flutter/adapters.dart'; @@ -26,14 +27,11 @@ class _TodayPageState extends State { shrinkWrap: true, itemCount: box.keys.length, itemBuilder: (context, i) { - if (box.keyAt(i).toString() == "DATE") { - return const SizedBox.shrink(); - } else { - return CardComponent( - box.keyAt(i).toString(), - box.getAt(i) - ); - } + String mealTypeAsString = box.keyAt(i).toString(); + return CardComponent( + mealTypeAsString, + StatisticsService.instance.getMealsOfTodayByMealtype(mealTypeAsString) + ); }); }))); }