show laps in a recyclerview
This commit is contained in:
parent
af91f217ef
commit
2a77bce55f
7 changed files with 141 additions and 9 deletions
|
@ -0,0 +1,60 @@
|
|||
package com.simplemobiletools.clock.adapters
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.extensions.formatStopwatchTime
|
||||
import com.simplemobiletools.clock.models.Lap
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.item_lap.view.*
|
||||
import java.util.*
|
||||
|
||||
class StopwatchAdapter(activity: SimpleActivity, var laps: ArrayList<Lap>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
override fun getActionMenuId() = 0
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
||||
override fun prepareItemSelection(view: View) {}
|
||||
|
||||
override fun markItemSelection(select: Boolean, view: View?) {}
|
||||
|
||||
override fun actionItemPressed(id: Int) {}
|
||||
|
||||
override fun getSelectableItemCount() = laps.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_lap, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||
val lap = laps[position]
|
||||
val view = holder.bindView(lap, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, lap)
|
||||
}
|
||||
bindViewHolder(holder, position, view)
|
||||
}
|
||||
|
||||
override fun getItemCount() = laps.size
|
||||
|
||||
fun updateItems(newItems: ArrayList<Lap>) {
|
||||
laps = newItems
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
private fun setupView(view: View, lap: Lap) {
|
||||
view.apply {
|
||||
lap_order.text = lap.id.toString()
|
||||
lap_order.setTextColor(textColor)
|
||||
|
||||
lap_lap_time.text = lap.lapTime.formatStopwatchTime(false)
|
||||
lap_lap_time.setTextColor(textColor)
|
||||
|
||||
lap_total_time.text = lap.totalTime.formatStopwatchTime(false)
|
||||
lap_total_time.setTextColor(textColor)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,9 +10,11 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.adapters.StopwatchAdapter
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.formatStopwatchTime
|
||||
import com.simplemobiletools.clock.models.StopwatchTime
|
||||
import com.simplemobiletools.clock.models.Lap
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import kotlinx.android.synthetic.main.fragment_stopwatch.view.*
|
||||
|
||||
|
@ -25,9 +27,9 @@ class StopwatchFragment : Fragment() {
|
|||
private var totalTicks = 0
|
||||
private var currentTicks = 0 // ticks that reset at pause
|
||||
private var lapTicks = 0
|
||||
private var currentLap = 0
|
||||
private var currentLap = 1
|
||||
private var isRunning = false
|
||||
private var laps = ArrayList<StopwatchTime>()
|
||||
private var laps = ArrayList<Lap>()
|
||||
|
||||
lateinit var view: ViewGroup
|
||||
|
||||
|
@ -46,11 +48,16 @@ class StopwatchFragment : Fragment() {
|
|||
}
|
||||
|
||||
stopwatch_lap.setOnClickListener {
|
||||
val lap = StopwatchTime(currentLap++, lapTicks * UPDATE_INTERVAL, totalTicks * UPDATE_INTERVAL)
|
||||
laps.add(lap)
|
||||
val lap = Lap(currentLap++, lapTicks * UPDATE_INTERVAL, totalTicks * UPDATE_INTERVAL)
|
||||
laps.add(0, lap)
|
||||
lapTicks = 0
|
||||
(stopwatch_list.adapter as StopwatchAdapter).updateItems(laps)
|
||||
}
|
||||
|
||||
val stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) { }
|
||||
stopwatch_list.adapter = stopwatchAdapter
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
|
@ -113,7 +120,7 @@ class StopwatchFragment : Fragment() {
|
|||
isRunning = false
|
||||
currentTicks = 0
|
||||
totalTicks = 0
|
||||
currentLap = 0
|
||||
currentLap = 1
|
||||
lapTicks = 0
|
||||
laps.clear()
|
||||
updateIcons()
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.clock.models
|
||||
|
||||
data class Lap(val id: Int, var lapTime: Long, var totalTime: Long)
|
|
@ -1,3 +0,0 @@
|
|||
package com.simplemobiletools.clock.models
|
||||
|
||||
data class StopwatchTime(val id: Int, var lapTime: Long, var totalTime: Long)
|
|
@ -21,6 +21,20 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="00.00"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/stopwatch_list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:clipToPadding="false"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="vertical"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"
|
||||
app:layout_constraintBottom_toTopOf="@+id/stopwatch_play_pause"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/stopwatch_time"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/stopwatch_reset"
|
||||
style="@style/MyBorderlessBackgroundStyle"
|
||||
|
|
49
app/src/main/res/layout/item_lap.xml
Normal file
49
app/src/main/res/layout/item_lap.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/lap_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingLeft="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/lap_order"
|
||||
android:layout_width="@dimen/lap_order_size"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:maxLines="1"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
app:layout_constraintEnd_toStartOf="@+id/lap_lap_time"
|
||||
app:layout_constraintHorizontal_bias="0.38"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:text="1"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/lap_lap_time"
|
||||
android:layout_width="@dimen/lap_time_size"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:maxLines="1"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
app:layout_constraintEnd_toStartOf="@+id/lap_total_time"
|
||||
app:layout_constraintStart_toEndOf="@+id/lap_order"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="0.00"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/lap_total_time"
|
||||
android:layout_width="@dimen/lap_time_size"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:maxLines="1"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/lap_lap_time"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="0.00"/>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -2,6 +2,8 @@
|
|||
<dimen name="alarm_day_size">38dp</dimen>
|
||||
<dimen name="stopwatch_button_small_size">60dp</dimen>
|
||||
<dimen name="stopwatch_button_size">64dp</dimen>
|
||||
<dimen name="lap_order_size">40dp</dimen>
|
||||
<dimen name="lap_time_size">80dp</dimen>
|
||||
|
||||
<dimen name="clock_text_size">70sp</dimen>
|
||||
<dimen name="alarm_text_size">46sp</dimen>
|
||||
|
|
Loading…
Reference in a new issue