1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-05 01:37:03 +01:00

Xiaomi: Refactor daily parser slightly

This commit is contained in:
José Rebelo 2023-10-21 16:53:34 +01:00
parent d3eb69fcf7
commit acba91d3c5

View File

@ -74,10 +74,14 @@ public class DailyDetailsParser extends XiaomiActivityParser {
return false; return false;
} }
final Calendar timestamp = Calendar.getInstance();
timestamp.setTime(fileId.getTimestamp());
final List<XiaomiActivitySample> samples = new ArrayList<>(); final List<XiaomiActivitySample> samples = new ArrayList<>();
while (buf.position() < buf.limit()) { while (buf.position() < buf.limit()) {
final XiaomiActivitySample sample = new XiaomiActivitySample(); final XiaomiActivitySample sample = new XiaomiActivitySample();
sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000));
sample.setSteps(buf.getShort()); sample.setSteps(buf.getShort());
@ -95,12 +99,11 @@ public class DailyDetailsParser extends XiaomiActivityParser {
} }
samples.add(sample); samples.add(sample);
timestamp.add(Calendar.MINUTE, 1);
} }
// save all the samples that we got // save all the samples that we got
final Calendar timestamp = Calendar.getInstance();
timestamp.setTime(fileId.getTimestamp());
try (DBHandler handler = GBApplication.acquireDB()) { try (DBHandler handler = GBApplication.acquireDB()) {
final DaoSession session = handler.getDaoSession(); final DaoSession session = handler.getDaoSession();
@ -113,15 +116,10 @@ public class DailyDetailsParser extends XiaomiActivityParser {
for (final XiaomiActivitySample sample : samples) { for (final XiaomiActivitySample sample : samples) {
sample.setDevice(device); sample.setDevice(device);
sample.setUser(user); sample.setUser(user);
sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000));
sample.setProvider(sampleProvider); sample.setProvider(sampleProvider);
timestamp.add(Calendar.MINUTE, 1);
} }
sampleProvider.addGBActivitySamples(samples.toArray(new XiaomiActivitySample[0])); sampleProvider.addGBActivitySamples(samples.toArray(new XiaomiActivitySample[0]));
timestamp.add(Calendar.MINUTE, -1);
return true; return true;
} catch (final Exception e) { } catch (final Exception e) {
GB.toast(support.getContext(), "Error saving activity samples", Toast.LENGTH_LONG, GB.ERROR); GB.toast(support.getContext(), "Error saving activity samples", Toast.LENGTH_LONG, GB.ERROR);