Commit cbb3898ac15266c44ba2760008e1f413375f93e8
1 parent
524c7ab6
1 完成全部成绩详情页
Showing
6 changed files
with
190 additions
and
46 deletions
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/ALLScoreDetailFragmentPresenter.java
| 1 | 1 | package com.cnlive.moudle.pedometer.frame.presenter; |
| 2 | 2 | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.text.TextUtils; | |
| 5 | +import android.widget.Toast; | |
| 6 | + | |
| 7 | +import com.baidu.mapapi.model.LatLng; | |
| 8 | +import com.baidu.trace.LBSTraceClient; | |
| 9 | +import com.baidu.trace.model.SortType; | |
| 10 | +import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; | |
| 3 | 11 | import com.cnlive.moudle.pedometer.frame.view.ALLScoreDetailFragmentView; |
| 12 | +import com.cnlive.moudle.pedometer.model.Constant; | |
| 13 | +import com.cnlive.moudle.pedometer.model.RunningFinishBean; | |
| 14 | +import com.cnlive.moudle.pedometer.sql.entity.FailedEntity; | |
| 15 | +import com.cnlive.moudle.pedometer.ui.widget.SelectDialog; | |
| 16 | +import com.cnlive.moudle.pedometer.utils.GsonUtil; | |
| 17 | +import com.cnlive.moudle.pedometer.utils.MyMapUtil; | |
| 18 | +import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; | |
| 19 | +import com.example.moudle_pedometer.R; | |
| 4 | 20 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 5 | 21 | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 6 | 24 | public class ALLScoreDetailFragmentPresenter extends MvpBasePresenter<ALLScoreDetailFragmentView> { |
| 25 | + private LBSTraceClient mClient = null; | |
| 26 | + private SelectDialog uploadFailDialog; | |
| 27 | + private SelectDialog failTraceDialog; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 查询当前用户历史轨迹 | |
| 31 | + */ | |
| 32 | + public void queryHistoryTrace(Activity context, RunningFinishBean runningFinishBean) { | |
| 33 | + QMUITipDialogUtil.loadingDialog(context, "正在获取轨迹信息,请稍后", false); | |
| 34 | + //查询当前用户的历史轨迹 | |
| 35 | + long startTime = 0; | |
| 36 | + if (!TextUtils.isEmpty(runningFinishBean.getUserStartTime())) { | |
| 37 | + startTime = Long.parseLong(runningFinishBean.getUserStartTime()); | |
| 38 | + } | |
| 39 | + //获取当前的时间戳(秒) | |
| 40 | + long endTime = 0; | |
| 41 | + if (!TextUtils.isEmpty(runningFinishBean.getUserFinishTime())){ | |
| 42 | + endTime = Long.parseLong(runningFinishBean.getUserFinishTime()); | |
| 43 | + } | |
| 44 | + //获取当前的实体名称 | |
| 45 | + String entityName = CommonInfo.getUserId(context); | |
| 46 | + if (mClient == null) { | |
| 47 | + mClient = new LBSTraceClient(context); | |
| 48 | + } | |
| 49 | + MyMapUtil.queryHistoryTrace(context, mClient, entityName, startTime, endTime, new MyMapUtil.CallBack() { | |
| 50 | + @Override | |
| 51 | + public void success(List<LatLng> resultPoints) { | |
| 52 | + if (resultPoints != null) { | |
| 53 | + if (getView() != null) { | |
| 54 | + QMUITipDialogUtil.dismessDialog(); | |
| 55 | + if (resultPoints.size() > 1) { | |
| 56 | + MyMapUtil.drawHistoryTrack(context, getView().baiduMap, resultPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end); | |
| 57 | + //设置地图自动缩放 | |
| 58 | + MyMapUtil.setMapAutoZoom(getView().baiduMap, resultPoints, -2f); | |
| 59 | + } | |
| 60 | + | |
| 61 | + } | |
| 62 | + } | |
| 63 | + //查询失败 | |
| 64 | + else { | |
| 65 | + if (getView() == null) { | |
| 66 | + return; | |
| 67 | + } | |
| 68 | + QMUITipDialogUtil.dismessDialog(); | |
| 69 | + | |
| 70 | + if (failTraceDialog == null) { | |
| 71 | + failTraceDialog = new SelectDialog(context, "获取轨迹失败,是否重试?", "重试", new SelectDialog.DialogInterface() { | |
| 72 | + @Override | |
| 73 | + public void onClick(SelectDialog dialog) { | |
| 74 | + dialog.dismiss(); | |
| 75 | + queryHistoryTrace(context, runningFinishBean); | |
| 76 | + } | |
| 77 | + }, "取消", new SelectDialog.DialogInterface() { | |
| 78 | + @Override | |
| 79 | + public void onClick(SelectDialog dialog) { | |
| 80 | + dialog.dismiss(); | |
| 81 | + | |
| 82 | + } | |
| 83 | + }); | |
| 84 | + failTraceDialog.setCanceledOnTouchOutside(false); | |
| 85 | + failTraceDialog.setCancelable(false); | |
| 86 | + if (!failTraceDialog.isShowing()) { | |
| 87 | + failTraceDialog.show(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + } else { | |
| 91 | + if (!failTraceDialog.isShowing()) { | |
| 92 | + failTraceDialog.show(); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | + } | |
| 97 | + }); | |
| 98 | + | |
| 99 | + } | |
| 7 | 100 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/ALLScoreDetailFragmentView.java
| ... | ... | @@ -10,6 +10,7 @@ import com.baidu.mapapi.map.UiSettings; |
| 10 | 10 | import com.cnlive.moudle.pedometer.model.RunningFinishBean; |
| 11 | 11 | import com.cnlive.moudle.pedometer.ui.fragment.ALLScoreDetailFragment; |
| 12 | 12 | import com.cnlive.moudle.pedometer.utils.TimeUtil; |
| 13 | +import com.example.moudle_pedometer.R; | |
| 13 | 14 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 14 | 15 | |
| 15 | 16 | /** |
| ... | ... | @@ -50,6 +51,25 @@ public class ALLScoreDetailFragmentView implements MvpView { |
| 50 | 51 | |
| 51 | 52 | fragment.binding.includeFinishRunRoute.tvTimer.setText(TimeUtil.stampToChronometer(Long.parseLong(runningFinishBean.getEmployTime()))); |
| 52 | 53 | } |
| 54 | + //设置完成时间 | |
| 55 | + if (!TextUtils.isEmpty(runningFinishBean.getUserFinishTime())) { | |
| 56 | + fragment.binding.includeFinishUserInfo.tvDate.setText(TimeUtil.getStampToTime(Long.parseLong(runningFinishBean.getUserFinishTime())*1000, "yyyy/MM/dd HH:mm")); | |
| 57 | + } | |
| 58 | + //设置起点 | |
| 59 | + fragment.binding.includeFinishRunRoute.tvStartPoint.setText(runningFinishBean.getStartPoint()); | |
| 60 | + //设置终点 | |
| 61 | + fragment.binding.includeFinishRunRoute.tvEndPoint.setText(runningFinishBean.getEndPoint()); | |
| 62 | + //设置是否完成 | |
| 63 | + //未完成 | |
| 64 | + if ("1".equals(runningFinishBean.getIsFinish())) { | |
| 65 | + fragment.binding.includeFinishRunRoute.tvFinishState.setText("路线完成"); | |
| 66 | + fragment.binding.includeFinishRunRoute.tvFinishState.setTextColor(getContext().getResources().getColor(R.color.green_round)); | |
| 67 | + } | |
| 68 | + //完成 | |
| 69 | + else if ("0".equals(runningFinishBean.getIsFinish())){ | |
| 70 | + fragment.binding.includeFinishRunRoute.tvFinishState.setText("路线未完成"); | |
| 71 | + fragment.binding.includeFinishRunRoute.tvFinishState.setTextColor(getContext().getResources().getColor(R.color.red)); | |
| 72 | + } | |
| 53 | 73 | //设置日期 |
| 54 | 74 | //点击返回按钮 |
| 55 | 75 | fragment.binding.flBack.setOnClickListener(new View.OnClickListener() { | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -237,8 +237,10 @@ public class RunMainFragmentView implements MvpView { |
| 237 | 237 | fragment.binding.chronometer.setFormat("00:00:01"); |
| 238 | 238 | fragment.binding.chronometer.setBase(SystemClock.elapsedRealtime()); |
| 239 | 239 | } |
| 240 | - //设置继续运动时间 | |
| 241 | - StepUtil.setContinueTime(getContext(), uid, TimeUtil.getNowTimeStamp()); | |
| 240 | + if (userStepEntity.getContinueTime() == 0) { | |
| 241 | + //设置继续运动时间 | |
| 242 | + StepUtil.setContinueTime(getContext(), uid, TimeUtil.getNowTimeStamp()); | |
| 243 | + } | |
| 242 | 244 | //因为进来以后就运动了,所以需要改变状态 |
| 243 | 245 | CommonInfo.setIsPauseState(getContext(), false); |
| 244 | 246 | //重新设置开始时间 |
| ... | ... | @@ -290,8 +292,10 @@ public class RunMainFragmentView implements MvpView { |
| 290 | 292 | fragment.binding.flContinue.setOnClickListener(new View.OnClickListener() { |
| 291 | 293 | @Override |
| 292 | 294 | public void onClick(View view) { |
| 293 | - //设置继续运动时间 | |
| 294 | - StepUtil.setContinueTime(getContext(), uid, TimeUtil.getNowTimeStamp()); | |
| 295 | + if (userStepEntity.getContinueTime() == 0) { | |
| 296 | + //设置继续运动时间 | |
| 297 | + StepUtil.setContinueTime(getContext(), uid, TimeUtil.getNowTimeStamp()); | |
| 298 | + } | |
| 295 | 299 | //设置继续标志 |
| 296 | 300 | CommonInfo.setIsPauseState(getContext(), false); |
| 297 | 301 | //继续记录轨迹 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningMapFragmentView.java
| ... | ... | @@ -86,6 +86,50 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 86 | 86 | |
| 87 | 87 | public void initView() { |
| 88 | 88 | currentPoints = new ArrayList<>(); |
| 89 | + initMap(); | |
| 90 | + //返回键 | |
| 91 | + fragment.binding.flBack.setOnTouchListener(new View.OnTouchListener() { | |
| 92 | + @Override | |
| 93 | + public boolean onTouch(View view, MotionEvent motionEvent) { | |
| 94 | + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { | |
| 95 | + ButtonAnimUtil.setViewZoomIn(fragment.binding.flBack); | |
| 96 | + } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { | |
| 97 | + ButtonAnimUtil.setViewZoomOut(fragment.binding.flBack); | |
| 98 | + } | |
| 99 | + return false; | |
| 100 | + } | |
| 101 | + }); | |
| 102 | + //返回键点击事件 | |
| 103 | + fragment.binding.flBack.setOnClickListener(new View.OnClickListener() { | |
| 104 | + @Override | |
| 105 | + public void onClick(View view) { | |
| 106 | + fragment.getActivity().finish(); | |
| 107 | + } | |
| 108 | + }); | |
| 109 | + //重新定位 | |
| 110 | + fragment.binding.flLocation.setOnTouchListener(new View.OnTouchListener() { | |
| 111 | + @Override | |
| 112 | + public boolean onTouch(View view, MotionEvent motionEvent) { | |
| 113 | + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { | |
| 114 | + ButtonAnimUtil.setViewZoomIn(fragment.binding.flLocation); | |
| 115 | + } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { | |
| 116 | + ButtonAnimUtil.setViewZoomOut(fragment.binding.flLocation); | |
| 117 | + } | |
| 118 | + return false; | |
| 119 | + } | |
| 120 | + }); | |
| 121 | + //重新定位功能 | |
| 122 | + fragment.binding.flLocation.setOnClickListener(new View.OnClickListener() { | |
| 123 | + @Override | |
| 124 | + public void onClick(View view) { | |
| 125 | + mLocClient.restart(); | |
| 126 | + isFirstLoc = true; | |
| 127 | + } | |
| 128 | + }); | |
| 129 | + | |
| 130 | + } | |
| 131 | + | |
| 132 | + public void initMap() { | |
| 89 | 133 | this.mMapView = fragment.binding.mapView; |
| 90 | 134 | if (baiduMap == null) { |
| 91 | 135 | baiduMap = mMapView.getMap(); |
| ... | ... | @@ -158,46 +202,6 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 158 | 202 | public void onMapLoaded() { |
| 159 | 203 | } |
| 160 | 204 | }); |
| 161 | - //返回键 | |
| 162 | - fragment.binding.flBack.setOnTouchListener(new View.OnTouchListener() { | |
| 163 | - @Override | |
| 164 | - public boolean onTouch(View view, MotionEvent motionEvent) { | |
| 165 | - if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { | |
| 166 | - ButtonAnimUtil.setViewZoomIn(fragment.binding.flBack); | |
| 167 | - } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { | |
| 168 | - ButtonAnimUtil.setViewZoomOut(fragment.binding.flBack); | |
| 169 | - } | |
| 170 | - return false; | |
| 171 | - } | |
| 172 | - }); | |
| 173 | - //返回键点击事件 | |
| 174 | - fragment.binding.flBack.setOnClickListener(new View.OnClickListener() { | |
| 175 | - @Override | |
| 176 | - public void onClick(View view) { | |
| 177 | - fragment.getActivity().finish(); | |
| 178 | - } | |
| 179 | - }); | |
| 180 | - //重新定位 | |
| 181 | - fragment.binding.flLocation.setOnTouchListener(new View.OnTouchListener() { | |
| 182 | - @Override | |
| 183 | - public boolean onTouch(View view, MotionEvent motionEvent) { | |
| 184 | - if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { | |
| 185 | - ButtonAnimUtil.setViewZoomIn(fragment.binding.flLocation); | |
| 186 | - } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { | |
| 187 | - ButtonAnimUtil.setViewZoomOut(fragment.binding.flLocation); | |
| 188 | - } | |
| 189 | - return false; | |
| 190 | - } | |
| 191 | - }); | |
| 192 | - //重新定位功能 | |
| 193 | - fragment.binding.flLocation.setOnClickListener(new View.OnClickListener() { | |
| 194 | - @Override | |
| 195 | - public void onClick(View view) { | |
| 196 | - mLocClient.restart(); | |
| 197 | - isFirstLoc = true; | |
| 198 | - } | |
| 199 | - }); | |
| 200 | - | |
| 201 | 205 | } |
| 202 | 206 | |
| 203 | 207 | public void drawServerStreetTrace(List<LatLng> trackPoints) { | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
| ... | ... | @@ -184,6 +184,8 @@ public class StepService extends Service implements SensorEventListener { |
| 184 | 184 | showStartForegroundNotification(); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | + private static int retryIndex = 0; | |
| 188 | + | |
| 187 | 189 | private void initTrace() { |
| 188 | 190 | if (mClient == null) { |
| 189 | 191 | mClient = new LBSTraceClient(getApplicationContext()); |
| ... | ... | @@ -243,6 +245,7 @@ public class StepService extends Service implements SensorEventListener { |
| 243 | 245 | if (StatusCodes.SUCCESS == errorNo || StatusCodes.START_TRACE_NETWORK_CONNECT_FAILED <= errorNo) { |
| 244 | 246 | //开始进行采集 |
| 245 | 247 | if (mClient != null) { |
| 248 | + retryIndex = 0; | |
| 246 | 249 | mClient.startGather(traceListener); |
| 247 | 250 | Toast.makeText(getApplicationContext(), "开启轨迹服务", Toast.LENGTH_LONG).show(); |
| 248 | 251 | boolean isFirstSendNotification = CommonInfo.getIsFirstStepSendTraceTip(getApplicationContext()); |
| ... | ... | @@ -262,6 +265,14 @@ public class StepService extends Service implements SensorEventListener { |
| 262 | 265 | CommonInfo.setIsFirstStepSendTraceTip(getApplicationContext(), false); |
| 263 | 266 | EventBus.getDefault().post(new MessageEvent(Constant.START_TRACE_GATHER_FAIL, "")); |
| 264 | 267 | } |
| 268 | + if (retryIndex < 4) { | |
| 269 | + //重新开启服务 | |
| 270 | + if (mClient != null) { | |
| 271 | + mClient.startTrace(mTrace, traceListener); | |
| 272 | + retryIndex++; | |
| 273 | + } | |
| 274 | + } | |
| 275 | + | |
| 265 | 276 | } |
| 266 | 277 | } |
| 267 | 278 | |
| ... | ... | @@ -300,7 +311,16 @@ public class StepService extends Service implements SensorEventListener { |
| 300 | 311 | @Override |
| 301 | 312 | public void onStartGatherCallback(int errorNo, String message) { |
| 302 | 313 | if (StatusCodes.SUCCESS == errorNo || StatusCodes.GATHER_STARTED == errorNo) { |
| 314 | + retryIndex = 0; | |
| 303 | 315 | Toast.makeText(getApplicationContext(), "开始采集", Toast.LENGTH_LONG).show(); |
| 316 | + } else { | |
| 317 | + //重新开启采集 | |
| 318 | + if (retryIndex < 4) { | |
| 319 | + if (null != mClient) { | |
| 320 | + mClient.startGather(traceListener); | |
| 321 | + } | |
| 322 | + retryIndex++; | |
| 323 | + } | |
| 304 | 324 | } |
| 305 | 325 | } |
| 306 | 326 | |
| ... | ... | @@ -703,7 +723,7 @@ public class StepService extends Service implements SensorEventListener { |
| 703 | 723 | CURRENT_STEP = Integer.parseInt(userStepEntity.getStepCount()); |
| 704 | 724 | } |
| 705 | 725 | } |
| 706 | - Log.e(TAG, "initTodayData: 初始化当前步数" + CURRENT_STEP); | |
| 726 | +// Log.e(TAG, "initTodayData: 初始化当前步数" + CURRENT_STEP); | |
| 707 | 727 | if (mStepCount != null) { |
| 708 | 728 | mStepCount.setSteps(CURRENT_STEP); |
| 709 | 729 | } |
| ... | ... | @@ -711,7 +731,7 @@ public class StepService extends Service implements SensorEventListener { |
| 711 | 731 | } |
| 712 | 732 | |
| 713 | 733 | private void updateNotification() { |
| 714 | - Log.e(TAG, "updateNotification: 当前步数:" + CURRENT_STEP); | |
| 734 | +// Log.e(TAG, "updateNotification: 当前步数:" + CURRENT_STEP); | |
| 715 | 735 | EventBus.getDefault().post(new MessageEvent(Constant.SERVICE_STEP_COUNT_UPDATE, CURRENT_STEP)); |
| 716 | 736 | updateSpeedStepFlag = false; |
| 717 | 737 | // remoteViews = new RemoteViews(getPackageName(), R.layout.custom_step_notification); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/ALLScoreDetailFragment.java
| ... | ... | @@ -49,6 +49,9 @@ public class ALLScoreDetailFragment extends QMUIFragment<ALLScoreDetailFragmentV |
| 49 | 49 | if (getMvpView() != null) { |
| 50 | 50 | getMvpView().initMap(); |
| 51 | 51 | getMvpView().initView(runningFinishBean); |
| 52 | + if (getPresenter() != null) { | |
| 53 | + getPresenter().queryHistoryTrace(getActivity(), runningFinishBean); | |
| 54 | + } | |
| 52 | 55 | } |
| 53 | 56 | } |
| 54 | 57 | } | ... | ... |