Merge pull request 'reduce DAO related merge conflicts for new devices' (#6294)

Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/6294
This commit is contained in:
José Rebelo
2026-06-17 23:33:58 +02:00
6 changed files with 200 additions and 22 deletions
@@ -0,0 +1,38 @@
/* Copyright (C) 2026 Thomas Kuehne
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.entities;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.model.HrvValueSample;
import nodomain.freeyourgadget.gadgetbridge.model.MetricSample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public abstract class AbstractMetricSample extends AbstractTimeSample implements MetricSample {
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimestampMillis(getTimestamp())) +
", metric=" + getMetric() +
", metricScore=" + getMetricScore() +
", metricExtra=" + getMetricExtra() +
", userId=" + getUserId() +
", deviceId=" + getDeviceId() +
"}";
}
}
@@ -0,0 +1,35 @@
/* Copyright (C) 2026 Thomas Kuehne
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.entities;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.model.SleepScoreSample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public abstract class AbstractSleepScoreSample extends AbstractTimeSample implements SleepScoreSample {
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimestampMillis(getTimestamp())) +
", sleepScore(=" + getSleepScore() +
", userId=" + getUserId() +
", deviceId=" + getDeviceId() +
"}";
}
}
@@ -0,0 +1,37 @@
/* Copyright (C) 2026 Thomas Kuehne
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.entities;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.model.SleepScoreSample;
import nodomain.freeyourgadget.gadgetbridge.model.SleepStageSample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public abstract class AbstractSleepStageSample extends AbstractTimeSample implements SleepStageSample {
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimestampMillis(getTimestamp())) +
", duration=" + getDuration() +
", stage=" + getStage() +
", userId=" + getUserId() +
", deviceId=" + getDeviceId() +
"}";
}
}
@@ -57,11 +57,11 @@ public interface MetricSample extends TimeSample {
setMetricExtra(extra);
}
@IntRange(from = 0, to = 12)
@IntRange(from = 0, to = 18)
int getMetricType();
/// use {@link #setMetric(Metric)} or {@link #setMetric(Metric, Double, Long)} instead
void setMetricType(@IntRange(from = 1, to = 12) int type);
/// use {@link #setMetric(Metric)} or {@link #setMetric(Metric, double, Long)} instead
void setMetricType(@IntRange(from = 1, to = 18) int type);
double getMetricScore();
@@ -109,13 +109,31 @@ public interface MetricSample extends TimeSample {
GENERIC_RESTING_METABOLIC_RATE(11, UNIT_KCAL_PER_DAY),
/// @see FitPhysiologicalMetrics#getMetMax()
GENERIC_MAXIMUM_OXYGEN_UPTAKE(12, UNIT_ML_KG_MIN),
/// Composite 0-100 sleep-quality score (Watson 2015 + Ohayon 2017).
/// metricScore: 0-100. metricExtra: total sleep duration seconds.
GENERIC_SLEEP_SCORE(13, UNIT_NONE),
/// Composite 0-100 readiness/recovery score (sleep + RHR + HRV deviations).
/// metricScore: 0-100. metricExtra: unused.
GENERIC_READINESS(14, UNIT_NONE),
/// Composite 0-100 daily energy / recovered-capacity score.
/// metricScore: 0-100. metricExtra: unused.
GENERIC_ENERGY(15, UNIT_NONE),
/// Running 0-100 body-battery / energy-reserve metric.
/// metricScore: 0-100. metricExtra: unused.
GENERIC_BODY_BATTERY(16, UNIT_NONE),
/// Edwards Training Impulse (TRIMP) — cumulative cardiac strain.
/// metricScore: TRIMP units. metricExtra: unused.
GENERIC_CARDIAC_STRAIN(17, UNIT_NONE),
/// Sleep Regularity Index (Phillips 2017) — 0-100, higher = more regular.
/// metricScore: 0-100. metricExtra: number of nights compared.
GENERIC_SLEEP_REGULARITY(18, UNIT_NONE),
;
final public int dbId;
public final int dbId;
/// @see nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries
/// @see ActivitySummaryEntries
@NonNull
final public String uomKey;
public final String uomKey;
Metric(int dbId, @NonNull String uomKey) {
this.dbId = dbId;
@@ -131,5 +149,9 @@ public interface MetricSample extends TimeSample {
}
return null;
}
public int getDbId() {
return dbId;
}
}
}
@@ -0,0 +1,22 @@
/* Copyright (C) 2026 Thomas Kuehne
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.model;
public interface SleepStageSample extends TimeSample {
int getDuration();
int getStage();
}