fixed calorie record issues.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 27 Aug 2021 03:32:57 +0000 (11:32 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 27 Aug 2021 03:32:57 +0000 (11:32 +0800)
app/src/main/aidl/com/ic/aidl/ped/IPedRemoteService.aidl
app/src/main/java/com/ic/work/db/PedInjection.java
app/src/main/java/com/ic/work/hardware/PedBaseRunnable.java
app/src/main/java/com/ic/work/process/PedProcess.java
app/src/main/java/com/ic/work/utils/SPUtils.java

index a876160..27c61f0 100644 (file)
@@ -17,4 +17,5 @@ interface IPedRemoteService {
     void queryPedRecord();
     void syncPedHeightSetting(in int height);
     void syncPedWeightSetting(in int weight);
+
 }
index 7322921..d3a3e89 100644 (file)
@@ -1,14 +1,10 @@
 package com.ic.work.db;
 
-import android.content.Context;
-
 import com.ic.work.db.dao.PedDao;
 import com.ic.work.db.entity.PedEntity;
 
-import org.threeten.bp.LocalDate;
 import org.threeten.bp.OffsetDateTime;
 
-import java.util.Date;
 import java.util.List;
 
 public class PedInjection {
@@ -48,7 +44,7 @@ public class PedInjection {
         getPedDao().updatePedEntity(entity.getId(),
                 entity.getPedNumber(),
                 entity.getPedDistance(),
-                entity.getPedDistance());
+                entity.getPedCalorie());
     }
 
     public int queryDBPedCount() {
index 4ab6ba4..d9d242d 100644 (file)
@@ -66,22 +66,9 @@ public class PedBaseRunnable {
                 Uri.parse(SensorDataService.SETTINGS), contentValues
         );
         //处理距离
-        ContentValues contentValuesDistance = new ContentValues();
-        contentValuesDistance.put("s_key", "sport_distance_value");
-        contentValuesDistance.put("s_value", getDistanceValue(number));
-        mContext.getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValuesDistance);
         entity.setPedDistance(getDistanceValue(number));
         entity.setPedCalorie(getCalorieValue(number));
         mPedInjection.updateDBPedDate(entity);
-        //更新卡路里
-        //保存一份到数据库中
-        BigDecimal bg = new BigDecimal(PedUtil.calcConsumeEnergy(mHeight, mWeight, number));
-        String value = String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
-        ContentValues contentValuesCalorie = new ContentValues();
-        contentValuesCalorie.put("s_key", "sport_calorie_value");
-        contentValuesCalorie.put("s_value", value);
-        ICLogger.d("sport_calorie_value == > " + value);
-        mContext.getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValuesCalorie);
     }
 
     protected void updateCountDB(int ped, OffsetDateTime dateTime) {
@@ -99,18 +86,25 @@ public class PedBaseRunnable {
             if (todayPed != null && todayPed.size() > 0) {
                 //3.如果数据中有当天的数据,并更新数据
                 if (ped > 0 && ped > todayPed.get(0).getPedNumber()) {
-                    todayPed.get(0).setPedNumber(ped);
+                    PedEntity pedEntity = todayPed.get(0);
+                    pedEntity.setPedNumber(ped);
+                    String calorieValue = getCalorieValue(ped);
+                    ICLogger.d("calorieValue ==> " + calorieValue);
+                    ICLogger.d("ped ==> " + ped);
+                    pedEntity.setPedCalorie(calorieValue);
+                    String distanceValue = getDistanceValue(ped);
+                    ICLogger.d("distanceValue ==> " + distanceValue);
+                    pedEntity.setPedDistance(distanceValue);
+                    mPedInjection.updateDBPedDate(pedEntity);
                 }
             } else {
                 //直接 插入今天的数据
                 insertDBPedEntity(ped, dateTime, size);
             }
-            updateDBPedEntity(todayPed.get(0));
         }
     }
 
     private PedEntity createEntity(int number, OffsetDateTime date) {
-
         PedEntity entity = new PedEntity();
         entity.setPedNumber(number);
         entity.setPedDistance(getDistanceValue(number));
@@ -132,7 +126,12 @@ public class PedBaseRunnable {
 
     private String getDistanceValue(int number) {
         BigDecimal bg = new BigDecimal(PedUtil.calcDistanceBySteps(mHeight, number));
-        return String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
+        String value = String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
+        ContentValues contentValuesDistance = new ContentValues();
+        contentValuesDistance.put("s_key", "sport_distance_value");
+        contentValuesDistance.put("s_value", value);
+        mContext.getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValuesDistance);
+        return value;
     }
 
     protected OffsetDateTime getOffsetDateTime() {
index dca3123..7afd262 100644 (file)
@@ -101,9 +101,7 @@ public class PedProcess {
             for (int i = 0; i < N; i++) {
                 mCallbacks.getBroadcastItem(i).updatePedRecord(record);
             }
-        } catch (NullPointerException e) {
-            IcLog.e(TAG, "", e);
-        } catch (RemoteException er) {
+        } catch (Exception er) {
             IcLog.e(TAG, "", er);
         } finally {
             try {
index 2cc5ccb..f11cc10 100644 (file)
@@ -20,7 +20,7 @@ public class SPUtils {
         return getSP(context).getInt(Ped_Weight, 75);
     }
 
-    public static void setPedHeightSP(Context context,int height) {
+    public static void setPedHeightSP(Context context, int height) {
         SharedPreferences.Editor editor = getSP(context).edit();
         if (editor != null) {
             editor.putInt(Ped_Weight, height);
@@ -28,11 +28,19 @@ public class SPUtils {
         }
     }
 
-    public static  void setPedWighttSP(Context context,int weight) {
+    public static void setPedWighttSP(Context context, int weight) {
         SharedPreferences.Editor editor = getSP(context).edit();
         if (editor != null) {
             editor.putInt(Ped_Weight, weight);
             editor.apply();
         }
     }
+
+    public static void setPedTargetSp(Context context, int stepCount) {
+        SharedPreferences.Editor editor = getSP(context).edit();
+        if (editor != null) {
+            editor.putInt(Ped_Weight, stepCount);
+            editor.apply();
+        }
+    }
 }