mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-29 02:59:57 +02:00
Show days since current date in overview
I find it more logical to see how long ago a measurement was done, instead of how long ago since the last measurement was a measurement done. Fix a bug where the days since a measurement was calculated incorrectly if the measurement was done in the previous year. Convert the days label to plurals so that "day" is used when the measurement was done yesterday.
This commit is contained in:
@@ -54,7 +54,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.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
|
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
|
||||||
@@ -255,12 +255,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
max_i = scaleDataList.size();
|
max_i = scaleDataList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Calendar histDate = Calendar.getInstance();
|
Date now = new Date();
|
||||||
Calendar lastDate = Calendar.getInstance();
|
|
||||||
|
|
||||||
if (!scaleDataList.isEmpty()) {
|
|
||||||
lastDate.setTime(scaleDataList.get(0).getDateTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
scaleDataLastDays = new ArrayList<ScaleData>();
|
scaleDataLastDays = new ArrayList<ScaleData>();
|
||||||
|
|
||||||
@@ -285,11 +280,9 @@ 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());
|
int days = daysBetween(now, histData.getDateTime());
|
||||||
|
String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days);
|
||||||
long days = 0 - daysBetween(lastDate, histDate);
|
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,8 +421,9 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
pieChartLast.setPieChartData(pieChartData);
|
pieChartLast.setPieChartData(pieChartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long daysBetween(Calendar startDate, Calendar endDate) {
|
private int daysBetween(Date startDate, Date endDate) {
|
||||||
return startDate.get(Calendar.DAY_OF_YEAR) - endDate.get(Calendar.DAY_OF_YEAR);
|
final float msPerDay = 24 * 60 * 60 * 1000;
|
||||||
|
return Math.round((endDate.getTime() - startDate.getTime()) / msPerDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void btnOnClickInsertData()
|
public void btnOnClickInsertData()
|
||||||
|
@@ -34,7 +34,7 @@ import com.health.openscale.core.datatypes.ScaleUser;
|
|||||||
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 +99,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 +114,8 @@ 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();
|
int days = Math.max(0, daysBetween(new Date(), currentScaleUser.goal_date));
|
||||||
Calendar curDate = Calendar.getInstance();
|
txtGoalDayLeft.setText(getResources().getQuantityString(R.plurals.label_days, days, days));
|
||||||
goalDate.setTime(currentScaleUser.goal_date);
|
|
||||||
|
|
||||||
long days = daysBetween(curDate, goalDate);
|
|
||||||
txtGoalDayLeft.setText(days + " " + getResources().getString(R.string.label_days));
|
|
||||||
|
|
||||||
lastScaleData.setUserId(currentScaleUser.id);
|
lastScaleData.setUserId(currentScaleUser.id);
|
||||||
|
|
||||||
@@ -335,9 +331,8 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
|||||||
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) {
|
private int daysBetween(Date startDate, Date endDate) {
|
||||||
long end = endDate.getTimeInMillis();
|
final float msPerDay = 24 * 60 * 60 * 1000;
|
||||||
long start = startDate.getTimeInMillis();
|
return (int)Math.ceil((endDate.getTime() - startDate.getTime()) / msPerDay);
|
||||||
return TimeUnit.MILLISECONDS.toDays(Math.abs(end - start));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
Reference in New Issue
Block a user