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.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
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) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
private var lastLapTimeView: TextView? = null
|
||||
private var lastTotalTimeView: TextView? = null
|
||||
private var lastLapId = 0
|
||||
|
||||
override fun getActionMenuId() = 0
|
||||
|
||||
|
@ -43,11 +47,17 @@ class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyc
|
|||
override fun getItemCount() = laps.size
|
||||
|
||||
fun updateItems(newItems: ArrayList<Lap>) {
|
||||
lastLapId = 0
|
||||
laps = newItems
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
fun updateLastField(lapTime: Long, totalTime: Long) {
|
||||
lastLapTimeView?.text = lapTime.formatStopwatchTime(false)
|
||||
lastTotalTimeView?.text = totalTime.formatStopwatchTime(false)
|
||||
}
|
||||
|
||||
private fun setupView(view: View, lap: Lap) {
|
||||
view.apply {
|
||||
lap_order.text = lap.id.toString()
|
||||
|
@ -67,6 +77,12 @@ class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyc
|
|||
lap_total_time.setOnClickListener {
|
||||
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 laps = ArrayList<Lap>()
|
||||
|
||||
lateinit var stopwatchAdapter: StopwatchAdapter
|
||||
lateinit var view: ViewGroup
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
|
@ -74,7 +75,7 @@ class StopwatchFragment : Fragment() {
|
|||
updateLaps()
|
||||
}
|
||||
|
||||
val stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) {
|
||||
stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) {
|
||||
if (it is Int) {
|
||||
changeSorting(it)
|
||||
}
|
||||
|
@ -141,6 +142,9 @@ class StopwatchFragment : Fragment() {
|
|||
|
||||
private fun updateDisplayedText() {
|
||||
view.stopwatch_time.text = (totalTicks * UPDATE_INTERVAL).formatStopwatchTime(false)
|
||||
if (currentLap > 1) {
|
||||
stopwatchAdapter.updateLastField(lapTicks * UPDATE_INTERVAL, totalTicks * UPDATE_INTERVAL)
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetStopwatch() {
|
||||
|
@ -197,7 +201,7 @@ class StopwatchFragment : Fragment() {
|
|||
|
||||
private fun updateLaps() {
|
||||
laps.sort()
|
||||
(view.stopwatch_list.adapter as StopwatchAdapter).updateItems(laps)
|
||||
stopwatchAdapter.updateItems(laps)
|
||||
}
|
||||
|
||||
private val updateRunnable = object : Runnable {
|
||||
|
|
Loading…
Reference in New Issue