OSDN Git Service

ラップタイム周りの表示処理を実装。
authorMRSa <mrsa@myad.jp>
Sat, 13 Jan 2024 14:43:54 +0000 (23:43 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 13 Jan 2024 14:43:54 +0000 (23:43 +0900)
wear/src/main/java/net/osdn/gokigen/joggingtimer/MainActivity.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/presentation/ui/main/LapTimeList.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/presentation/ui/main/MainCounter.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/presentation/ui/main/MainScreen.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/presentation/ui/main/SubCounter.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/timer/ITimerCounter.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/timer/MyTimerCounter.kt

index 1c6772f..b89425a 100644 (file)
@@ -24,7 +24,7 @@ import net.osdn.gokigen.joggingtimer.stopwatch.timer.ICounterStatusNotify
 class MainActivity : ComponentActivity(), ICounterStatusNotify
 {
     private lateinit var rootComponent : ViewRoot
-    //private var pendingStart = false
+    private var pendingStart = false
     //private var stopTrigger: ITimerStopTrigger? = null
 
     /**
@@ -182,11 +182,11 @@ class MainActivity : ComponentActivity(), ICounterStatusNotify
             }
         }
 
-        //AppSingleton.controller.setupReferenceData()
-        //if (isStartTimer)
-        //{
-        //    pendingStart = true
-        //}
+        AppSingleton.controller.setupReferenceData()
+        if (isStartTimer)
+        {
+            pendingStart = true
+        }
     }
 
     /**
@@ -239,18 +239,18 @@ class MainActivity : ComponentActivity(), ICounterStatusNotify
     {
         try
         {
-            Log.v(TAG, "counterStatusChanged($forceStartTimer)")
+            Log.v(TAG, "counterStatusChanged($forceStartTimer),  pendingStart:v$pendingStart")
             if (forceStartTimer)
             {
                 AppSingleton.timerCounter.start()
             }
-            //runOnUiThread {
-            //    if (pendingStart)
-            //    {
-            //        AppSingleton.timerCounter.start()
-            //        pendingStart = false
-            //    }
-            //}
+            runOnUiThread {
+                if (pendingStart)
+                {
+                    AppSingleton.timerCounter.start()
+                    pendingStart = false
+                }
+            }
         }
         catch (e: Exception)
         {
index 9438f01..50f1444 100644 (file)
@@ -5,53 +5,50 @@ import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.unit.sp
-import androidx.navigation.NavHostController
 import androidx.wear.compose.material.MaterialTheme
 import androidx.wear.compose.material.Text
+import net.osdn.gokigen.joggingtimer.stopwatch.timer.ITimerCounter
+import net.osdn.ja.gokigen.wearos.timerapp.counter.TimeStringConvert
 
 @Composable
-fun LapTimeList(navController: NavHostController) {
+fun LapTimeList(counterManager: ITimerCounter)
+{
+    LapTimeListPastTime(counterManager)
+}
 
-    Text(
-        modifier = Modifier.fillMaxWidth(),
-        textAlign = TextAlign.Center,
-        color = MaterialTheme.colors.primary,
-        text = "00:00:00.00",
-        fontSize = 12.sp,
-    )
-    Text(
-        modifier = Modifier.fillMaxWidth(),
-        textAlign = TextAlign.Center,
-        color = MaterialTheme.colors.primary,
-        text = "00:00:00.00",
-        fontSize = 12.sp,
-    )
-    Text(
-        modifier = Modifier.fillMaxWidth(),
-        textAlign = TextAlign.Center,
-        color = MaterialTheme.colors.primary,
-        text = "00:00:00.00",
-        fontSize = 12.sp,
-    )
-    Text(
-        modifier = Modifier.fillMaxWidth(),
-        textAlign = TextAlign.Center,
-        color = MaterialTheme.colors.primary,
-        text = "00:00:00.00",
-        fontSize = 12.sp,
-    )
-    Text(
-        modifier = Modifier.fillMaxWidth(),
-        textAlign = TextAlign.Center,
-        color = MaterialTheme.colors.primary,
-        text = "00:00:00.00",
-        fontSize = 12.sp,
-    )
-    Text(
-        modifier = Modifier.fillMaxWidth(),
-        textAlign = TextAlign.Center,
-        color = MaterialTheme.colors.primary,
-        text = "00:00:00.00",
-        fontSize = 12.sp,
-    )
+@Composable
+fun LapTimeListPastTime(counterManager: ITimerCounter)
+{
+    // (通常の)ラップタイム表示
+    val lapTimeCount = counterManager.getLapTimeCount()
+    val stopLapIndex = 1
+    //val stopLapIndex = if (lapTimeCount > (5 + 1)) { lapTimeCount - 5 } else { 1 }  // 表示するラップ数を最大5に制限する場合...
+    if (lapTimeCount > 0)
+    {
+        // 最新ラップタイムが上に表示されるようにしてみる
+        for (lapTimeIndex in (lapTimeCount - 1) downTo stopLapIndex)
+        {
+            val lapTime = counterManager.getLapTime(lapTimeIndex)
+            val previousTime = counterManager.getLapTime(lapTimeIndex - 1)
+            val timeString = TimeStringConvert.getTimeString(lapTime - previousTime)
+            Text(
+                modifier = Modifier.fillMaxWidth(),
+                textAlign = TextAlign.Center,
+                color = MaterialTheme.colors.primary,
+                text = "[${lapTimeIndex}] $timeString",
+                fontSize = 12.sp,
+            )
+        }
+    }
+    else
+    {
+        // ラップタイムがない(リセットされている)場合...
+        Text(
+            modifier = Modifier.fillMaxWidth(),
+            textAlign = TextAlign.Center,
+            color = MaterialTheme.colors.primary,
+            text = " - - - - - ",
+            fontSize = 12.sp,
+        )
+    }
 }
index 9a0b6f3..f6f6231 100644 (file)
@@ -15,7 +15,7 @@ import net.osdn.ja.gokigen.wearos.timerapp.counter.TimeStringConvert
 fun MainCounter(counterManager: ITimerCounter)
 {
     val totalTimeValue = counterManager.getPastTime() //- counterManager.getStartTime()
-    val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastElapsedTime() <= 0 ) { 0 } else { counterManager.getLastElapsedTime() }
+    val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastLapTime() <= 0 ) { 0 } else { counterManager.getLastLapTime() }
     val finishTimeValue = counterManager.getStopTime() - counterManager.getStartTime()
     val timeString = if (counterManager.getCounterMode()) {
         // メインカウンタはトータル時間を表示する
@@ -40,7 +40,7 @@ fun MainCounter(counterManager: ITimerCounter)
         when (counterManager.getCurrentCountStatus()) {
             ICounterStatus.START -> {
                 // 実行中
-                "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+                "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
             }
             ICounterStatus.STOP -> {
                 // 開始前
@@ -48,7 +48,7 @@ fun MainCounter(counterManager: ITimerCounter)
             }
             ICounterStatus.FINISHED -> {
                 // カウント終了
-                "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+                "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
             }
         }
     }
index ebe4db6..1371cf6 100644 (file)
@@ -105,7 +105,7 @@ fun MainScreen(navController: NavHostController, counterManager: ITimerCounter)
                 }
 
                 // ラップタイム一覧の表示
-                LapTimeList(navController)
+                LapTimeList(counterManager)
 
                 // 現在の状態によって、サブボタンの表示を切り替える
                 when (counterManager.getCurrentCountStatus())
index 157e8f7..de25d4d 100644 (file)
@@ -20,14 +20,14 @@ import net.osdn.ja.gokigen.wearos.timerapp.counter.TimeStringConvert
 fun SubCounter(counterManager: ITimerCounter)
 {
     val totalTimeValue = counterManager.getPastTime() // - counterManager.getStartTime()
-    val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastElapsedTime() <= 0 ) { 0 } else { counterManager.getLastElapsedTime() }
+    val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastLapTime() <= 0 ) { 0 } else { counterManager.getLastLapTime() }
     val finishTimeValue = counterManager.getStopTime() - counterManager.getStartTime()
     val timeString = if (counterManager.getCounterMode()) {
             // サブカウンタは、ラップタイムを表示する
             when (counterManager.getCurrentCountStatus()) {
                 ICounterStatus.START -> {
                     // 実行中
-                    "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+                    "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
                 }
                 ICounterStatus.STOP -> {
                     // 開始前
@@ -35,7 +35,7 @@ fun SubCounter(counterManager: ITimerCounter)
                 }
                 ICounterStatus.FINISHED -> {
                     // カウント終了
-                    "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+                    "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
                 }
             }
         }
index 0aab7c2..503bc14 100644 (file)
@@ -11,12 +11,12 @@ interface ITimerCounter
     fun stop()
     fun timeStamp(): Long
     fun reset()
-    fun getElapsedCount(): Int
+    fun getLapTimeCount(): Int
     fun getPastTime(): Long
 
-    fun getElapsedTime(lapCount: Int): Long
-    fun getLastElapsedTime(): Long
-    fun getCurrentElapsedTime(): Long
+    fun getLapTime(lapCount: Int): Long
+    fun getLastLapTime(): Long
+    fun getCurrentLapTime(): Long
     fun getStartTime(): Long
     fun getStopTime(): Long
     fun getLapTimeList(): List<Long>
index fced02b..deb54f3 100644 (file)
@@ -17,7 +17,7 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
     private var currentTimer = mutableLongStateOf(0)
     private var currentLapCount = mutableIntStateOf(0)
     private var referenceTimeId = 0
-    private var elapsedTime: MutableList<Long>
+    private var lapTime: MutableList<Long>
     private var referenceTimeA: List<Long>? = null
     private var referenceTimeB: List<Long>? = null
     private var referenceTimeC: List<Long>? = null
@@ -28,7 +28,7 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
 
     init
     {
-        elapsedTime = ArrayList()
+        lapTime = ArrayList()
         currentLapCount.intValue = 0
         currentTimer.longValue = 0L
     }
@@ -74,8 +74,8 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
         {
             startTime = System.currentTimeMillis()
             stopTime = 0L
-            elapsedTime.clear()
-            elapsedTime.add(startTime)
+            lapTime.clear()
+            lapTime.add(startTime)
             currentTimer.longValue = startTime
             currentLapCount.intValue = 1
             counterStatus.value = ICounterStatus.START
@@ -90,7 +90,7 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
         if (counterStatus.value == ICounterStatus.START)
         {
             timeToSet = System.currentTimeMillis()
-            elapsedTime.add(timeToSet)
+            lapTime.add(timeToSet)
             ++(currentLapCount.intValue)
         }
         return timeToSet
@@ -101,7 +101,7 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
         if (counterStatus.value == ICounterStatus.START)
         {
             stopTime = System.currentTimeMillis()
-            elapsedTime.add(stopTime)
+            lapTime.add(stopTime)
             ++(currentLapCount.intValue)
             counterStatus.value = ICounterStatus.FINISHED
         }
@@ -116,13 +116,13 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
             stopTime = 0L
             currentTimer.longValue = 0L
             currentLapCount.intValue = 0
-            elapsedTime.clear()
+            lapTime.clear()
             counterStatus.value = ICounterStatus.STOP
         }
         myTimer.forceStop()
     }
 
-    override fun getElapsedCount(): Int
+    override fun getLapTimeCount(): Int
     {
         return (currentLapCount.intValue)
     }
@@ -145,26 +145,26 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
         }
     }
 
-    override fun getElapsedTime(lapCount: Int): Long
+    override fun getLapTime(lapCount: Int): Long
     {
         try
         {
-            return if (lapCount < 0) 0 else elapsedTime[lapCount] - startTime
+            return if (lapCount < 0) 0 else lapTime[lapCount] - startTime
         }
         catch (e: Exception)
         {
             e.printStackTrace()
         }
-        return getLastElapsedTime()
+        return getLastLapTime()
     }
 
-    override fun getLastElapsedTime(): Long
+    override fun getLastLapTime(): Long
     {
         try
         {
-            if (elapsedTime.size > 0)
+            if (lapTime.size > 0)
             {
-                return (elapsedTime[elapsedTime.size - 1] - startTime)
+                return (lapTime[lapTime.size - 1] - startTime)
             }
         }
         catch (e: Exception)
@@ -174,14 +174,14 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
         return 0L
     }
 
-    override fun getCurrentElapsedTime(): Long
+    override fun getCurrentLapTime(): Long
     {
         val currentTime = System.currentTimeMillis()
         try
         {
-            if (elapsedTime.size > 0)
+            if (lapTime.size > 0)
             {
-                return currentTime - elapsedTime[elapsedTime.size - 1]
+                return currentTime - lapTime[lapTime.size - 1]
             }
         }
         catch (e: Exception)
@@ -212,7 +212,7 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
     }
     override fun getLapTimeList(): List<Long>
     {
-        return elapsedTime
+        return lapTime
     }
 
     override fun setCallback(callback: ICounterStatusNotify)
@@ -230,9 +230,9 @@ class MyTimerCounter internal constructor() : ITimerCounter, ITimeoutReceiver, I
             myTimer.startTimer()
             Log.v(TAG, "pastTime : $pastTime")
             this.startTime = startTime
-            elapsedTime = ArrayList(timelist)
+            lapTime = ArrayList(timelist)
             stopTime = 0L
-            currentLapCount.intValue = elapsedTime.size
+            currentLapCount.intValue = lapTime.size
             counterStatus.value = ICounterStatus.START
             callback?.counterStatusChanged(true)
         }