fixed time update.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 30 Jul 2021 08:16:23 +0000 (16:16 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 30 Jul 2021 08:16:23 +0000 (16:16 +0800)
app/src/main/java/com/ic/sport/model/PedometerModel.java
app/src/main/res/layout/activity_pedometer.xml

index b554311..338561a 100644 (file)
@@ -41,6 +41,7 @@ public class PedometerModel extends AndroidViewModel {
         mCalorie = pedometerPresenter.getCalorie();
         //注冊广播,监听时间变化
         registerTimeDateReceiver();
+        updateTime();
     }
 
     @Override
@@ -56,12 +57,16 @@ public class PedometerModel extends AndroidViewModel {
             String action = intent.getAction();
             if (TextUtils.isEmpty(action)) return;
             //更新时间
-            String format = LocalDateTime.now().format(HH_MM);
-            IcLog.d(TAG, "format time == > " + format);
-            timeValue.postValue(format);
+            updateTime();
         }
     };
 
+    private void updateTime() {
+        String format = LocalDateTime.now().format(HH_MM);
+        IcLog.d(TAG, "format time == > " + format);
+        timeValue.postValue(format);
+    }
+
 
     public void registerTimeDateReceiver() {
         IntentFilter filter = new IntentFilter();
@@ -71,7 +76,6 @@ public class PedometerModel extends AndroidViewModel {
         getApplication().registerReceiver(mIntentReceiver, filter);
     }
 
-
     public LiveData<Float> getCalorie() {
         return mCalorie;
     }
index e40ce58..b138558 100644 (file)
@@ -7,22 +7,22 @@
     tools:context=".PedometerActivity">
 
     <TextView
+        android:id="@+id/top_left_title_tv"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:padding="5dp"
-        android:id="@+id/top_left_title_tv"
         android:text="@string/app_name"
         android:textColor="@color/green1"
         android:textSize="30sp"
         android:textStyle="bold" />
 
     <TextView
+        android:id="@+id/top_time_tv"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="right|top"
         android:padding="5dp"
         android:text="12:12"
-        android:id="@+id/top_time_tv"
         android:textColor="@color/white"
         android:textSize="30sp"
         android:textStyle="bold" />