Skip to content

Commit

Permalink
Merge pull request #101 from OrenZak/fix/using_consumed_wirtable_map
Browse files Browse the repository at this point in the history
[Android] fix: crash - using consumed WriteableMap
  • Loading branch information
Francesco-Voto authored Jun 12, 2021
2 parents b72cde4 + e545efc commit fd9c385
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions android/src/main/java/com/ovalmoney/fitness/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void onSuccess(DataReadResponse dataReadResponse) {
for (Bucket bucket : dataReadResponse.getBuckets()) {
List<DataSet> dataSets = bucket.getDataSets();
for (DataSet dataSet : dataSets) {
processDistance(dataSet, calories);
processCalories(dataSet, calories);
}
}
promise.resolve(calories);
Expand Down Expand Up @@ -402,7 +402,7 @@ public void getSleepAnalysis(Context context, double startDate, double endDate,
promise.reject(String.valueOf(FitnessError.ERROR_METHOD_NOT_AVAILABLE), "Method not available");
return;
}

SessionReadRequest request = new SessionReadRequest.Builder()
.readSessionsFromAllApps()
.read(DataType.TYPE_ACTIVITY_SEGMENT)
Expand All @@ -425,10 +425,8 @@ public boolean test(Session s) {
.collect(Collectors.toList());

WritableArray sleep = Arguments.createArray();

for (Object session : sleepSessions) {
List<DataSet> dataSets = response.getDataSet((Session) session);

for (DataSet dataSet : dataSets) {
processSleep(dataSet, (Session) session, sleep);
}
Expand All @@ -447,10 +445,9 @@ public void onFailure(@NonNull Exception e) {

private void processStep(DataSet dataSet, WritableArray map) {

WritableMap stepMap = Arguments.createMap();

for (DataPoint dp : dataSet.getDataPoints()) {
for(Field field : dp.getDataType().getFields()) {
WritableMap stepMap = Arguments.createMap();
stepMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
stepMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
stepMap.putDouble("quantity", dp.getValue(field).asInt());
Expand All @@ -461,10 +458,9 @@ private void processStep(DataSet dataSet, WritableArray map) {

private void processDistance(DataSet dataSet, WritableArray map) {

WritableMap distanceMap = Arguments.createMap();

for (DataPoint dp : dataSet.getDataPoints()) {
for(Field field : dp.getDataType().getFields()) {
WritableMap distanceMap = Arguments.createMap();
distanceMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
distanceMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
distanceMap.putDouble("quantity", dp.getValue(field).asFloat());
Expand All @@ -475,10 +471,9 @@ private void processDistance(DataSet dataSet, WritableArray map) {

private void processCalories(DataSet dataSet, WritableArray map) {

WritableMap caloryMap = Arguments.createMap();

for (DataPoint dp : dataSet.getDataPoints()) {
for(Field field : dp.getDataType().getFields()) {
WritableMap caloryMap = Arguments.createMap();
caloryMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
caloryMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
caloryMap.putDouble("quantity", dp.getValue(field).asFloat());
Expand All @@ -489,10 +484,9 @@ private void processCalories(DataSet dataSet, WritableArray map) {

private void processHeartRate(DataSet dataSet, WritableArray map) {

WritableMap heartRateMap = Arguments.createMap();

for (DataPoint dp : dataSet.getDataPoints()) {
for(Field field : dp.getDataType().getFields()) {
WritableMap heartRateMap = Arguments.createMap();
heartRateMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
heartRateMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
heartRateMap.putDouble("quantity", dp.getValue(field).asFloat());
Expand All @@ -503,10 +497,9 @@ private void processHeartRate(DataSet dataSet, WritableArray map) {

private void processSleep(DataSet dataSet, Session session, WritableArray map) {

WritableMap sleepMap = Arguments.createMap();

for (DataPoint dp : dataSet.getDataPoints()) {
for(Field field : dp.getDataType().getFields()) {
WritableMap sleepMap = Arguments.createMap();
sleepMap.putString("value", dp.getValue(field).asActivity());
sleepMap.putString("sourceId", session.getIdentifier());
sleepMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
Expand Down

0 comments on commit fd9c385

Please sign in to comment.