Commit 74b861eaf2f639e167ab345ea5e1770704f05128
1 parent
8a2e7050
1 修复用户开始运动后,点击返回按钮,再次点击继续运动按钮后,提示正在运行另一赛事的问题
Showing
2 changed files
with
27 additions
and
13 deletions
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -77,6 +77,7 @@ public class RunMainFragmentView implements MvpView { |
| 77 | 77 | private TipDialog tipDialog; |
| 78 | 78 | //创建震动服务对象 |
| 79 | 79 | private Vibrator mVibrator; |
| 80 | + | |
| 80 | 81 | public RunMainFragmentView(RunMainFragment fragment) { |
| 81 | 82 | this.fragment = fragment; |
| 82 | 83 | } |
| ... | ... | @@ -136,26 +137,38 @@ public class RunMainFragmentView implements MvpView { |
| 136 | 137 | //设置数据 |
| 137 | 138 | if (userStepEntity != null) { |
| 138 | 139 | //设置赛事标题 |
| 139 | - if (TextUtils.isEmpty(userStepEntity.getStreetTitle())) { | |
| 140 | - StepUtil.setStreetTitle(getContext(), CommonInfo.getUserId(getContext()), runRaceDetailInfo.getTitle()); | |
| 140 | + if (TextUtils.isEmpty(userStepEntity.getStreetTitle()) || null == userStepEntity.getStreetTitle()) { | |
| 141 | + userStepEntity = StepUtil.getUserStepData(getContext(), uid); | |
| 142 | + if (null != userStepEntity) { | |
| 143 | + StepUtil.setStreetTitle(getContext(), CommonInfo.getUserId(getContext()), runRaceDetailInfo.getTitle()); | |
| 144 | + } | |
| 141 | 145 | } |
| 142 | 146 | //设置实体名字 |
| 143 | - if (TextUtils.isEmpty(userStepEntity.getQueryEntityName())) { | |
| 147 | + if (TextUtils.isEmpty(userStepEntity.getQueryEntityName()) || null == userStepEntity.getQueryEntityName()) { | |
| 144 | 148 | long startTime = Long.parseLong(runRaceDetailInfo.getStartTime()); |
| 145 | 149 | long endTime = Long.parseLong(runRaceDetailInfo.getEndTime()); |
| 146 | - StepUtil.setQueryTraceTime(getContext(), CommonInfo.getUserId(getContext()), startTime, endTime, runRaceDetailInfo.getEntityName()); | |
| 150 | + userStepEntity = StepUtil.getUserStepData(getContext(), uid); | |
| 151 | + if (null != userStepEntity) { | |
| 152 | + StepUtil.setQueryTraceTime(getContext(), CommonInfo.getUserId(getContext()), startTime, endTime, runRaceDetailInfo.getEntityName()); | |
| 153 | + } | |
| 147 | 154 | } |
| 148 | 155 | //设置开始时间和赛事id |
| 149 | - if (TextUtils.isEmpty(userStepEntity.getStreetId())) { | |
| 150 | - StepUtil.setStepStartData(getContext(), uid, TimeUtil.getNowTimeStamp(), CommonInfo.getStreetId(getContext())); | |
| 156 | + if (TextUtils.isEmpty(userStepEntity.getStreetId()) || null == userStepEntity.getStreetId()) { | |
| 157 | + userStepEntity = StepUtil.getUserStepData(getContext(), uid); | |
| 158 | + if (null != userStepEntity) { | |
| 159 | + StepUtil.setStepStartData(getContext(), uid, TimeUtil.getNowTimeStamp(), CommonInfo.getStreetId(getContext())); | |
| 160 | + } | |
| 151 | 161 | } |
| 152 | 162 | //设置终点经纬度 |
| 153 | - if (TextUtils.isEmpty(userStepEntity.getEndLatLng())) { | |
| 163 | + if (TextUtils.isEmpty(userStepEntity.getEndLatLng()) || null == userStepEntity.getEndLatLng()) { | |
| 154 | 164 | if (null != runRaceDetailInfo.getEndLatLng()) { |
| 155 | - //设置终点坐标 | |
| 156 | - userStepEntity.setEndLatLng(runRaceDetailInfo.getEndLatLng()); | |
| 157 | - //更新数据 | |
| 158 | - StepUtil.updateStepData(getContext(), userStepEntity); | |
| 165 | + userStepEntity = StepUtil.getUserStepData(getContext(), uid); | |
| 166 | + if (null != userStepEntity) { | |
| 167 | + //设置终点坐标 | |
| 168 | + userStepEntity.setEndLatLng(runRaceDetailInfo.getEndLatLng()); | |
| 169 | + //更新数据 | |
| 170 | + StepUtil.updateStepData(getContext(), userStepEntity); | |
| 171 | + } | |
| 159 | 172 | } |
| 160 | 173 | } |
| 161 | 174 | //设置终点经纬度 |
| ... | ... | @@ -163,7 +176,7 @@ public class RunMainFragmentView implements MvpView { |
| 163 | 176 | endLatLng = GsonUtil.GsonToBean(userStepEntity.getEndLatLng(), LatLng.class); |
| 164 | 177 | } |
| 165 | 178 | //设置步数 |
| 166 | - if (!TextUtils.isEmpty(userStepEntity.getStepCount())){ | |
| 179 | + if (!TextUtils.isEmpty(userStepEntity.getStepCount())) { | |
| 167 | 180 | //设置行走步数 |
| 168 | 181 | fragment.binding.tvStepCount.setText(userStepEntity.getStepCount()); |
| 169 | 182 | //设置行走公里 |
| ... | ... | @@ -898,6 +911,7 @@ public class RunMainFragmentView implements MvpView { |
| 898 | 911 | StepUtil.setFailData(context, failedEntity); |
| 899 | 912 | |
| 900 | 913 | } |
| 914 | + | |
| 901 | 915 | public void onStop() { |
| 902 | 916 | ChineseToSpeechUtil.destroy(); |
| 903 | 917 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/StepUtil.java
| ... | ... | @@ -258,8 +258,8 @@ public class StepUtil { |
| 258 | 258 | */ |
| 259 | 259 | public static void updateStepData(Context context, UserStepEntity userStepEntity) { |
| 260 | 260 | try { |
| 261 | + DbCore.init(context, dbName); | |
| 261 | 262 | if (userStepEntity != null) { |
| 262 | - DbCore.init(context, dbName); | |
| 263 | 263 | DbCore.getDaoSession().getUserStepEntityDao().update(userStepEntity); |
| 264 | 264 | } |
| 265 | 265 | } catch (Exception e) { | ... | ... |