1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-28 18:49:56 +02:00

Merge branch 'erijo-days'

This commit is contained in:
OliE
2017-12-30 10:14:45 +01:00
16 changed files with 182 additions and 40 deletions

View File

@@ -23,4 +23,4 @@ after_success:
- chmod +x ./upload_apk.sh - chmod +x ./upload_apk.sh
- ./upload_apk.sh - ./upload_apk.sh
script: cd android_app && ./gradlew assembleDebug script: cd android_app && ./gradlew testDebug assembleDebug

View File

@@ -31,4 +31,13 @@ dependencies {
compile "com.android.support:support-v4:${supportLibVersion}" compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:appcompat-v7:${supportLibVersion}" compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile 'com.github.lecho:hellocharts-library:1.5.8@aar' compile 'com.github.lecho:hellocharts-library:1.5.8@aar'
compile 'junit:junit:4.12'
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
} }

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 2017 Erik Johansson <erik@ejohansson.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.health.openscale.core.utils;
import java.util.Calendar;
public final class DateTimeHelpers {
static public int daysBetween(Calendar start, Calendar end) {
if (start.after(end)) {
return -daysBetween(end, start);
}
int days = 0;
Calendar current = (Calendar)start.clone();
while (current.get(Calendar.YEAR) < end.get(Calendar.YEAR)) {
final int daysInYear =
current.getActualMaximum(Calendar.DAY_OF_YEAR)
- current.get(Calendar.DAY_OF_YEAR) + 1;
days += daysInYear;
current.add(Calendar.DAY_OF_YEAR, daysInYear);
}
days += end.get(Calendar.DAY_OF_YEAR) - current.get(Calendar.DAY_OF_YEAR);
return days;
}
}

View File

@@ -37,6 +37,7 @@ import com.health.openscale.R;
import com.health.openscale.core.OpenScale; import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleData; import com.health.openscale.core.datatypes.ScaleData;
import com.health.openscale.core.datatypes.ScaleUser; import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.DateTimeHelpers;
import com.health.openscale.gui.activities.DataEntryActivity; import com.health.openscale.gui.activities.DataEntryActivity;
import com.health.openscale.gui.views.BMIMeasurementView; import com.health.openscale.gui.views.BMIMeasurementView;
import com.health.openscale.gui.views.BMRMeasurementView; import com.health.openscale.gui.views.BMRMeasurementView;
@@ -55,6 +56,7 @@ import com.health.openscale.gui.views.WeightMeasurementView;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter; import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
@@ -255,12 +257,8 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
max_i = scaleDataList.size(); max_i = scaleDataList.size();
} }
Calendar histDate = Calendar.getInstance(); final Calendar now = Calendar.getInstance();
Calendar lastDate = Calendar.getInstance(); Calendar histCalendar = Calendar.getInstance();
if (!scaleDataList.isEmpty()) {
lastDate.setTime(scaleDataList.get(0).getDateTime());
}
scaleDataLastDays = new ArrayList<ScaleData>(); scaleDataLastDays = new ArrayList<ScaleData>();
@@ -285,11 +283,10 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
if (histData.getBone() != 0.0f) if (histData.getBone() != 0.0f)
valuesBone.add(new PointValue(i, histData.getBone())); valuesBone.add(new PointValue(i, histData.getBone()));
histDate.setTime(histData.getDateTime()); histCalendar.setTime(histData.getDateTime());
int days = DateTimeHelpers.daysBetween(now, histCalendar);
long days = 0 - daysBetween(lastDate, histDate); String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days);
axisValues.add(new AxisValue(i, label.toCharArray()));
axisValues.add(new AxisValue(i, String.format("%d " + getResources().getString(R.string.label_days), days).toCharArray()));
} }
Line lineWeight = new Line(valuesWeight). Line lineWeight = new Line(valuesWeight).
@@ -428,10 +425,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
pieChartLast.setPieChartData(pieChartData); pieChartLast.setPieChartData(pieChartData);
} }
private long daysBetween(Calendar startDate, Calendar endDate) {
return startDate.get(Calendar.DAY_OF_YEAR) - endDate.get(Calendar.DAY_OF_YEAR);
}
public void btnOnClickInsertData() public void btnOnClickInsertData()
{ {
Intent intent = new Intent(overviewView.getContext(), DataEntryActivity.class); Intent intent = new Intent(overviewView.getContext(), DataEntryActivity.class);

View File

@@ -30,11 +30,12 @@ import com.health.openscale.R;
import com.health.openscale.core.OpenScale; import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleData; import com.health.openscale.core.datatypes.ScaleData;
import com.health.openscale.core.datatypes.ScaleUser; import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.DateTimeHelpers;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.concurrent.TimeUnit; import java.util.Date;
public class StatisticsFragment extends Fragment implements FragmentUpdateListener { public class StatisticsFragment extends Fragment implements FragmentUpdateListener {
@@ -99,7 +100,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
txtTitleStatistics.setText(getResources().getString(R.string.label_title_statistics).toUpperCase()); txtTitleStatistics.setText(getResources().getString(R.string.label_title_statistics).toUpperCase());
prefs = PreferenceManager.getDefaultSharedPreferences(statisticsView.getContext()); prefs = PreferenceManager.getDefaultSharedPreferences(statisticsView.getContext());
currentScaleUser = OpenScale.getInstance(getContext()).getSelectedScaleUser(); currentScaleUser = OpenScale.getInstance(getContext()).getSelectedScaleUser();
updateStatistics(scaleDataList); updateStatistics(scaleDataList);
updateGoal(scaleDataList); updateGoal(scaleDataList);
@@ -114,12 +115,10 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
double weight_diff = goalScaleData.getConvertedWeight(currentScaleUser.scale_unit) - lastScaleData.getConvertedWeight(currentScaleUser.scale_unit); double weight_diff = goalScaleData.getConvertedWeight(currentScaleUser.scale_unit) - lastScaleData.getConvertedWeight(currentScaleUser.scale_unit);
txtGoalDiff.setText(String.format("%.1f " + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit], weight_diff)); txtGoalDiff.setText(String.format("%.1f " + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit], weight_diff));
Calendar goalDate = Calendar.getInstance(); Calendar goalCalendar = Calendar.getInstance();
Calendar curDate = Calendar.getInstance(); goalCalendar.setTime(currentScaleUser.goal_date);
goalDate.setTime(currentScaleUser.goal_date); int days = Math.max(0, DateTimeHelpers.daysBetween(Calendar.getInstance(), goalCalendar));
txtGoalDayLeft.setText(getResources().getQuantityString(R.plurals.label_days, days, days));
long days = daysBetween(curDate, goalDate);
txtGoalDayLeft.setText(days + " " + getResources().getString(R.string.label_days));
lastScaleData.setUserId(currentScaleUser.id); lastScaleData.setUserId(currentScaleUser.id);
@@ -334,10 +333,4 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
txtAvgWeek.setText(weekSize + " " + getResources().getString(R.string.label_measures)); txtAvgWeek.setText(weekSize + " " + getResources().getString(R.string.label_measures));
txtAvgMonth.setText(monthSize + " " + getResources().getString(R.string.label_measures)); txtAvgMonth.setText(monthSize + " " + getResources().getString(R.string.label_measures));
} }
private long daysBetween(Calendar startDate, Calendar endDate) {
long end = endDate.getTimeInMillis();
long start = startDate.getTimeInMillis();
return TimeUnit.MILLISECONDS.toDays(Math.abs(end - start));
}
} }

View File

@@ -0,0 +1,80 @@
/* Copyright (C) 2017 Erik Johansson <erik@ejohansson.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.health.openscale.junit;
import com.health.openscale.core.utils.DateTimeHelpers;
import org.junit.Test;
import java.util.Calendar;
import static org.junit.Assert.assertEquals;
public class DateTimeHelpersTest {
Calendar getDate(int year, int month, int day, int hour, int minute, int second, int ms) {
Calendar cal = Calendar.getInstance();
cal.set(year, month - 1, day, hour, minute, second);
cal.set(Calendar.MILLISECOND, ms);
return cal;
}
Calendar getDate(int year, int month, int day) {
return getDate(year, month, day, 0, 0, 0, 0);
}
@Test
public void daysBetween() throws Exception {
assertEquals(0,
DateTimeHelpers.daysBetween(
getDate(2017, 1, 1),
getDate(2017, 1, 1)));
assertEquals(0,
DateTimeHelpers.daysBetween(
getDate(2017, 1, 1, 12, 10, 10, 0),
getDate(2017, 1, 1, 12, 9, 0, 0)));
assertEquals(0,
DateTimeHelpers.daysBetween(
getDate(2017, 1, 1, 23, 59, 59, 999),
getDate(2017, 1, 1)));
assertEquals(1,
DateTimeHelpers.daysBetween(
getDate(2017, 1, 1),
getDate(2017, 1, 2)));
assertEquals(-1,
DateTimeHelpers.daysBetween(
getDate(2017, 1, 2),
getDate(2017, 1, 1)));
assertEquals(1,
DateTimeHelpers.daysBetween(
getDate(2017, 1, 1, 23, 59, 59, 999),
getDate(2017, 1, 2)));
assertEquals(29 - 10 + 4 * 30 + 6 * 31 + 2,
DateTimeHelpers.daysBetween(
getDate(2016, 2, 10, 1, 2, 3, 10),
getDate(2017, 1, 2)));
assertEquals(1 + 365 + 366,
DateTimeHelpers.daysBetween(
getDate(2014, 12, 31),
getDate(2017, 1, 1)));
}
}

View File

@@ -36,7 +36,10 @@
<string name="label_body_height">Körpergröße</string> <string name="label_body_height">Körpergröße</string>
<string name="label_comment">Kommentar</string> <string name="label_comment">Kommentar</string>
<string name="label_date">Datum</string> <string name="label_date">Datum</string>
<string name="label_days">Tage</string> <plurals name="label_days">
<item quantity="one">%d Tag</item>
<item quantity="other">%d Tage</item>
</plurals>
<string name="label_days_left">Tage übrig</string> <string name="label_days_left">Tage übrig</string>
<string name="label_delete">Löschen</string> <string name="label_delete">Löschen</string>
<string name="label_delete_all">Alles löschen</string> <string name="label_delete_all">Alles löschen</string>

View File

@@ -38,7 +38,10 @@
<string name="label_bone">Masa ósea</string> <string name="label_bone">Masa ósea</string>
<string name="label_smartUserAssign">Asignación inteligente de usuario</string> <string name="label_smartUserAssign">Asignación inteligente de usuario</string>
<string name="label_days">días</string> <plurals name="label_days">
<item quantity="one">%d día</item>
<item quantity="other">%d días</item>
</plurals>
<string name="label_measures">medidas</string> <string name="label_measures">medidas</string>
<string name="label_last_week">Últimos 7 días</string> <string name="label_last_week">Últimos 7 días</string>
<string name="label_last_month">Últimos 30 días</string> <string name="label_last_month">Últimos 30 días</string>

View File

@@ -33,7 +33,10 @@
<string name="label_whr">Rapport taille-hanches</string> <string name="label_whr">Rapport taille-hanches</string>
<string name="label_smartUserAssign">Affectation intelligente de l\'Utilisateur</string> <string name="label_smartUserAssign">Affectation intelligente de l\'Utilisateur</string>
<string name="label_days">jours</string> <plurals name="label_days">
<item quantity="one">%d jour</item>
<item quantity="other">%d jours</item>
</plurals>
<string name="label_measures">mesures</string> <string name="label_measures">mesures</string>
<string name="label_last_week">7 derniers jours</string> <string name="label_last_week">7 derniers jours</string>
<string name="label_last_month">30 derniers jours</string> <string name="label_last_month">30 derniers jours</string>

View File

@@ -23,7 +23,9 @@
<string name="label_body_height">身長</string> <string name="label_body_height">身長</string>
<string name="label_cancel">キャンセル</string> <string name="label_cancel">キャンセル</string>
<string name="label_comment">コメント</string> <string name="label_comment">コメント</string>
<string name="label_days"></string> <plurals name="label_days">
<item quantity="other">%d 日</item>
</plurals>
<string name="label_date">期日</string> <string name="label_date">期日</string>
<string name="label_delete">デリート</string> <string name="label_delete">デリート</string>
<string name="label_export">レコードのエクスポート</string> <string name="label_export">レコードのエクスポート</string>

View File

@@ -36,7 +36,9 @@
<string name="label_bone">Masa kostna</string> <string name="label_bone">Masa kostna</string>
<string name="label_smartUserAssign">Inteligente przypisywanie użytkowników</string> <string name="label_smartUserAssign">Inteligente przypisywanie użytkowników</string>
<string name="label_days">dni</string> <plurals name="label_days">
<item quantity="other">%d dni</item>
</plurals>
<string name="label_measures">pomiarów</string> <string name="label_measures">pomiarów</string>
<string name="label_last_week">Ostatnie 7 dni</string> <string name="label_last_week">Ostatnie 7 dni</string>
<string name="label_last_month">Ostatnie 30 dni</string> <string name="label_last_month">Ostatnie 30 dni</string>

View File

@@ -69,7 +69,9 @@
<string name="label_cancel">Cancelar</string> <string name="label_cancel">Cancelar</string>
<string name="label_comment">Comentário</string> <string name="label_comment">Comentário</string>
<string name="label_date">Data</string> <string name="label_date">Data</string>
<string name="label_days">dias</string> <plurals name="label_days">
<item quantity="other">%d dias</item>
</plurals>
<string name="label_days_left">Dias restantes</string> <string name="label_days_left">Dias restantes</string>
<string name="label_delete">Deletar</string> <string name="label_delete">Deletar</string>
<string name="label_delete_all">Deletar tudo</string> <string name="label_delete_all">Deletar tudo</string>

View File

@@ -31,7 +31,9 @@
<string name="label_whr">Pomer pásu a bokov</string> <string name="label_whr">Pomer pásu a bokov</string>
<string name="label_bone">Hmotnosť kostí</string> <string name="label_bone">Hmotnosť kostí</string>
<string name="label_smartUserAssign">Chytré priradenie používateľa</string> <string name="label_smartUserAssign">Chytré priradenie používateľa</string>
<string name="label_days">dni</string> <plurals name="label_days">
<item quantity="other">%d dni</item>
</plurals>
<string name="label_measures">merania</string> <string name="label_measures">merania</string>
<string name="label_last_week">Posledných 7 dní</string> <string name="label_last_week">Posledných 7 dní</string>
<string name="label_last_month">Posledných 30 dní</string> <string name="label_last_month">Posledných 30 dní</string>

View File

@@ -60,7 +60,10 @@
<string name="label_days_left">Dagar kvar</string> <string name="label_days_left">Dagar kvar</string>
<string name="label_goal_date_is">Måldatum är</string> <string name="label_goal_date_is">Måldatum är</string>
<string name="label_weight_difference">Viktskillnad</string> <string name="label_weight_difference">Viktskillnad</string>
<string name="label_days">dagar</string> <plurals name="label_days">
<item quantity="one">%d dag</item>
<item quantity="other">%d dagar</item>
</plurals>
<string name="label_measures">mätningar</string> <string name="label_measures">mätningar</string>
<string name="label_last_week">Senast 7 dagarna</string> <string name="label_last_week">Senast 7 dagarna</string>
<string name="label_last_month">Senast 30 dagarna</string> <string name="label_last_month">Senast 30 dagarna</string>

View File

@@ -37,7 +37,9 @@
<string name="label_bone">Kemik kütlesi</string> <string name="label_bone">Kemik kütlesi</string>
<string name="label_smartUserAssign">Akýllý kullanýcý atamasý</string> <string name="label_smartUserAssign">Akýllý kullanýcý atamasý</string>
<string name="label_days">Günler</string> <plurals name="label_days">
<item quantity="other">%d Günler</item>
</plurals>
<string name="label_measures">Ölçüler</string> <string name="label_measures">Ölçüler</string>
<string name="label_last_week">Son 7 Gün</string> <string name="label_last_week">Son 7 Gün</string>
<string name="label_last_month">Son 30 Gün</string> <string name="label_last_month">Son 30 Gün</string>

View File

@@ -38,7 +38,10 @@
<string name="label_bone">Bone mass</string> <string name="label_bone">Bone mass</string>
<string name="label_smartUserAssign">Smart User assignment</string> <string name="label_smartUserAssign">Smart User assignment</string>
<string name="label_days">days</string> <plurals name="label_days">
<item quantity="one">%d day</item>
<item quantity="other">%d days</item>
</plurals>
<string name="label_measures">measures</string> <string name="label_measures">measures</string>
<string name="label_last_week">Last 7 days</string> <string name="label_last_week">Last 7 days</string>
<string name="label_last_month">Last 30 days</string> <string name="label_last_month">Last 30 days</string>