Commit 82781df1873da1bc48c916f4865b53899ad9ed4e

Authored by YangShuai
1 parent d0f5c5da

1 修复bug

config.gradle
... ... @@ -21,7 +21,7 @@ ext {
21 21 //编译方式
22 22 debug : false,
23 23 //版本号
24   - version: "0.8.9",
  24 + version: "0.9.0",
25 25 //Lib库前缀
26 26 packeg : "com.cnlive.module",
27 27 //Lib库名称
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/calorie/service/CalorieService.java
... ... @@ -54,6 +54,7 @@ import org.greenrobot.eventbus.Subscribe;
54 54 import org.greenrobot.eventbus.ThreadMode;
55 55  
56 56 import java.text.SimpleDateFormat;
  57 +import java.util.Calendar;
57 58 import java.util.Date;
58 59  
59 60 /**
... ... @@ -129,7 +130,7 @@ public class CalorieService extends Service implements SensorEventListener {
129 130 public void onCreate() {
130 131 super.onCreate();
131 132 init();
132   -// initBroadcastReceiver();
  133 + initBroadcastReceiver();
133 134 // if (!ServiceUtils.isServiceRunning(getApplicationContext(), "com.cnlive.moudle.pedometer.service.CollKeepLiveService")) {
134 135 // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
135 136 // startForegroundService(new Intent(getApplicationContext(), CollKeepLiveService.class));
... ... @@ -137,7 +138,6 @@ public class CalorieService extends Service implements SensorEventListener {
137 138 // startService(new Intent(getApplicationContext(), CollKeepLiveService.class));
138 139 // }
139 140 // }
140   - showStartForegroundNotification();
141 141 }
142 142  
143 143 private static int retryIndex = 0;
... ... @@ -181,7 +181,7 @@ public class CalorieService extends Service implements SensorEventListener {
181 181 private void showStartForegroundNotification() {
182 182 if (null == remoteViews) {
183 183 remoteViews = new RemoteViews(getPackageName(), R.layout.custom_step_notification);
184   - remoteViews.setImageViewResource(R.id.iv_icon,R.drawable.ic_icon);
  184 + remoteViews.setImageViewResource(R.id.iv_icon, R.drawable.ic_icon);
185 185 }
186 186 NotificationChannel channel = null;
187 187 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
... ... @@ -312,13 +312,21 @@ public class CalorieService extends Service implements SensorEventListener {
312 312 */
313 313 private void initTodayData(String userId) {
314 314 CURRENT_DATE = getTodayDate();
  315 + Log.e(TAG, "initTodayData: " + getTodayDate());
315 316 if (userId == null || CURRENT_DATE == null) {
316 317 return;
317 318 }
318 319 //获取当天的数据,用于展示 CURRENT_DATE
319   - CalorieEntity calorieEntity = CalorieUtil.getUserCalorieData(getApplicationContext(), userId, getTodayDate());
  320 + CalorieEntity calorieEntity = CalorieUtil.getUserCalorieData(getApplicationContext(), userId, CURRENT_DATE);
  321 + Log.e(TAG, "calorieEntity: " + calorieEntity);
320 322 if (null == calorieEntity) {
321 323 CURRENT_STEP = 0;
  324 + calorieEntity=new CalorieEntity();
  325 + calorieEntity.setUuid(CalorieUtil.getUUID());
  326 + calorieEntity.setCurrentDate(CURRENT_DATE);
  327 + calorieEntity.setUserId(userId);
  328 + calorieEntity.setStep(CURRENT_STEP+"");
  329 + CalorieUtil.insertData(getApplicationContext(),calorieEntity);
322 330 } else {
323 331 if (calorieEntity.getStep() != null && !TextUtils.isEmpty(calorieEntity.getStep())) {
324 332 CURRENT_STEP = Integer.parseInt(calorieEntity.getStep());
... ... @@ -442,14 +450,19 @@ public class CalorieService extends Service implements SensorEventListener {
442 450 save();
443 451 } else if (Intent.ACTION_DATE_CHANGED.equals(action)) {//日期变化步数重置为0
444 452 // Logger.d("重置步数" + StepDcretor.CURRENT_STEP);
  453 + Log.e(TAG, "onReceive:ACTION_DATE_CHANGED ");
445 454 save();
446 455 isNewDay();
447 456 } else if (Intent.ACTION_TIME_CHANGED.equals(action)) {
  457 + Log.e(TAG, "onReceive:ACTION_TIME_CHANGED ");
  458 +
448 459 //时间变化步数重置为0
449 460 // isCall();
450 461 save();
451 462 isNewDay();
452 463 } else if (Intent.ACTION_TIME_TICK.equals(action)) {//日期变化步数重置为0
  464 + Log.e(TAG, "onReceive:ACTION_TIME_TICK ");
  465 +
453 466 // isCall();
454 467 // Logger.d("重置步数" + StepDcretor.CURRENT_STEP);
455 468 save();
... ... @@ -478,12 +491,8 @@ public class CalorieService extends Service implements SensorEventListener {
478 491 */
479 492 private void isNewDay() {
480 493 String time = "00:00";
481   - CalorieEntity calorieEntity = new CalorieEntity();
482   - calorieEntity.setUuid(CalorieUtil.getUUID());
483   - calorieEntity.setUserId(userId);
484   - calorieEntity.setCurrentDate(getTodayDate());
485   - CalorieUtil.insertData(getApplicationContext(), calorieEntity);
486 494 if (time.equals(new SimpleDateFormat("HH:mm").format(new Date())) || !CURRENT_DATE.equals(getTodayDate())) {
  495 + Log.e(TAG, "isNewDay: ");
487 496 initTodayData(userId);
488 497 }
489 498 }
... ... @@ -678,15 +687,8 @@ public class CalorieService extends Service implements SensorEventListener {
678 687 */
679 688 private void save() {
680 689 int tempStep = CURRENT_STEP;
681   - CalorieEntity calorieEntity = CalorieUtil.getUserCalorieData(getApplicationContext(), userId, getTodayDate());
682   - if (null == calorieEntity) {
683   - calorieEntity = new CalorieEntity();
684   - calorieEntity.setUserId(userId);
685   - calorieEntity.setUuid(CalorieUtil.getUUID());
686   - calorieEntity.setStep(tempStep + "");
687   - calorieEntity.setCurrentDate(getTodayDate());
688   - CalorieUtil.insertData(getApplicationContext(), calorieEntity);
689   - } else {
  690 + CalorieEntity calorieEntity = CalorieUtil.getUserCalorieData(getApplicationContext(), userId, CURRENT_DATE);
  691 + if (null != calorieEntity) {
690 692 calorieEntity.setStep(tempStep + "");
691 693 CalorieUtil.updateData(getApplicationContext(), calorieEntity);
692 694 }
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/calorie/utils/CalorieUtil.java
... ... @@ -28,6 +28,17 @@ public class CalorieUtil {
28 28 return UUID.randomUUID().toString().replace("-", "");
29 29 }
30 30  
  31 + public synchronized static void deleteDate(Context context, CalorieEntity calorieEntity) {
  32 + try {
  33 + if (null != calorieEntity) {
  34 + DbCore.init(context, dbName);
  35 + DbCore.getDaoSession().getCalorieEntityDao().deleteByKey(calorieEntity.getUuid());
  36 + DbCore.getDaoSession().getCalorieEntityDao().detachAll();
  37 + }
  38 + } catch (Exception e) {
  39 + }
  40 + }
  41 +
31 42 public synchronized static void updateData(Context context, CalorieEntity calorieEntity) {
32 43 try {
33 44 if (null != calorieEntity) {
... ... @@ -82,6 +93,7 @@ public class CalorieUtil {
82 93 try {
83 94 if (!TextUtils.isEmpty(uid)) {
84 95 DbCore.init(context, dbName);
  96 + DbCore.getDaoSession().getCalorieEntityDao().detachAll();
85 97 List<CalorieEntity> list = DbCore.getDaoSession().getCalorieEntityDao().queryBuilder().where(CalorieEntityDao.Properties.UserId.eq(uid), CalorieEntityDao.Properties.CurrentDate.eq(currentDate)).list();
86 98 if (list != null && list.size() > 0) {
87 99 return list.get(0);
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/MyRecordView.java
... ... @@ -72,7 +72,9 @@ public class MyRecordView implements MvpView {
72 72 }
73 73 if (fragment.currentPage > 1) {
74 74 list.addAll(myRecordInfoBaseInfo.getData().getList());
75   - adapter.notifyDataSetChanged();
  75 + if (null != adapter) {
  76 + adapter.notifyDataSetChanged();
  77 + }
76 78 }
77 79 fragment.binding.refreshLayout.finishRefresh();
78 80 fragment.binding.refreshLayout.finishLoadMore();
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunLineView.java
... ... @@ -33,54 +33,56 @@ public class RunLineView implements MvpView {
33 33 this.fragment = fragment;
34 34 }
35 35  
36   - public void initView(){
  36 + public void initView() {
37 37 fragment.binding.refreshLayout.setRefreshHeader(new ClassicsHeader(fragment.getActivity()));
38 38 fragment.binding.refreshLayout.setRefreshFooter(new ClassicsFooter(fragment.getActivity()));
39 39 fragment.binding.backBtn.setOnClickListener(v -> fragment.getActivity().finish());
40   - fragment.binding.myActivity.setOnClickListener(v -> MyRecordActivity.newInstance(fragment.getActivity(),null,null,null,null));
  40 + fragment.binding.myActivity.setOnClickListener(v -> MyRecordActivity.newInstance(fragment.getActivity(), null, null, null, null));
41 41  
42 42 fragment.binding.runLineRecy.setLayoutManager(new LinearLayoutManager(fragment.getActivity()));
43 43 }
44 44  
45   - public void onSuccess(BaseInfo<RunLineInfo> runLineInfoBaseInfo){
46   - if(fragment.currentPage == 1){
  45 + public void onSuccess(BaseInfo<RunLineInfo> runLineInfoBaseInfo) {
  46 + if (fragment.currentPage == 1) {
47 47 list.clear();
48 48 list.addAll(runLineInfoBaseInfo.getData().getList());
49   - if(adapter == null){
50   - adapter = new RunLineAdapter(list,fragment.getActivity());
  49 + if (adapter == null) {
  50 + adapter = new RunLineAdapter(list, fragment.getActivity());
51 51 fragment.binding.runLineRecy.setAdapter(adapter);
52 52 adapter.setClickListener(new RunLineAdapter.OnClickListener() {
53 53 @Override
54 54 public void onClickListener(RunLineInfo.ListBean bean, int position) {
55   - RunRaceDetailActivity.startActivity(fragment.getActivity(),bean.getId()+"",null,null,null,null);
  55 + RunRaceDetailActivity.startActivity(fragment.getActivity(), bean.getId() + "", null, null, null, null);
56 56 }
57 57 });
58   - }else {
  58 + } else {
59 59 adapter.notifyDataSetChanged();
60 60 }
61 61 }
62 62  
63   - if(list.size() != 0){
  63 + if (list.size() != 0) {
64 64 fragment.binding.empty.setVisibility(View.GONE);
65 65 fragment.binding.refreshLayout.setVisibility(View.VISIBLE);
66   - }else {
  66 + } else {
67 67 showEmpty();
68 68 }
69 69  
70   - if(runLineInfoBaseInfo.getData().getList().size() < fragment.pageSize){
  70 + if (runLineInfoBaseInfo.getData().getList().size() < fragment.pageSize) {
71 71 fragment.binding.refreshLayout.setEnableLoadMore(false);
72   - }else {
  72 + } else {
73 73 fragment.binding.refreshLayout.setEnableLoadMore(true);
74 74 }
75   - if(fragment.currentPage > 1){
  75 + if (fragment.currentPage > 1) {
76 76 list.addAll(runLineInfoBaseInfo.getData().getList());
77   - adapter.notifyDataSetChanged();
  77 + if (null != adapter) {
  78 + adapter.notifyDataSetChanged();
  79 + }
78 80 }
79 81 fragment.binding.refreshLayout.finishRefresh();
80 82 fragment.binding.refreshLayout.finishLoadMore();
81 83 }
82 84  
83   - public void showErr(String msg){
  85 + public void showErr(String msg) {
84 86 fragment.binding.refreshLayout.finishRefresh();
85 87 fragment.binding.refreshLayout.finishLoadMore();
86 88 if (list.size() == 0) {
... ... @@ -92,7 +94,7 @@ public class RunLineView implements MvpView {
92 94 @Override
93 95 public void onClick(View v) {
94 96 fragment.currentPage = 1;
95   - fragment.getPresenter().setData(fragment.getActivity(), CommonInfo.getUserId(fragment.getActivity()),fragment.currentPage,fragment.pageSize);
  97 + fragment.getPresenter().setData(fragment.getActivity(), CommonInfo.getUserId(fragment.getActivity()), fragment.currentPage, fragment.pageSize);
96 98 }
97 99 });
98 100 fragment.binding.empty.setLoadingShowing(false);
... ... @@ -109,7 +111,7 @@ public class RunLineView implements MvpView {
109 111 AlertUtil.showDeftToast(fragment.getActivity(), message);
110 112 }
111 113  
112   - public void showEmpty(){
  114 + public void showEmpty() {
113 115 fragment.binding.empty.setVisibility(View.VISIBLE);
114 116 fragment.binding.refreshLayout.setVisibility(View.GONE);
115 117 fragment.binding.empty.show("没有相关数据", "", R.drawable.zhuangtai_kong);
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/GsonUtil.java
... ... @@ -12,7 +12,7 @@ import java.util.List;
12 12 import java.util.Map;
13 13  
14 14 /**
15   - * Created by sijia
  15 + * Created by ShinnyYang
16 16 * on 2016/12/19.
17 17 */
18 18 public class GsonUtil {
... ...