Commit 82781df1873da1bc48c916f4865b53899ad9ed4e

Authored by YangShuai
1 parent d0f5c5da

1 修复bug

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