mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-04-16 19:27:32 +02:00
update time at the last lap in realtime
This commit is contained in:
parent
3e62f995ac
commit
40eb93dae9
@ -3,6 +3,7 @@ package com.simplemobiletools.clock.adapters
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.TextView
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||||
import com.simplemobiletools.clock.extensions.formatStopwatchTime
|
import com.simplemobiletools.clock.extensions.formatStopwatchTime
|
||||||
@ -17,6 +18,9 @@ import java.util.*
|
|||||||
|
|
||||||
class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||||
|
private var lastLapTimeView: TextView? = null
|
||||||
|
private var lastTotalTimeView: TextView? = null
|
||||||
|
private var lastLapId = 0
|
||||||
|
|
||||||
override fun getActionMenuId() = 0
|
override fun getActionMenuId() = 0
|
||||||
|
|
||||||
@ -43,11 +47,17 @@ class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyc
|
|||||||
override fun getItemCount() = laps.size
|
override fun getItemCount() = laps.size
|
||||||
|
|
||||||
fun updateItems(newItems: ArrayList<Lap>) {
|
fun updateItems(newItems: ArrayList<Lap>) {
|
||||||
|
lastLapId = 0
|
||||||
laps = newItems
|
laps = newItems
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateLastField(lapTime: Long, totalTime: Long) {
|
||||||
|
lastLapTimeView?.text = lapTime.formatStopwatchTime(false)
|
||||||
|
lastTotalTimeView?.text = totalTime.formatStopwatchTime(false)
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupView(view: View, lap: Lap) {
|
private fun setupView(view: View, lap: Lap) {
|
||||||
view.apply {
|
view.apply {
|
||||||
lap_order.text = lap.id.toString()
|
lap_order.text = lap.id.toString()
|
||||||
@ -67,6 +77,12 @@ class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyc
|
|||||||
lap_total_time.setOnClickListener {
|
lap_total_time.setOnClickListener {
|
||||||
itemClick(SORT_BY_TOTAL_TIME)
|
itemClick(SORT_BY_TOTAL_TIME)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lap.id > lastLapId) {
|
||||||
|
lastLapTimeView = lap_lap_time
|
||||||
|
lastTotalTimeView = lap_total_time
|
||||||
|
lastLapId = lap.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ class StopwatchFragment : Fragment() {
|
|||||||
private var sorting = SORT_BY_LAP or SORT_DESCENDING
|
private var sorting = SORT_BY_LAP or SORT_DESCENDING
|
||||||
private var laps = ArrayList<Lap>()
|
private var laps = ArrayList<Lap>()
|
||||||
|
|
||||||
|
lateinit var stopwatchAdapter: StopwatchAdapter
|
||||||
lateinit var view: ViewGroup
|
lateinit var view: ViewGroup
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
@ -74,7 +75,7 @@ class StopwatchFragment : Fragment() {
|
|||||||
updateLaps()
|
updateLaps()
|
||||||
}
|
}
|
||||||
|
|
||||||
val stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) {
|
stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) {
|
||||||
if (it is Int) {
|
if (it is Int) {
|
||||||
changeSorting(it)
|
changeSorting(it)
|
||||||
}
|
}
|
||||||
@ -141,6 +142,9 @@ class StopwatchFragment : Fragment() {
|
|||||||
|
|
||||||
private fun updateDisplayedText() {
|
private fun updateDisplayedText() {
|
||||||
view.stopwatch_time.text = (totalTicks * UPDATE_INTERVAL).formatStopwatchTime(false)
|
view.stopwatch_time.text = (totalTicks * UPDATE_INTERVAL).formatStopwatchTime(false)
|
||||||
|
if (currentLap > 1) {
|
||||||
|
stopwatchAdapter.updateLastField(lapTicks * UPDATE_INTERVAL, totalTicks * UPDATE_INTERVAL)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetStopwatch() {
|
private fun resetStopwatch() {
|
||||||
@ -197,7 +201,7 @@ class StopwatchFragment : Fragment() {
|
|||||||
|
|
||||||
private fun updateLaps() {
|
private fun updateLaps() {
|
||||||
laps.sort()
|
laps.sort()
|
||||||
(view.stopwatch_list.adapter as StopwatchAdapter).updateItems(laps)
|
stopwatchAdapter.updateItems(laps)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val updateRunnable = object : Runnable {
|
private val updateRunnable = object : Runnable {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user