diff --git a/app/build.gradle b/app/build.gradle index c14690d6..a2b4ce1e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,10 @@ configurations { } android { - buildFeatures.viewBinding = true - + buildFeatures { + buildConfig = true + viewBinding = true + } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -33,8 +35,8 @@ android { compileSdk 34 targetSdkVersion 34 vectorDrawables.useSupportLibrary = true - versionCode 90 - versionName "26" + versionCode 91 + versionName "27" } buildTypes { debug { @@ -43,8 +45,8 @@ android { } release { manifestPlaceholders = [crashlyticsCollectionEnabled: "true"] -// minifyEnabled true -// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } @@ -61,18 +63,18 @@ android { } dependencies { - implementation 'com.google.firebase:firebase-analytics:22.0.2' - implementation 'com.google.firebase:firebase-crashlytics:19.0.3' + implementation 'com.google.firebase:firebase-analytics:22.1.0' + implementation 'com.google.firebase:firebase-crashlytics:19.1.0' implementation 'androidx.appcompat:appcompat:1.7.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.google.android.material:material:1.12.0' - implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT' + implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.darwinsys:hirondelle-date4j:1.5.1' implementation 'com.github.prolificinteractive:material-calendarview:2.0.1' implementation('com.joanzapata.iconify:android-iconify-fontawesome:2.2.2') { exclude group: "com.android.support" } implementation('com.github.PhilJay:MPAndroidChart:v2.2.5') { exclude group: "com.android.support" } implementation('org.greenrobot:eventbus:3.3.1') { exclude group: "com.android.support" } implementation 'com.google.code.gson:gson:2.10.1' - implementation 'com.jakewharton.timber:timber:4.7.1' + implementation 'com.jakewharton.timber:timber:5.0.1' implementation "io.noties.markwon:core:4.6.2" } diff --git a/app/libs/activeandroid-3.1.0-SNAPSHOT.jar b/app/libs/activeandroid-3.1.0-SNAPSHOT.jar new file mode 100644 index 00000000..28b494e6 Binary files /dev/null and b/app/libs/activeandroid-3.1.0-SNAPSHOT.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index b4031fb0..20d5d7d7 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -24,6 +24,8 @@ # ActiveAndroid -keep class com.activeandroid.** { *; } +-keep class org.nutritionfacts.dailydozen.model.** { *; } + # MPAndroidChart -keep class com.github.mikephil.charting.** { *; } -dontwarn io.realm.** diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 75f07721..1c289978 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,7 +29,6 @@ android:name=".activity.MainActivity" android:exported="true" android:launchMode="singleTask" - android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"> @@ -55,14 +54,12 @@ + android:configChanges="orientation|keyboardHidden"/> getServingsOfFoodInYearAndMonth(final long foodI } } - if (placeholderArray.size() == 0) { + if (placeholderArray.isEmpty()) { return new ArrayMap<>(); } diff --git a/app/src/main/java/org/nutritionfacts/dailydozen/model/Day.java b/app/src/main/java/org/nutritionfacts/dailydozen/model/Day.java index 16cd062b..ae3a509a 100644 --- a/app/src/main/java/org/nutritionfacts/dailydozen/model/Day.java +++ b/app/src/main/java/org/nutritionfacts/dailydozen/model/Day.java @@ -134,6 +134,10 @@ public static Day getByDate(String dateString) throws InvalidDateException { return day; } + public static Day createDay(final String dateString) { + return createDayIfDoesNotExist(new Day(fromDateString(dateString))); + } + public static Day createDayIfDoesNotExist(final String dateString) throws InvalidDateException { return createDayIfDoesNotExist(getByDate(dateString)); } diff --git a/app/src/main/java/org/nutritionfacts/dailydozen/model/TweakServings.java b/app/src/main/java/org/nutritionfacts/dailydozen/model/TweakServings.java index fdb83443..95aea648 100644 --- a/app/src/main/java/org/nutritionfacts/dailydozen/model/TweakServings.java +++ b/app/src/main/java/org/nutritionfacts/dailydozen/model/TweakServings.java @@ -97,6 +97,13 @@ public static TweakServings getByDateAndTweak(Day day, Tweak tweak) { return null; } + public static TweakServings createServings(final Day day, final Tweak tweak, final int numServings) { + TweakServings servings = new TweakServings(day, tweak); + servings.setServings(numServings); + servings.save(); + return servings; + } + public static TweakServings createServingsIfDoesNotExist(final Day day, final Tweak tweak) { return createServingsIfDoesNotExist(day, tweak, 0); } @@ -183,7 +190,7 @@ public static Map getServingsOfTweakInYearAndMonth(final long twea } } - if (placeholderArray.size() == 0) { + if (placeholderArray.isEmpty()) { return new ArrayMap<>(); } diff --git a/app/src/main/java/org/nutritionfacts/dailydozen/model/Weights.java b/app/src/main/java/org/nutritionfacts/dailydozen/model/Weights.java index a9163d55..7f3466cf 100644 --- a/app/src/main/java/org/nutritionfacts/dailydozen/model/Weights.java +++ b/app/src/main/java/org/nutritionfacts/dailydozen/model/Weights.java @@ -59,6 +59,12 @@ public Float getAverageWeight() { return null; } + public static boolean createWeights(final Day day, float morningWeight, float eveningWeight) { + Weights weights = new Weights(day, morningWeight, eveningWeight); + weights.save(); + return true; + } + public static boolean createWeightsIfDoesNotExist(final Day day, float morningWeight, float eveningWeight) { Weights weights = getWeightsOnDay(day); diff --git a/app/src/main/java/org/nutritionfacts/dailydozen/task/BackupTask.java b/app/src/main/java/org/nutritionfacts/dailydozen/task/BackupTask.java index af416467..7e85a0d4 100644 --- a/app/src/main/java/org/nutritionfacts/dailydozen/task/BackupTask.java +++ b/app/src/main/java/org/nutritionfacts/dailydozen/task/BackupTask.java @@ -5,7 +5,6 @@ import com.google.gson.Gson; -import org.nutritionfacts.dailydozen.Common; import org.nutritionfacts.dailydozen.R; import org.nutritionfacts.dailydozen.controller.Bus; import org.nutritionfacts.dailydozen.model.DDServings; @@ -49,19 +48,16 @@ public Boolean call() { final int numDays = allDays.size(); - final String lineSeparator = Common.getLineSeparator(); - - final StringBuilder jsonLines = new StringBuilder(); + try { + final FileWriter fileWriter = new FileWriter(backupFile); - for (int i = 0; i < numDays; i++) { - jsonLines.append(String.format("%s%s", lineSeparator, getDayJsonLine(allDays.get(i)))); + for (int i = 0; i < numDays; i++) { + fileWriter.write(getDayJsonLine(allDays.get(i))); + fileWriter.write(System.lineSeparator()); - progressListener.updateProgressBar(i + 1, numDays); - } + progressListener.updateProgressBar(i + 1, numDays); + } - try { - final FileWriter fileWriter = new FileWriter(backupFile); - fileWriter.write(jsonLines.toString()); fileWriter.close(); Timber.d("backup file successfully written"); diff --git a/app/src/main/java/org/nutritionfacts/dailydozen/task/GenerateDataTask.java b/app/src/main/java/org/nutritionfacts/dailydozen/task/GenerateDataTask.java index 723857f3..0d92cbe3 100644 --- a/app/src/main/java/org/nutritionfacts/dailydozen/task/GenerateDataTask.java +++ b/app/src/main/java/org/nutritionfacts/dailydozen/task/GenerateDataTask.java @@ -99,7 +99,7 @@ private void createDailyDozenForDay(List allFoods, Day day) { final int numServings = taskParams.generateRandomData() ? random.nextInt(recommendedServings + 1) : recommendedServings; if (numServings > 0) { - DDServings.createServingsIfDoesNotExist(day, food, numServings); + DDServings.createServings(day, food, numServings); } } } @@ -110,7 +110,7 @@ private void createTweaksForDay(List allTweaks, Day day) { final int numServings = taskParams.generateRandomData() ? random.nextInt(recommendedServings + 1) : recommendedServings; if (numServings > 0) { - TweakServings.createServingsIfDoesNotExist(day, tweak, numServings); + TweakServings.createServings(day, tweak, numServings); } } } @@ -128,7 +128,7 @@ private void createWeightsForDay(final Day day) { eveningWeight = round(180 + 3 * random.nextFloat()); } - Weights.createWeightsIfDoesNotExist(day, morningWeight, eveningWeight); + Weights.createWeights(day, morningWeight, eveningWeight); } private static float round(double value) { diff --git a/app/src/main/java/org/nutritionfacts/dailydozen/task/RestoreTask.java b/app/src/main/java/org/nutritionfacts/dailydozen/task/RestoreTask.java index a7f71116..c3a37ca1 100644 --- a/app/src/main/java/org/nutritionfacts/dailydozen/task/RestoreTask.java +++ b/app/src/main/java/org/nutritionfacts/dailydozen/task/RestoreTask.java @@ -84,11 +84,11 @@ public Boolean call() { progressListener.updateProgressBar(++i, numLines); } while (line != null); } else { - do { - line = reader.readLine(); + while (line != null) { restoreLineJSON(line); progressListener.updateProgressBar(++i, numLines); - } while (line != null); + line = reader.readLine(); + } } } @@ -164,23 +164,25 @@ private void restoreLineJSON(final String line) { try { DayEntries dayEntries = new Gson().fromJson(line, DayEntries.class); - final Day day = Day.createDayIfDoesNotExist(dayEntries.getDate()); + final Day day = Day.createDay(dayEntries.getDate()); - Weights.createWeightsIfDoesNotExist(day, - dayEntries.getMorningWeight(), - dayEntries.getEveningWeight()); + if (dayEntries.getMorningWeight() != 0 || dayEntries.getEveningWeight() != 0) { + Weights.createWeights(day, dayEntries.getMorningWeight(), dayEntries.getEveningWeight()); + } for (Map.Entry entry : dayEntries.getDailyDozen().entrySet()) { - DDServings.createServingsAndRecalculateStreak(day, getFoodByIdName(entry.getKey()), entry.getValue()); + if (entry.getValue() > 0) { + DDServings.createServings(day, getFoodByIdName(entry.getKey()), entry.getValue()); + } } for (Map.Entry entry : dayEntries.getTweaks().entrySet()) { - TweakServings.createServingsIfDoesNotExist(day, getTweakByIdName(entry.getKey()), entry.getValue()); + if (entry.getValue() > 0) { + TweakServings.createServings(day, getTweakByIdName(entry.getKey()), entry.getValue()); + } } ActiveAndroid.setTransactionSuccessful(); - } catch (InvalidDateException e) { - Timber.e(e, "restoreLineJSON: "); } catch (JsonSyntaxException e) { Timber.e(e, "restoreLineJSON: "); } finally { diff --git a/app/src/main/res/layout-land/activity_servings_history.xml b/app/src/main/res/layout-land/activity_servings_history.xml new file mode 100644 index 00000000..ea43324c --- /dev/null +++ b/app/src/main/res/layout-land/activity_servings_history.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/time_range_selector.xml b/app/src/main/res/layout-land/time_range_selector.xml new file mode 100644 index 00000000..eeb5e817 --- /dev/null +++ b/app/src/main/res/layout-land/time_range_selector.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/time_scale_selector.xml b/app/src/main/res/layout-land/time_scale_selector.xml new file mode 100644 index 00000000..ac9747b8 --- /dev/null +++ b/app/src/main/res/layout-land/time_scale_selector.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-v17/food_type_item.xml b/app/src/main/res/layout-v17/food_type_item.xml deleted file mode 100644 index 92fca05c..00000000 --- a/app/src/main/res/layout-v17/food_type_item.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout-v21/activity_food_info.xml b/app/src/main/res/layout-v21/activity_food_info.xml deleted file mode 100644 index d5707536..00000000 --- a/app/src/main/res/layout-v21/activity_food_info.xml +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -