Commit 74b24356307a54c84e8930e624060853319389a3
1 parent
4af31590
1 关闭数据库缓存功能
Showing
2 changed files
with
212 additions
and
134 deletions
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningMapFragmentView.java
| @@ -51,7 +51,6 @@ import com.cnlive.moudle.pedometer.utils.ButtonAnimUtil; | @@ -51,7 +51,6 @@ import com.cnlive.moudle.pedometer.utils.ButtonAnimUtil; | ||
| 51 | import com.cnlive.moudle.collectionTrace.utils.CollStepUtil; | 51 | import com.cnlive.moudle.collectionTrace.utils.CollStepUtil; |
| 52 | import com.cnlive.moudle.pedometer.utils.GsonUtil; | 52 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 53 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; | 53 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| 54 | -import com.cnlive.moudle.pedometer.utils.StepUtil; | ||
| 55 | import com.cnlive.moudle.pedometer.utils.TimeUtil; | 54 | import com.cnlive.moudle.pedometer.utils.TimeUtil; |
| 56 | import com.example.moudle_pedometer.R; | 55 | import com.example.moudle_pedometer.R; |
| 57 | import com.hannesdorfmann.mosby3.mvp.MvpView; | 56 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| @@ -71,7 +70,6 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener | @@ -71,7 +70,6 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener | ||
| 71 | private static int accuracyCircleStrokeColor; | 70 | private static int accuracyCircleStrokeColor; |
| 72 | private MyLocationData followMyLocation; | 71 | private MyLocationData followMyLocation; |
| 73 | boolean isFirstLoc = true; // 是否首次定位 | 72 | boolean isFirstLoc = true; // 是否首次定位 |
| 74 | - private MarkerOptions currentMark; | ||
| 75 | private Double lastX = 0.0; | 73 | private Double lastX = 0.0; |
| 76 | private int mCurrentDirection = 0; | 74 | private int mCurrentDirection = 0; |
| 77 | private float mCurrentAccracy; | 75 | private float mCurrentAccracy; |
| @@ -79,7 +77,6 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener | @@ -79,7 +77,6 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener | ||
| 79 | private LocationClient mLocClient; | 77 | private LocationClient mLocClient; |
| 80 | public MyLocationListenner myListener = new MyLocationListenner(); | 78 | public MyLocationListenner myListener = new MyLocationListenner(); |
| 81 | private int DEFULT_ZOOM = 17; | 79 | private int DEFULT_ZOOM = 17; |
| 82 | - private boolean isFirstLoadMap = true; | ||
| 83 | private Overlay currentLine; | 80 | private Overlay currentLine; |
| 84 | private List<LatLng> currentWalkPoints;//用户当前行走的线的集合 | 81 | private List<LatLng> currentWalkPoints;//用户当前行走的线的集合 |
| 85 | private CollUserStepEntity userStepEntity; | 82 | private CollUserStepEntity userStepEntity; |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/StepUtil.java
| @@ -36,12 +36,17 @@ public class StepUtil { | @@ -36,12 +36,17 @@ public class StepUtil { | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | public static void initDataBase(Context context, String uid) { | 38 | public static void initDataBase(Context context, String uid) { |
| 39 | - if (null == getUserStepData(context, uid)) { | ||
| 40 | - DbCore.init(context, dbName); | ||
| 41 | - UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 42 | - userStepEntity.setUserId(uid); | ||
| 43 | - DbCore.getDaoSession().getUserStepEntityDao().insert(userStepEntity); | 39 | + try { |
| 40 | + if (null == getUserStepData(context, uid)) { | ||
| 41 | + DbCore.init(context, dbName); | ||
| 42 | + UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 43 | + userStepEntity.setUserId(uid); | ||
| 44 | + DbCore.getDaoSession().getUserStepEntityDao().insert(userStepEntity); | ||
| 45 | + } | ||
| 46 | + } catch (Exception e) { | ||
| 47 | + Log.e(TAG, "initDataBase: " + e.toString()); | ||
| 44 | } | 48 | } |
| 49 | + | ||
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | /** | 52 | /** |
| @@ -51,11 +56,16 @@ public class StepUtil { | @@ -51,11 +56,16 @@ public class StepUtil { | ||
| 51 | * @param entity | 56 | * @param entity |
| 52 | */ | 57 | */ |
| 53 | public static void deleteTempSaveFailData(Context context, FailedEntity entity) { | 58 | public static void deleteTempSaveFailData(Context context, FailedEntity entity) { |
| 54 | - DbCore.init(context, dbName); | ||
| 55 | - if (entity != null && !TextUtils.isEmpty(entity.getUuid())) { | ||
| 56 | - DbCore.getDaoSession().getFailedEntityDao().deleteByKey(entity.getUuid()); | ||
| 57 | - Log.e(TAG, "deleteTempSaveFailData: 删除临时保存数据"); | 59 | + try { |
| 60 | + DbCore.init(context, dbName); | ||
| 61 | + if (entity != null && !TextUtils.isEmpty(entity.getUuid())) { | ||
| 62 | + DbCore.getDaoSession().getFailedEntityDao().deleteByKey(entity.getUuid()); | ||
| 63 | + Log.e(TAG, "deleteTempSaveFailData: 删除临时保存数据"); | ||
| 64 | + } | ||
| 65 | + } catch (Exception e) { | ||
| 66 | + Log.e(TAG, "deleteTempSaveFailData: " + e.toString()); | ||
| 58 | } | 67 | } |
| 68 | + | ||
| 59 | } | 69 | } |
| 60 | 70 | ||
| 61 | /** | 71 | /** |
| @@ -67,37 +77,49 @@ public class StepUtil { | @@ -67,37 +77,49 @@ public class StepUtil { | ||
| 67 | * @return | 77 | * @return |
| 68 | */ | 78 | */ |
| 69 | public static FailedEntity getTempSaveFailData(Context context, String uid, long userStartTime) { | 79 | public static FailedEntity getTempSaveFailData(Context context, String uid, long userStartTime) { |
| 70 | - DbCore.init(context, dbName); | ||
| 71 | - List<FailedEntity> list = DbCore.getDaoSession().getFailedEntityDao().queryBuilder().where(FailedEntityDao.Properties.Uid.eq(uid), FailedEntityDao.Properties.UserStartTime.eq(userStartTime)).list(); | ||
| 72 | - if (list != null && list.size() > 0) { | ||
| 73 | - if (list.get(0) == null) { | ||
| 74 | - return null; | ||
| 75 | - } else { | ||
| 76 | - return list.get(0); | 80 | + try { |
| 81 | + DbCore.init(context, dbName); | ||
| 82 | + List<FailedEntity> list = DbCore.getDaoSession().getFailedEntityDao().queryBuilder().where(FailedEntityDao.Properties.Uid.eq(uid), FailedEntityDao.Properties.UserStartTime.eq(userStartTime)).list(); | ||
| 83 | + if (list != null && list.size() > 0) { | ||
| 84 | + if (list.get(0) == null) { | ||
| 85 | + return null; | ||
| 86 | + } else { | ||
| 87 | + return list.get(0); | ||
| 88 | + } | ||
| 77 | } | 89 | } |
| 90 | + return null; | ||
| 91 | + } catch (Exception e) { | ||
| 92 | + Log.e(TAG, "getTempSaveFailData: " + e.toString()); | ||
| 93 | + return null; | ||
| 78 | } | 94 | } |
| 79 | - return null; | 95 | + |
| 80 | } | 96 | } |
| 81 | 97 | ||
| 82 | //获取上传失败列表 | 98 | //获取上传失败列表 |
| 83 | public static List<FailedEntity> getFailListData(Context context, String uid) { | 99 | public static List<FailedEntity> getFailListData(Context context, String uid) { |
| 84 | - DbCore.init(context, dbName); | ||
| 85 | - List<FailedEntity> list = DbCore.getDaoSession().getFailedEntityDao().queryBuilder().where(FailedEntityDao.Properties.Uid.eq(uid)).list(); | ||
| 86 | - return list; | 100 | + try { |
| 101 | + DbCore.init(context, dbName); | ||
| 102 | + List<FailedEntity> list = DbCore.getDaoSession().getFailedEntityDao().queryBuilder().where(FailedEntityDao.Properties.Uid.eq(uid)).list(); | ||
| 103 | + return list; | ||
| 104 | + } catch (Exception e) { | ||
| 105 | + Log.e(TAG, "getFailListData: " + e.toString()); | ||
| 106 | + return null; | ||
| 107 | + } | ||
| 108 | + | ||
| 87 | } | 109 | } |
| 88 | 110 | ||
| 89 | //设置失败数据 | 111 | //设置失败数据 |
| 90 | public static void setFailData(Context context, FailedEntity failedEntity) { | 112 | public static void setFailData(Context context, FailedEntity failedEntity) { |
| 91 | - DbCore.init(context, dbName); | ||
| 92 | - DbCore.getDaoSession().getFailedEntityDao().insert(failedEntity); | ||
| 93 | - } | 113 | + try { |
| 114 | + DbCore.init(context, dbName); | ||
| 115 | + DbCore.getDaoSession().getFailedEntityDao().insert(failedEntity); | ||
| 116 | + } catch (Exception e) { | ||
| 117 | + Log.e(TAG, "setFailData: " + e.toString()); | ||
| 118 | + } | ||
| 94 | 119 | ||
| 95 | - //设置运营失败数据 | ||
| 96 | - public static void setCollFailData(Context context, CollFailedEntity failedEntity) { | ||
| 97 | - DbCore.init(context, dbName); | ||
| 98 | - DbCore.getDaoSession().getCollFailedEntityDao().insert(failedEntity); | ||
| 99 | } | 120 | } |
| 100 | 121 | ||
| 122 | + | ||
| 101 | /** | 123 | /** |
| 102 | * 设置赛事标题 | 124 | * 设置赛事标题 |
| 103 | * | 125 | * |
| @@ -106,12 +128,17 @@ public class StepUtil { | @@ -106,12 +128,17 @@ public class StepUtil { | ||
| 106 | * @param streetTitle | 128 | * @param streetTitle |
| 107 | */ | 129 | */ |
| 108 | public static void setStreetTitle(Context context, String uid, String streetTitle) { | 130 | public static void setStreetTitle(Context context, String uid, String streetTitle) { |
| 109 | - if (getUserStepData(context, uid) != null) { | ||
| 110 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 111 | - entity.setStreetTitle(streetTitle); | ||
| 112 | - //更新数据 | ||
| 113 | - updateStepData(context, entity); | 131 | + try { |
| 132 | + if (getUserStepData(context, uid) != null) { | ||
| 133 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 134 | + entity.setStreetTitle(streetTitle); | ||
| 135 | + //更新数据 | ||
| 136 | + updateStepData(context, entity); | ||
| 137 | + } | ||
| 138 | + } catch (Exception e) { | ||
| 139 | + Log.e(TAG, "setStreetTitle: " + e.toString()); | ||
| 114 | } | 140 | } |
| 141 | + | ||
| 115 | } | 142 | } |
| 116 | 143 | ||
| 117 | 144 | ||
| @@ -123,12 +150,17 @@ public class StepUtil { | @@ -123,12 +150,17 @@ public class StepUtil { | ||
| 123 | * @param importStr | 150 | * @param importStr |
| 124 | */ | 151 | */ |
| 125 | public static void setImportPoints(Context context, String uid, String importStr) { | 152 | public static void setImportPoints(Context context, String uid, String importStr) { |
| 126 | - if (getUserStepData(context, uid) != null) { | ||
| 127 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 128 | - entity.setImportPoint(importStr); | ||
| 129 | - //更新数据 | ||
| 130 | - updateStepData(context, entity); | 153 | + try { |
| 154 | + if (getUserStepData(context, uid) != null) { | ||
| 155 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 156 | + entity.setImportPoint(importStr); | ||
| 157 | + //更新数据 | ||
| 158 | + updateStepData(context, entity); | ||
| 159 | + } | ||
| 160 | + } catch (Exception e) { | ||
| 161 | + Log.e(TAG, "setImportPoints: " + e.toString()); | ||
| 131 | } | 162 | } |
| 163 | + | ||
| 132 | } | 164 | } |
| 133 | 165 | ||
| 134 | /** | 166 | /** |
| @@ -139,17 +171,22 @@ public class StepUtil { | @@ -139,17 +171,22 @@ public class StepUtil { | ||
| 139 | * @param fenceId | 171 | * @param fenceId |
| 140 | */ | 172 | */ |
| 141 | public static void setFenceId(Context context, String uid, long fenceId) { | 173 | public static void setFenceId(Context context, String uid, long fenceId) { |
| 142 | - if (getUserStepData(context, uid) != null) { | ||
| 143 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 144 | - entity.setFenceId(fenceId); | ||
| 145 | - updateStepData(context, entity); | ||
| 146 | - } else { | ||
| 147 | - DbCore.init(context, dbName); | ||
| 148 | - UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 149 | - userStepEntity.setUserId(uid); | ||
| 150 | - userStepEntity.setFenceId(fenceId); | ||
| 151 | - DbCore.getDaoSession().getUserStepEntityDao().insert(userStepEntity); | 174 | + try { |
| 175 | + if (getUserStepData(context, uid) != null) { | ||
| 176 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 177 | + entity.setFenceId(fenceId); | ||
| 178 | + updateStepData(context, entity); | ||
| 179 | + } else { | ||
| 180 | + DbCore.init(context, dbName); | ||
| 181 | + UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 182 | + userStepEntity.setUserId(uid); | ||
| 183 | + userStepEntity.setFenceId(fenceId); | ||
| 184 | + DbCore.getDaoSession().getUserStepEntityDao().insert(userStepEntity); | ||
| 185 | + } | ||
| 186 | + } catch (Exception e) { | ||
| 187 | + Log.e(TAG, "setFenceId: " + e.toString()); | ||
| 152 | } | 188 | } |
| 189 | + | ||
| 153 | } | 190 | } |
| 154 | 191 | ||
| 155 | /** | 192 | /** |
| @@ -160,11 +197,16 @@ public class StepUtil { | @@ -160,11 +197,16 @@ public class StepUtil { | ||
| 160 | * @param continueTime | 197 | * @param continueTime |
| 161 | */ | 198 | */ |
| 162 | public static void setContinueTime(Context context, String uid, long continueTime) { | 199 | public static void setContinueTime(Context context, String uid, long continueTime) { |
| 163 | - if (getUserStepData(context, uid) != null) { | ||
| 164 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 165 | - entity.setContinueTime(continueTime); | ||
| 166 | - updateStepData(context, entity); | 200 | + try { |
| 201 | + if (getUserStepData(context, uid) != null) { | ||
| 202 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 203 | + entity.setContinueTime(continueTime); | ||
| 204 | + updateStepData(context, entity); | ||
| 205 | + } | ||
| 206 | + } catch (Exception e) { | ||
| 207 | + Log.e(TAG, "setContinueTime: " + e.toString()); | ||
| 167 | } | 208 | } |
| 209 | + | ||
| 168 | } | 210 | } |
| 169 | 211 | ||
| 170 | /** | 212 | /** |
| @@ -174,17 +216,22 @@ public class StepUtil { | @@ -174,17 +216,22 @@ public class StepUtil { | ||
| 174 | * @param endTime | 216 | * @param endTime |
| 175 | */ | 217 | */ |
| 176 | public static void setQueryTraceTime(Context context, String uid, long startTime, long endTime, String entityName) { | 218 | public static void setQueryTraceTime(Context context, String uid, long startTime, long endTime, String entityName) { |
| 177 | - if (getUserStepData(context, uid) != null) { | ||
| 178 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 179 | - //设置查询开始时间 | ||
| 180 | - entity.setQueryTraceStartTime(startTime); | ||
| 181 | - //设置查询结束时间 | ||
| 182 | - entity.setQueryTraceEndTime(endTime); | ||
| 183 | - //设置从服务器端获取的实体名称 | ||
| 184 | - entity.setQueryEntityName(entityName); | ||
| 185 | - //更新数据 | ||
| 186 | - updateStepData(context, entity); | 219 | + try { |
| 220 | + if (getUserStepData(context, uid) != null) { | ||
| 221 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 222 | + //设置查询开始时间 | ||
| 223 | + entity.setQueryTraceStartTime(startTime); | ||
| 224 | + //设置查询结束时间 | ||
| 225 | + entity.setQueryTraceEndTime(endTime); | ||
| 226 | + //设置从服务器端获取的实体名称 | ||
| 227 | + entity.setQueryEntityName(entityName); | ||
| 228 | + //更新数据 | ||
| 229 | + updateStepData(context, entity); | ||
| 230 | + } | ||
| 231 | + } catch (Exception e) { | ||
| 232 | + Log.e(TAG, "setQueryTraceTime: " + e.toString()); | ||
| 187 | } | 233 | } |
| 234 | + | ||
| 188 | } | 235 | } |
| 189 | 236 | ||
| 190 | /** | 237 | /** |
| @@ -210,11 +257,16 @@ public class StepUtil { | @@ -210,11 +257,16 @@ public class StepUtil { | ||
| 210 | * @param userStepEntity | 257 | * @param userStepEntity |
| 211 | */ | 258 | */ |
| 212 | public static void updateStepData(Context context, UserStepEntity userStepEntity) { | 259 | public static void updateStepData(Context context, UserStepEntity userStepEntity) { |
| 213 | - if (userStepEntity != null) { | ||
| 214 | - DbCore.init(context, dbName); | ||
| 215 | - DbCore.getDaoSession().getUserStepEntityDao().update(userStepEntity); | 260 | + try { |
| 261 | + if (userStepEntity != null) { | ||
| 262 | + DbCore.init(context, dbName); | ||
| 263 | + DbCore.getDaoSession().getUserStepEntityDao().update(userStepEntity); | ||
| 264 | + } | ||
| 265 | + } catch (Exception e) { | ||
| 266 | + Log.e(TAG, "updateStepData: " + e.toString()); | ||
| 216 | } | 267 | } |
| 217 | 268 | ||
| 269 | + | ||
| 218 | } | 270 | } |
| 219 | 271 | ||
| 220 | 272 | ||
| @@ -252,13 +304,18 @@ public class StepUtil { | @@ -252,13 +304,18 @@ public class StepUtil { | ||
| 252 | * @param uid | 304 | * @param uid |
| 253 | */ | 305 | */ |
| 254 | public static void clearRunData(Context context, String uid) { | 306 | public static void clearRunData(Context context, String uid) { |
| 255 | - DbCore.init(context, dbName); | ||
| 256 | - List<UserStepEntity> list = DbCore.getDaoSession().getUserStepEntityDao().queryBuilder().where(UserStepEntityDao.Properties.UserId.eq(uid)).list(); | ||
| 257 | - if (list != null && list.size() > 0) { | ||
| 258 | - Log.e(TAG, "clearRunData:删除用户逻辑数据 " + list.size()); | ||
| 259 | - DbCore.getDaoSession().getUserStepEntityDao().delete(list.get(0)); | ||
| 260 | - DbCore.getDaoSession().getUserStepEntityDao().detachAll(); | 307 | + try { |
| 308 | + DbCore.init(context, dbName); | ||
| 309 | + List<UserStepEntity> list = DbCore.getDaoSession().getUserStepEntityDao().queryBuilder().where(UserStepEntityDao.Properties.UserId.eq(uid)).list(); | ||
| 310 | + if (list != null && list.size() > 0) { | ||
| 311 | + Log.e(TAG, "clearRunData:删除用户逻辑数据 " + list.size()); | ||
| 312 | + DbCore.getDaoSession().getUserStepEntityDao().delete(list.get(0)); | ||
| 313 | + DbCore.getDaoSession().getUserStepEntityDao().detachAll(); | ||
| 314 | + } | ||
| 315 | + } catch (Exception e) { | ||
| 316 | + Log.e(TAG, "clearRunData: " + e.toString()); | ||
| 261 | } | 317 | } |
| 318 | + | ||
| 262 | } | 319 | } |
| 263 | 320 | ||
| 264 | /** | 321 | /** |
| @@ -269,17 +326,23 @@ public class StepUtil { | @@ -269,17 +326,23 @@ public class StepUtil { | ||
| 269 | * @return | 326 | * @return |
| 270 | */ | 327 | */ |
| 271 | public static UserStepEntity getUserStepData(Context context, String uid) { | 328 | public static UserStepEntity getUserStepData(Context context, String uid) { |
| 272 | - if (!TextUtils.isEmpty(uid)) { | ||
| 273 | - DbCore.init(context, dbName); | ||
| 274 | - List<UserStepEntity> list = DbCore.getDaoSession().getUserStepEntityDao().queryBuilder().where(UserStepEntityDao.Properties.UserId.eq(uid)).list(); | ||
| 275 | - if (list != null && list.size() > 0) { | ||
| 276 | - return list.get(0); | 329 | + try { |
| 330 | + if (!TextUtils.isEmpty(uid)) { | ||
| 331 | + DbCore.init(context, dbName); | ||
| 332 | + List<UserStepEntity> list = DbCore.getDaoSession().getUserStepEntityDao().queryBuilder().where(UserStepEntityDao.Properties.UserId.eq(uid)).list(); | ||
| 333 | + if (list != null && list.size() > 0) { | ||
| 334 | + return list.get(0); | ||
| 335 | + } else { | ||
| 336 | + return null; | ||
| 337 | + } | ||
| 277 | } else { | 338 | } else { |
| 278 | return null; | 339 | return null; |
| 279 | } | 340 | } |
| 280 | - } else { | 341 | + } catch (Exception e) { |
| 342 | + Log.e(TAG, "getUserStepData: " + e.toString()); | ||
| 281 | return null; | 343 | return null; |
| 282 | } | 344 | } |
| 345 | + | ||
| 283 | } | 346 | } |
| 284 | 347 | ||
| 285 | /** | 348 | /** |
| @@ -290,34 +353,26 @@ public class StepUtil { | @@ -290,34 +353,26 @@ public class StepUtil { | ||
| 290 | * @return | 353 | * @return |
| 291 | */ | 354 | */ |
| 292 | public static CollUserStepEntity getCollUserStepData(Context context, String uid) { | 355 | public static CollUserStepEntity getCollUserStepData(Context context, String uid) { |
| 293 | - if (!TextUtils.isEmpty(uid)) { | ||
| 294 | - DbCore.init(context, dbName); | ||
| 295 | - List<CollUserStepEntity> list = DbCore.getDaoSession().getCollUserStepEntityDao().queryBuilder().where(CollUserStepEntityDao.Properties.UserId.eq(uid)).list(); | ||
| 296 | - if (list != null && list.size() > 0) { | ||
| 297 | - return list.get(0); | 356 | + try { |
| 357 | + if (!TextUtils.isEmpty(uid)) { | ||
| 358 | + DbCore.init(context, dbName); | ||
| 359 | + List<CollUserStepEntity> list = DbCore.getDaoSession().getCollUserStepEntityDao().queryBuilder().where(CollUserStepEntityDao.Properties.UserId.eq(uid)).list(); | ||
| 360 | + if (list != null && list.size() > 0) { | ||
| 361 | + return list.get(0); | ||
| 362 | + } else { | ||
| 363 | + return null; | ||
| 364 | + } | ||
| 298 | } else { | 365 | } else { |
| 299 | return null; | 366 | return null; |
| 300 | } | 367 | } |
| 301 | - } else { | 368 | + } catch (Exception e) { |
| 369 | + Log.e(TAG, "getCollUserStepData: " + e.toString()); | ||
| 302 | return null; | 370 | return null; |
| 303 | } | 371 | } |
| 304 | - } | ||
| 305 | - | ||
| 306 | - /** | ||
| 307 | - * 设置用户数据 | ||
| 308 | - * | ||
| 309 | - * @param context | ||
| 310 | - * @param uid | ||
| 311 | - * @return | ||
| 312 | - */ | ||
| 313 | - public static void setUserStepData(Context context, String uid, UserStepEntity userStepEntity) { | ||
| 314 | - if (getUserStepData(context, uid) != null) { | ||
| 315 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 316 | - } else { | ||
| 317 | 372 | ||
| 318 | - } | ||
| 319 | } | 373 | } |
| 320 | 374 | ||
| 375 | + | ||
| 321 | /** | 376 | /** |
| 322 | * 初始化计步相关数据 | 377 | * 初始化计步相关数据 |
| 323 | * | 378 | * |
| @@ -327,20 +382,25 @@ public class StepUtil { | @@ -327,20 +382,25 @@ public class StepUtil { | ||
| 327 | * @param streetId | 382 | * @param streetId |
| 328 | */ | 383 | */ |
| 329 | public static void setStepStartData(Context context, String uid, long startStamp, String streetId) { | 384 | public static void setStepStartData(Context context, String uid, long startStamp, String streetId) { |
| 330 | - if (getUserStepData(context, uid) != null) { | ||
| 331 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 332 | - entity.setStartTimeStamp(startStamp); | ||
| 333 | - entity.setStreetId(streetId); | ||
| 334 | - //更新数据 | ||
| 335 | - updateStepData(context, entity); | ||
| 336 | - } else { | ||
| 337 | - //创建数据 | ||
| 338 | - UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 339 | - userStepEntity.setUserId(uid); | ||
| 340 | - userStepEntity.setStartTimeStamp(startStamp); | ||
| 341 | - userStepEntity.setStreetId(streetId); | ||
| 342 | - insertStepData(context, userStepEntity); | 385 | + try { |
| 386 | + if (getUserStepData(context, uid) != null) { | ||
| 387 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 388 | + entity.setStartTimeStamp(startStamp); | ||
| 389 | + entity.setStreetId(streetId); | ||
| 390 | + //更新数据 | ||
| 391 | + updateStepData(context, entity); | ||
| 392 | + } else { | ||
| 393 | + //创建数据 | ||
| 394 | + UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 395 | + userStepEntity.setUserId(uid); | ||
| 396 | + userStepEntity.setStartTimeStamp(startStamp); | ||
| 397 | + userStepEntity.setStreetId(streetId); | ||
| 398 | + insertStepData(context, userStepEntity); | ||
| 399 | + } | ||
| 400 | + } catch (Exception e) { | ||
| 401 | + Log.e(TAG, "setStepStartData: " + e.toString()); | ||
| 343 | } | 402 | } |
| 403 | + | ||
| 344 | } | 404 | } |
| 345 | 405 | ||
| 346 | 406 | ||
| @@ -352,18 +412,23 @@ public class StepUtil { | @@ -352,18 +412,23 @@ public class StepUtil { | ||
| 352 | * @param time | 412 | * @param time |
| 353 | */ | 413 | */ |
| 354 | public static void setChronometerBase(Context context, String uid, long time) { | 414 | public static void setChronometerBase(Context context, String uid, long time) { |
| 355 | - if (getUserStepData(context, uid) != null) { | ||
| 356 | - UserStepEntity entity = getUserStepData(context, uid); | ||
| 357 | - entity.setChronometerBase(time); | ||
| 358 | - //更新数据 | ||
| 359 | - updateStepData(context, entity); | ||
| 360 | - } else { | ||
| 361 | - //创建数据 | ||
| 362 | - UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 363 | - userStepEntity.setUserId(uid); | ||
| 364 | - userStepEntity.setChronometerBase(time); | ||
| 365 | - insertStepData(context, userStepEntity); | 415 | + try { |
| 416 | + if (getUserStepData(context, uid) != null) { | ||
| 417 | + UserStepEntity entity = getUserStepData(context, uid); | ||
| 418 | + entity.setChronometerBase(time); | ||
| 419 | + //更新数据 | ||
| 420 | + updateStepData(context, entity); | ||
| 421 | + } else { | ||
| 422 | + //创建数据 | ||
| 423 | + UserStepEntity userStepEntity = new UserStepEntity(); | ||
| 424 | + userStepEntity.setUserId(uid); | ||
| 425 | + userStepEntity.setChronometerBase(time); | ||
| 426 | + insertStepData(context, userStepEntity); | ||
| 427 | + } | ||
| 428 | + } catch (Exception e) { | ||
| 429 | + Log.e(TAG, "setChronometerBase: " + e.toString()); | ||
| 366 | } | 430 | } |
| 431 | + | ||
| 367 | } | 432 | } |
| 368 | 433 | ||
| 369 | /** | 434 | /** |
| @@ -373,8 +438,13 @@ public class StepUtil { | @@ -373,8 +438,13 @@ public class StepUtil { | ||
| 373 | * @param userStepEntity | 438 | * @param userStepEntity |
| 374 | */ | 439 | */ |
| 375 | public static void insertStepData(Context context, UserStepEntity userStepEntity) { | 440 | public static void insertStepData(Context context, UserStepEntity userStepEntity) { |
| 376 | - DbCore.init(context, dbName); | ||
| 377 | - DbCore.getDaoSession().getUserStepEntityDao().insert(userStepEntity); | 441 | + try { |
| 442 | + DbCore.init(context, dbName); | ||
| 443 | + DbCore.getDaoSession().getUserStepEntityDao().insert(userStepEntity); | ||
| 444 | + } catch (Exception e) { | ||
| 445 | + Log.e(TAG, "insertStepData: " + e.toString()); | ||
| 446 | + } | ||
| 447 | + | ||
| 378 | } | 448 | } |
| 379 | 449 | ||
| 380 | 450 | ||
| @@ -386,12 +456,18 @@ public class StepUtil { | @@ -386,12 +456,18 @@ public class StepUtil { | ||
| 386 | * @return | 456 | * @return |
| 387 | */ | 457 | */ |
| 388 | public static int getUserPauseCount(Context context, String uid) { | 458 | public static int getUserPauseCount(Context context, String uid) { |
| 389 | - UserStepEntity userStepEntity = getUserStepData(context, uid); | ||
| 390 | - if (userStepEntity != null) { | ||
| 391 | - return userStepEntity.getPauseCount(); | ||
| 392 | - } else { | 459 | + try { |
| 460 | + UserStepEntity userStepEntity = getUserStepData(context, uid); | ||
| 461 | + if (userStepEntity != null) { | ||
| 462 | + return userStepEntity.getPauseCount(); | ||
| 463 | + } else { | ||
| 464 | + return -1; | ||
| 465 | + } | ||
| 466 | + } catch (Exception e) { | ||
| 467 | + Log.e(TAG, "getUserPauseCount: " + e.toString()); | ||
| 393 | return -1; | 468 | return -1; |
| 394 | } | 469 | } |
| 470 | + | ||
| 395 | } | 471 | } |
| 396 | 472 | ||
| 397 | /** | 473 | /** |
| @@ -400,12 +476,17 @@ public class StepUtil { | @@ -400,12 +476,17 @@ public class StepUtil { | ||
| 400 | * @param context | 476 | * @param context |
| 401 | */ | 477 | */ |
| 402 | public static void setUserFinishTimeStamp(Context context, String uid) { | 478 | public static void setUserFinishTimeStamp(Context context, String uid) { |
| 403 | - UserStepEntity userStepEntity = getUserStepData(context, uid); | ||
| 404 | - if (userStepEntity != null) { | ||
| 405 | - userStepEntity.setFinishTimeStamp(TimeUtil.getNowTimeStamp()); | ||
| 406 | - //更新 | ||
| 407 | - updateStepData(context, userStepEntity); | 479 | + try { |
| 480 | + UserStepEntity userStepEntity = getUserStepData(context, uid); | ||
| 481 | + if (userStepEntity != null) { | ||
| 482 | + userStepEntity.setFinishTimeStamp(TimeUtil.getNowTimeStamp()); | ||
| 483 | + //更新 | ||
| 484 | + updateStepData(context, userStepEntity); | ||
| 485 | + } | ||
| 486 | + } catch (Exception e) { | ||
| 487 | + Log.e(TAG, "setUserFinishTimeStamp: " + e.toString()); | ||
| 408 | } | 488 | } |
| 489 | + | ||
| 409 | } | 490 | } |
| 410 | 491 | ||
| 411 | /** | 492 | /** |