1.修复计步数据插入问题。
authorkfl_614 <kfl_614@163.com>
Fri, 10 Apr 2020 08:35:16 +0000 (16:35 +0800)
committerkfl_614 <kfl_614@163.com>
Fri, 10 Apr 2020 08:35:16 +0000 (16:35 +0800)
2.修复天气获取问题。
3.添加24点广播处理

12 files changed:
app/src/main/java/com/ic/work/MainActivity.java
app/src/main/java/com/ic/work/WorkService.java
app/src/main/java/com/ic/work/db/AppDatabase.java
app/src/main/java/com/ic/work/db/WeatherInjection.java
app/src/main/java/com/ic/work/db/entity/WeatherEntity.java
app/src/main/java/com/ic/work/hardware/BeforeDawnRunnable.java [new file with mode: 0644]
app/src/main/java/com/ic/work/hardware/PedBaseRunnable.java
app/src/main/java/com/ic/work/hardware/PedRunnable.java
app/src/main/java/com/ic/work/hardware/WritePedTotalRunnable.java [deleted file]
app/src/main/java/com/ic/work/weather/WeatherHelper.java
app/src/main/java/com/ic/work/weather/melon/SocketThread.java
app/version_code.properties

index e4e42ad..26d5ca0 100644 (file)
@@ -2,29 +2,20 @@ package com.ic.work;
 
 import androidx.appcompat.app.AppCompatActivity;
 
-import android.app.AlarmManager;
 import android.content.Context;
-import android.nfc.Tag;
 import android.os.Bundle;
 import android.os.Handler;
-import android.os.SystemClock;
 import android.widget.Button;
 
-import com.ic.work.hardware.WritePedTotalRunnable;
-import com.ic.work.utils.IcLog;
-import com.ic.work.utils.PedUtil;
+import com.ic.work.hardware.BeforeDawnRunnable;
 import com.ic.work.utils.ServiceUtil;
+import com.ic.work.weather.LocationState;
+import com.ic.work.weather.WeatherHelper;
 
-import org.threeten.bp.Instant;
-import org.threeten.bp.LocalDate;
-import org.threeten.bp.LocalDateTime;
-import org.threeten.bp.LocalTime;
 import org.threeten.bp.OffsetDateTime;
 import org.threeten.bp.ZoneId;
 import org.threeten.bp.format.DateTimeFormatter;
 
-import java.math.BigDecimal;
-
 public class MainActivity extends AppCompatActivity {
     private static final String TAG="MainActivity";
 
@@ -48,23 +39,22 @@ public class MainActivity extends AppCompatActivity {
         context = this;
         app =(WorkServiceApp) getApplication();
 
-        OffsetDateTime time = OffsetDateTime.now(ZoneId.systemDefault()).plusDays(1);
+        /**OffsetDateTime time = OffsetDateTime.now(ZoneId.systemDefault()).plusDays(1);
+
+        ThreadPoolManager.getInstance().execute(new BeforeDawnRunnable(
+                app.getApplicationContext(),
+                app.getRepository(),
+                app.getWeatherRepository(),
+                11000));
 
-        /**new Handler().postDelayed(new Runnable() {
+        new Handler().postDelayed(new Runnable() {
             @Override
             public void run() {
-                int count=0;
-                while (count<5){
-                    ThreadPoolManager.getInstance().execute(new WritePedTotalRunnable(
-                            context,
-                            app.getRepository(),
-                            3000+count));
-
-                    count++;
-                }
-
+                WeatherHelper  weather = new WeatherHelper();
+                LocationState  state = new LocationState(null,true,"深圳市");
+                weather.queryWeatherServerInfo(app.getWeatherRepository(),state);
             }
-        },1000);**/
+        },10000);**/
     }
 
 
index 63267d6..e111994 100644 (file)
@@ -20,11 +20,11 @@ import com.ic.work.event.PedSettingEvent;
 import com.ic.work.event.ThreadPoolEvent;
 import com.ic.work.event.WeatherAgainEvent;
 import com.ic.work.event.WeatherResultEvent;
+import com.ic.work.hardware.BeforeDawnRunnable;
 import com.ic.work.hardware.BloodRunnable;
 import com.ic.work.hardware.MessengerCoreService;
 import com.ic.work.hardware.PedRecordRunnable;
 import com.ic.work.hardware.PedRunnable;
-import com.ic.work.hardware.WritePedTotalRunnable;
 import com.ic.work.process.BloodProcess;
 import com.ic.work.process.PedProcess;
 import com.ic.work.process.WeatherProcess;
@@ -199,7 +199,7 @@ public class WorkService extends Service {
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void onMessageEvent(WeatherAgainEvent event) {
         if (mWeatherHelper != null) {
-            mWeatherHelper.startLocation(getApplicationContext(), false);
+            mWeatherHelper.startLocation(getApplicationContext());
         }
     }
 
@@ -207,7 +207,7 @@ public class WorkService extends Service {
     public void onMessageEvent(ThreadPoolEvent event) {
         switch (event.getEventType()) {
             case 1:
-                postPedThread();
+                ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(),mApp.getRepository()));
                 break;
             case 2:
                 ThreadPoolManager.getInstance().execute(new PedRecordRunnable(mApp.getRepository()));
@@ -256,10 +256,10 @@ public class WorkService extends Service {
                 }
                 switch (acyion) {
                     case GET_PED_ACTION:
-                        postPedThread();
+                        ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(),mApp.getRepository()));
                         break;
                     case Intent.ACTION_TIMEZONE_CHANGED:
-                        mWeatherHelper.startLocation(getApplicationContext(), true);
+                        mWeatherHelper.startLocation(getApplicationContext());
                         break;
                     case PED_FINISH_ACTION:
                         IcLog.i(TAG,"PED_FINISH_ACTION");
@@ -279,18 +279,11 @@ public class WorkService extends Service {
         }
         IcLog.i(TAG,"everyDayFinish");
         mFinishTime = LocalDateTime.now(ZoneId.systemDefault());
-
         //完成,需要把所有的今天的数据全部写入到数据中
-        mWeatherHelper.startLocation(getApplicationContext(), true);
-        int count = intent.getIntExtra(PED_TOTAL_KEY, 0);
-        ThreadPoolManager.getInstance().execute(new WritePedTotalRunnable(
+        ThreadPoolManager.getInstance().execute(new BeforeDawnRunnable(
                 mApp.getApplicationContext(),
                 mApp.getRepository(),
-                count));
-        postPedThread();
-    }
-
-    private void postPedThread() {
-        ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(), mApp.getRepository()));
+                mApp.getWeatherRepository(),
+                intent.getIntExtra(PED_TOTAL_KEY, 0)));
     }
 }
index 6b0a320..9f2fbbb 100644 (file)
@@ -12,7 +12,7 @@ import com.ic.work.db.dao.WeatherDao;
 import com.ic.work.db.entity.PedEntity;
 import com.ic.work.db.entity.WeatherEntity;
 
-@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 3,exportSchema = false)
+@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 4,exportSchema = false)
 @TypeConverters(TiviTypeConverters.class)
 public abstract  class AppDatabase extends RoomDatabase {
 
index 5447e42..55c17a2 100644 (file)
@@ -3,9 +3,6 @@ package com.ic.work.db;
 import com.ic.work.db.dao.WeatherDao;
 import com.ic.work.db.entity.WeatherEntity;
 
-import org.threeten.bp.LocalDate;
-import org.threeten.bp.OffsetDateTime;
-
 import java.util.List;
 
 public class WeatherInjection {
index 4ebdb1a..343cac0 100644 (file)
@@ -4,6 +4,8 @@ import androidx.room.Entity;
 import androidx.room.Index;
 import androidx.room.PrimaryKey;
 
+import org.threeten.bp.OffsetDateTime;
+
 
 @Entity(tableName = "icWeatherDb",
         indices = {@Index("id")})
@@ -18,6 +20,7 @@ public class WeatherEntity {
     private String temperatureDay;  // 白天温度 或 最低温度
     private String temperatureNight; // 晚上温度 或 最低温度
     private String updateTime;       // 更新时间
+    private OffsetDateTime queryTime;
 
     public int getId() {
         return id;
@@ -90,4 +93,12 @@ public class WeatherEntity {
     public void setUpdateTime(String updateTime) {
         this.updateTime = updateTime;
     }
+
+    public OffsetDateTime getQueryTime() {
+        return queryTime;
+    }
+
+    public void setQueryTime(OffsetDateTime queryTime) {
+        this.queryTime = queryTime;
+    }
 }
diff --git a/app/src/main/java/com/ic/work/hardware/BeforeDawnRunnable.java b/app/src/main/java/com/ic/work/hardware/BeforeDawnRunnable.java
new file mode 100644 (file)
index 0000000..818afdb
--- /dev/null
@@ -0,0 +1,35 @@
+package com.ic.work.hardware;
+
+import android.content.Context;
+
+import com.ic.work.db.PedInjection;
+import com.ic.work.db.WeatherInjection;
+import com.ic.work.utils.IcLog;
+
+public class BeforeDawnRunnable extends PedBaseRunnable implements Runnable {
+
+    private static final String TAG = "BeforeDawnRunnable";
+
+    private int mTotalPed;
+    private WeatherInjection weatherInjection;
+
+    public BeforeDawnRunnable(Context context, PedInjection pedInjection, WeatherInjection weatherInjection, int totalPed) {
+        super(context, pedInjection);
+        this.mTotalPed = totalPed;
+        this.weatherInjection = weatherInjection;
+    }
+
+    @Override
+    public void run() {
+
+        if(weatherInjection != null){
+            weatherInjection.deleteDBWeatherDate();
+        }
+
+        IcLog.i(TAG, "Before Ped Count" + mTotalPed);
+
+        updateCountDB(mTotalPed, getFrontOffsetDateTime());
+
+        updateCountDB(0,getOffsetDateTime());
+    }
+}
index f4e177c..bcbca8b 100644 (file)
@@ -25,19 +25,19 @@ public class PedBaseRunnable {
         mWeight = SPUtils.getPedWighttSP(context);
     }
 
-    protected boolean isCheckPedInjection() {
+    private boolean isCheckPedInjection() {
         return mPedInjection == null;
     }
 
-    protected int queryDBPedCount() {
+    private int queryDBPedCount() {
         return mPedInjection.queryDBPedCount();
     }
 
-    protected List<PedEntity>  queryTodayPedEntity(){
-        return mPedInjection.queryDBPedDate(getOffsetDateTime());
+    private List<PedEntity>  queryTimePedEntity(OffsetDateTime time){
+        return mPedInjection.queryDBPedDate(time);
     }
 
-    protected void insertDBPedEntity(int number, OffsetDateTime date, int size) {
+    private void insertDBPedEntity(int number, OffsetDateTime date, int size) {
         //判断 size 超过
         if (size >= 60) {
             //删除一条最早的数据
@@ -56,28 +56,27 @@ public class PedBaseRunnable {
         mPedInjection.updateDBPedDate(entity);
     }
 
-    protected void processPedCountDB(int pedCount){
+    protected void updateCountDB(int ped,OffsetDateTime dateTime){
         if (isCheckPedInjection()) {
             return;
         }
 
         int size = queryDBPedCount();
-
-        if (size == 0) {
+        if(size == 0){
             //如果数据库中无记录,把当前数据插入到数据库中
-            insertDBPedEntity(pedCount, getOffsetDateTime(), size);
-        } else {
-            //2.去查询数据中是否有当天的记录。
-            List<PedEntity> todayPed = queryTodayPedEntity();
+            insertDBPedEntity(ped, dateTime, size);
+        }else {
+            //2.去查询数据中是否有记录。
+            List<PedEntity> todayPed = queryTimePedEntity(dateTime);
             if (todayPed != null && todayPed.size() > 0) {
                 //3.如果数据中有当天的数据,并更新数据
-                if (pedCount > 0 && pedCount > todayPed.get(0).getPedNumber()) {
-                    todayPed.get(0).setPedNumber(pedCount);
+                if (ped > 0 && ped > todayPed.get(0).getPedNumber()) {
+                    todayPed.get(0).setPedNumber(ped);
                     updateDBPedEntity(todayPed.get(0));
                 }
             } else {
                 //直接 插入今天的数据
-                insertDBPedEntity(pedCount, getOffsetDateTime(), size);
+                insertDBPedEntity(ped, dateTime, size);
             }
         }
     }
@@ -107,7 +106,7 @@ public class PedBaseRunnable {
         return OffsetDateTime.now(ZoneId.systemDefault());
     }
 
-    private OffsetDateTime getFrontOffsetDateTime() {
+    protected OffsetDateTime getFrontOffsetDateTime() {
         return getOffsetDateTime().minusDays(1);
     }
 
index 1703dba..a489288 100644 (file)
@@ -3,45 +3,26 @@ package com.ic.work.hardware;
 import android.content.Context;
 
 import com.ic.work.db.PedInjection;
-import com.ic.work.db.entity.PedEntity;
 import com.ic.work.event.PedCountEvent;
 import com.ic.work.utils.HardwareUtils;
 import com.ic.work.utils.IcLog;
-import com.ic.work.utils.PedUtil;
 
 import org.greenrobot.eventbus.EventBus;
-import org.threeten.bp.OffsetDateTime;
-import org.threeten.bp.ZoneId;
-
-import java.math.BigDecimal;
-import java.util.List;
 
 public class PedRunnable extends PedBaseRunnable implements Runnable {
 
     private static final String TAG = "PedRunnable";
 
-    private boolean isRuning = false;
-
     public PedRunnable(Context context,PedInjection pedDB) {
        super(context,pedDB);
     }
 
     @Override
     public void run() {
-
-        if (isRuning) {
-            return;
-        }
-
-        isRuning = true;
-
-        //1.先获取一次当前的计步数
-        int currCount = HardwareUtils.getNdkStepCountValue();
-        IcLog.i(TAG, "Ped Count" + currCount);
+        int ped = HardwareUtils.getNdkStepCountValue();
+        IcLog.i(TAG, "Get Ped Count" + ped);
         //发送给主线程。主线更新数据UI
-        EventBus.getDefault().post(new PedCountEvent(currCount));
-        processPedCountDB(currCount);
-
-        isRuning = false;
+        EventBus.getDefault().post(new PedCountEvent(ped));
+        updateCountDB(ped,getOffsetDateTime());
     }
 }
diff --git a/app/src/main/java/com/ic/work/hardware/WritePedTotalRunnable.java b/app/src/main/java/com/ic/work/hardware/WritePedTotalRunnable.java
deleted file mode 100644 (file)
index 541931c..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.ic.work.hardware;
-
-import android.content.Context;
-import com.ic.work.db.PedInjection;
-
-public class WritePedTotalRunnable extends PedBaseRunnable implements Runnable {
-
-    private int mTotalPed;
-
-    public WritePedTotalRunnable(Context context, PedInjection pedDB, int totalPed) {
-        super(context, pedDB);
-        mTotalPed = totalPed;
-    }
-
-    @Override
-    public void run() {
-        processPedCountDB(mTotalPed);
-    }
-}
index dbe6f40..5073570 100644 (file)
@@ -8,26 +8,12 @@ import com.ic.work.ThreadPoolManager;
 import com.ic.work.db.WeatherInjection;
 import com.ic.work.weather.melon.SocketThread;
 
-import org.threeten.bp.Duration;
-import org.threeten.bp.LocalDateTime;
-import org.threeten.bp.ZoneId;
-
 public class WeatherHelper {
 
     private LocationHelper mLocation = null;
-    private LocationState locationState = null;
 
-    public void startLocation(Context context,boolean force) {
+    public void startLocation(Context context) {
         //如果已经定位成功
-        if(!force && locationState != null && !TextUtils.isEmpty(locationState.getCity())){
-            LocalDateTime oldTime = locationState.getTime();
-            LocalDateTime currTime = LocalDateTime.now(ZoneId.systemDefault());
-            Duration duration = Duration.between(currTime,oldTime);
-            if(duration.toDays() <1){
-                return;
-            }
-        }
-
         mLocation = new LocationHelper(context);
         mLocation.startLocationService();
     }
@@ -49,8 +35,6 @@ public class WeatherHelper {
             return;
         }
 
-        locationState = state;
-
         final String serverHost = "118.190.120.79";
         final int port = 11645;
 
index b58c2cc..13af573 100644 (file)
@@ -12,6 +12,7 @@ import com.ic.work.utils.IcLog;
 import org.greenrobot.eventbus.EventBus;
 import org.threeten.bp.LocalDate;
 import org.threeten.bp.OffsetDateTime;
+import org.threeten.bp.ZoneId;
 import org.threeten.bp.format.DateTimeFormatter;
 
 import java.util.ArrayList;
@@ -152,6 +153,8 @@ public class SocketThread implements Runnable {
                     weather.setUpdateTime(fJson.getString("date"));
                     db.setUpdateTime(fJson.getString("date"));
 
+                    db.setQueryTime(OffsetDateTime.now(ZoneId.systemDefault()));
+
                     if (BuildConfig.DEBUG) {
                         StringBuffer stringBuffer = new StringBuffer();
                         stringBuffer.append(weather.getStatusDay()).append("-").append(weather.getStatusNight())
@@ -167,7 +170,6 @@ public class SocketThread implements Runnable {
                 }
 
                 EventBus.getDefault().post(new WeatherResultEvent(wpList));
-                //插入数据库
                 weatherInjection.deleteDBWeatherDate();
                 weatherInjection.insertWeatherEntity(dbList);
             }
index ec13f8d..0f89718 100644 (file)
@@ -1,2 +1,2 @@
-#Tue Mar 31 18:36:21 CST 2020
-VERSION_CODE=19
+#Fri Apr 10 13:53:45 CST 2020
+VERSION_CODE=29