mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-02-10 23:57:31 +01:00
Move formatting of date periods to a shared file
This commit is contained in:
parent
e134a3bfbb
commit
08fec63892
@ -33,6 +33,7 @@ import java.util.Locale;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
|
|
||||||
public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<RespiratoryRatePeriodFragment.RespiratoryRateData> {
|
public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<RespiratoryRatePeriodFragment.RespiratoryRateData> {
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(BodyEnergyFragment.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(BodyEnergyFragment.class);
|
||||||
@ -121,10 +122,8 @@ public class RespiratoryRatePeriodFragment extends RespiratoryRateFragment<Respi
|
|||||||
protected RespiratoryRateData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
|
protected RespiratoryRateData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
|
||||||
Calendar day = Calendar.getInstance();
|
Calendar day = Calendar.getInstance();
|
||||||
Date to = new Date((long) this.getTSEnd() * 1000);
|
Date to = new Date((long) this.getTSEnd() * 1000);
|
||||||
Date from = DateUtils.addDays(to,-(TOTAL_DAYS - 1));
|
mDateView.setText(DateTimeUtils.formatDaysUntil(TOTAL_DAYS, getTSEnd()));
|
||||||
String toFormattedDate = new SimpleDateFormat("E, MMM dd").format(to);
|
|
||||||
String fromFormattedDate = new SimpleDateFormat("E, MMM dd").format(from);
|
|
||||||
mDateView.setText(fromFormattedDate + " - " + toFormattedDate);
|
|
||||||
day.setTime(to);
|
day.setTime(to);
|
||||||
List<RespiratoryRateDay> respiratoryRateDaysData = getMyRespiratoryRateDaysData(db, day, device);
|
List<RespiratoryRateDay> respiratoryRateDaysData = getMyRespiratoryRateDaysData(db, day, device);
|
||||||
return new RespiratoryRateData(respiratoryRateDaysData);
|
return new RespiratoryRateData(respiratoryRateDaysData);
|
||||||
|
@ -19,7 +19,6 @@ import com.github.mikephil.charting.data.BarDataSet;
|
|||||||
import com.github.mikephil.charting.data.BarEntry;
|
import com.github.mikephil.charting.data.BarEntry;
|
||||||
import com.github.mikephil.charting.formatter.ValueFormatter;
|
import com.github.mikephil.charting.formatter.ValueFormatter;
|
||||||
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -36,6 +35,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.workouts.WorkoutValueForm
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
|
|
||||||
public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.StepsData> {
|
public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.StepsData> {
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(BodyEnergyFragment.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(BodyEnergyFragment.class);
|
||||||
@ -164,12 +164,7 @@ public class StepsPeriodFragment extends StepsFragment<StepsPeriodFragment.Steps
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateChartsnUIThread(StepsData stepsData) {
|
protected void updateChartsnUIThread(StepsData stepsData) {
|
||||||
Date to = new Date((long) getTSEnd() * 1000);
|
mDateView.setText(DateTimeUtils.formatDaysUntil(TOTAL_DAYS, getTSEnd()));
|
||||||
Date from = DateUtils.addDays(to, -(TOTAL_DAYS - 1));
|
|
||||||
String toFormattedDate = new SimpleDateFormat("E, MMM dd").format(to);
|
|
||||||
String fromFormattedDate = new SimpleDateFormat("E, MMM dd").format(from);
|
|
||||||
mDateView.setText(fromFormattedDate + " - " + toFormattedDate);
|
|
||||||
|
|
||||||
stepsChart.setData(null);
|
stepsChart.setData(null);
|
||||||
|
|
||||||
List<BarEntry> entries = new ArrayList<>();
|
List<BarEntry> entries = new ArrayList<>();
|
||||||
|
@ -37,7 +37,6 @@ import com.github.mikephil.charting.formatter.ValueFormatter;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -221,11 +220,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
|||||||
awakeSleepTimeTextWrapper.setVisibility(View.GONE);
|
awakeSleepTimeTextWrapper.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Date to = new Date((long) this.getTSEnd() * 1000);
|
sleepDatesText.setText(DateTimeUtils.formatDaysUntil(TOTAL_DAYS, getTSEnd()));
|
||||||
Date from = DateUtils.addDays(to,-(TOTAL_DAYS - 1));
|
|
||||||
String toFormattedDate = new SimpleDateFormat("E, MMM dd").format(to);
|
|
||||||
String fromFormattedDate = new SimpleDateFormat("E, MMM dd").format(from);
|
|
||||||
sleepDatesText.setText(fromFormattedDate + " - " + toFormattedDate);
|
|
||||||
|
|
||||||
mBalanceView.setText(mcd.getWeekBeforeData().getBalanceMessage());
|
mBalanceView.setText(mcd.getWeekBeforeData().getBalanceMessage());
|
||||||
}
|
}
|
||||||
|
@ -126,14 +126,9 @@ public class WeightChartFragment extends AbstractChartFragment<WeightChartFragme
|
|||||||
chart.getXAxis().setValueFormatter(chartsData.getXValueFormatter());
|
chart.getXAxis().setValueFormatter(chartsData.getXValueFormatter());
|
||||||
chart.getXAxis().setAvoidFirstLastClipping(true);
|
chart.getXAxis().setAvoidFirstLastClipping(true);
|
||||||
chart.setData(chartsData.getData());
|
chart.setData(chartsData.getData());
|
||||||
|
textTimeSpan.setText(DateTimeUtils.formatDaysUntil(totalDays, getTSEnd()));
|
||||||
|
|
||||||
Date dateStart = DateTimeUtils.parseTimeStamp(getTSStart());
|
|
||||||
Date dateEnd = DateTimeUtils.parseTimeStamp(getTSEnd());
|
|
||||||
SimpleDateFormat format = new SimpleDateFormat("E, MMM dd");
|
|
||||||
WeightSample latestSample = chartsData.getLatestSample();
|
WeightSample latestSample = chartsData.getLatestSample();
|
||||||
|
|
||||||
textTimeSpan.setText(format.format(dateStart) + " - " + format.format(dateEnd));
|
|
||||||
|
|
||||||
if (latestSample != null)
|
if (latestSample != null)
|
||||||
textWeightLatest.setText(formatWeight(weightFromKg(latestSample.getWeightKg())));
|
textWeightLatest.setText(formatWeight(weightFromKg(latestSample.getWeightKg())));
|
||||||
|
|
||||||
|
@ -319,4 +319,12 @@ public class DateTimeUtils {
|
|||||||
|
|
||||||
return context.getString(R.string.unknown);
|
return context.getString(R.string.unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatDaysUntil(int days, int endTs) {
|
||||||
|
Date to = new Date((long) endTs * 1000);
|
||||||
|
Date from = org.apache.commons.lang3.time.DateUtils.addDays(to, - (days - 1));
|
||||||
|
String toFormattedDate = new SimpleDateFormat("E, MMM dd").format(to);
|
||||||
|
String fromFormattedDate = new SimpleDateFormat("E, MMM dd").format(from);
|
||||||
|
return fromFormattedDate + " - " + toFormattedDate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user