Commit fcce818fb393bc64bc9e4d087887e45e90a3705c
1 parent
03203b73
1.赛事详情
Showing
4 changed files
with
32 additions
and
20 deletions
config.gradle
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -5,6 +5,7 @@ import android.content.Intent; |
| 5 | 5 | import android.os.Handler; |
| 6 | 6 | import android.os.SystemClock; |
| 7 | 7 | import android.support.v4.content.ContextCompat; |
| 8 | +import android.text.TextUtils; | |
| 8 | 9 | import android.util.Log; |
| 9 | 10 | import android.view.MotionEvent; |
| 10 | 11 | import android.view.View; |
| ... | ... | @@ -181,7 +182,7 @@ public class RunMainFragmentView implements MvpView { |
| 181 | 182 | } |
| 182 | 183 | needWriteDataFlag = true; |
| 183 | 184 | //将当前计时器时间戳写入数据库 |
| 184 | - setSQLPauseTime(); | |
| 185 | + setSQLPauseTime(uid); | |
| 185 | 186 | //为了点击时可以显示缩放动画,这里延迟一个动画时间进行(包括放大和缩小) |
| 186 | 187 | handler.postDelayed(new Runnable() { |
| 187 | 188 | @Override |
| ... | ... | @@ -311,7 +312,7 @@ public class RunMainFragmentView implements MvpView { |
| 311 | 312 | StepService.mClient.stopGather(StepService.traceListener); |
| 312 | 313 | } |
| 313 | 314 | //将当前计时器时间戳写入数据库 |
| 314 | - setSQLPauseTime(); | |
| 315 | + setSQLPauseTime(uid); | |
| 315 | 316 | needWriteDataFlag = false; |
| 316 | 317 | ButtonAnimUtil.setViewHideZoomOut(fragment.binding.llPause); |
| 317 | 318 | handler.postDelayed(new Runnable() { |
| ... | ... | @@ -365,16 +366,19 @@ public class RunMainFragmentView implements MvpView { |
| 365 | 366 | }); |
| 366 | 367 | } |
| 367 | 368 | |
| 368 | - public void setSQLPauseTime() { | |
| 369 | + public void setSQLPauseTime(String id) { | |
| 369 | 370 | if (needWriteDataFlag) { |
| 370 | 371 | //将当前计时器时间戳写入数据库 |
| 371 | - UserStepEntity userStepEntity = StepUtil.getUserStepData(fragment.getActivity(), uid); | |
| 372 | - if (userStepEntity != null) { | |
| 373 | - userStepEntity.setPauseTimeStamp(fragment.binding.chronometer.getBase()); | |
| 374 | - //设置当前暂停的时间戳 | |
| 375 | - userStepEntity.setRecordTime(SystemClock.elapsedRealtime()); | |
| 376 | - //更新数据 | |
| 377 | - StepUtil.updateStepData(fragment.getActivity(), userStepEntity); | |
| 372 | +// String id = MySpHelper.getInstance(getContext(), Context.MODE_MULTI_PROCESS).getString("userId", ""); | |
| 373 | + if (!TextUtils.isEmpty(id)) { | |
| 374 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(fragment.getActivity(), uid); | |
| 375 | + if (userStepEntity != null) { | |
| 376 | + userStepEntity.setPauseTimeStamp(fragment.binding.chronometer.getBase()); | |
| 377 | + //设置当前暂停的时间戳 | |
| 378 | + userStepEntity.setRecordTime(SystemClock.elapsedRealtime()); | |
| 379 | + //更新数据 | |
| 380 | + StepUtil.updateStepData(fragment.getActivity(), userStepEntity); | |
| 381 | + } | |
| 378 | 382 | } |
| 379 | 383 | } |
| 380 | 384 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunMainFragment.java
| ... | ... | @@ -3,6 +3,7 @@ package com.cnlive.moudle.pedometer.ui.fragment; |
| 3 | 3 | import android.os.Bundle; |
| 4 | 4 | import android.os.Handler; |
| 5 | 5 | import android.support.annotation.Nullable; |
| 6 | +import android.text.TextUtils; | |
| 6 | 7 | import android.util.Log; |
| 7 | 8 | import android.view.View; |
| 8 | 9 | |
| ... | ... | @@ -23,7 +24,7 @@ import org.greenrobot.eventbus.ThreadMode; |
| 23 | 24 | |
| 24 | 25 | public class RunMainFragment extends QMUIFragment<RunMainFragmentView, RunMainFragmentPresenter, FragmentRunMainBinding> { |
| 25 | 26 | private final String TAG = "RunMainFragment"; |
| 26 | - | |
| 27 | + private String userId = "yangshuai"; | |
| 27 | 28 | |
| 28 | 29 | @Override |
| 29 | 30 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| ... | ... | @@ -54,7 +55,9 @@ public class RunMainFragment extends QMUIFragment<RunMainFragmentView, RunMainFr |
| 54 | 55 | super.onPause(); |
| 55 | 56 | //记录当前计时器相关数据 |
| 56 | 57 | if (getMvpView() != null) { |
| 57 | - getMvpView().setSQLPauseTime(); | |
| 58 | + if (!TextUtils.isEmpty(userId)) { | |
| 59 | + getMvpView().setSQLPauseTime(userId); | |
| 60 | + } | |
| 58 | 61 | } |
| 59 | 62 | } |
| 60 | 63 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/StepUtil.java
| 1 | 1 | package com.cnlive.moudle.pedometer.utils; |
| 2 | 2 | |
| 3 | 3 | import android.content.Context; |
| 4 | +import android.text.TextUtils; | |
| 4 | 5 | import android.util.Log; |
| 5 | 6 | |
| 6 | 7 | import com.cnlive.moudle.pedometer.model.Constant; |
| ... | ... | @@ -102,13 +103,17 @@ public class StepUtil { |
| 102 | 103 | } |
| 103 | 104 | |
| 104 | 105 | public static UserStepEntity getUserStepData(Context context, String uid) { |
| 105 | - DbCore.init(context, dbName); | |
| 106 | - DbCore.getDaoSession().getUserStepEntityDao().detachAll(); | |
| 107 | - DbCore.getDaoSession().clear(); | |
| 108 | - String CURRENT_DATE = getTodayDate(); | |
| 109 | - List<UserStepEntity> list = DbCore.getDaoSession().getUserStepEntityDao().queryBuilder().where(UserStepEntityDao.Properties.UserId.eq(uid), UserStepEntityDao.Properties.Date.eq(CURRENT_DATE)).list(); | |
| 110 | - if (list != null && list.size() > 0) { | |
| 111 | - return list.get(0); | |
| 106 | + if (!TextUtils.isEmpty(uid)) { | |
| 107 | + DbCore.init(context, dbName); | |
| 108 | + DbCore.getDaoSession().getUserStepEntityDao().detachAll(); | |
| 109 | + DbCore.getDaoSession().clear(); | |
| 110 | + String CURRENT_DATE = getTodayDate(); | |
| 111 | + List<UserStepEntity> list = DbCore.getDaoSession().getUserStepEntityDao().queryBuilder().where(UserStepEntityDao.Properties.UserId.eq(uid), UserStepEntityDao.Properties.Date.eq(CURRENT_DATE)).list(); | |
| 112 | + if (list != null && list.size() > 0) { | |
| 113 | + return list.get(0); | |
| 114 | + } else { | |
| 115 | + return null; | |
| 116 | + } | |
| 112 | 117 | } else { |
| 113 | 118 | return null; |
| 114 | 119 | } | ... | ... |