mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2024-12-17 10:48:23 +01:00
Implement concise view for timer
This commit is contained in:
parent
db3e0c9d07
commit
dc3ddacffa
@ -7,7 +7,6 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.dialogs.MyTimePickerDialogDialog
|
||||
import com.simplemobiletools.clock.extensions.getFormattedDuration
|
||||
import com.simplemobiletools.clock.extensions.hideTimerNotification
|
||||
import com.simplemobiletools.clock.extensions.secondsToMillis
|
||||
@ -25,7 +24,7 @@ class TimerAdapter(
|
||||
private val simpleActivity: SimpleActivity,
|
||||
recyclerView: MyRecyclerView,
|
||||
onRefresh: () -> Unit,
|
||||
private val onItemClick: (Timer) -> Unit,
|
||||
onItemClick: (Timer) -> Unit,
|
||||
) : MyRecyclerViewListAdapter<Timer>(simpleActivity, recyclerView, diffUtil, null, onItemClick, onRefresh) {
|
||||
|
||||
companion object {
|
||||
@ -75,12 +74,10 @@ class TimerAdapter(
|
||||
return position
|
||||
}
|
||||
|
||||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
override fun onActionModeDestroyed() {}
|
||||
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_timer, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
@ -101,7 +98,6 @@ class TimerAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun setupView(view: View, timer: Timer) {
|
||||
view.apply {
|
||||
val isSelected = selectedKeys.contains(timer.id)
|
||||
@ -118,23 +114,12 @@ class TimerAdapter(
|
||||
is TimerState.Paused -> timer.state.tick.getFormattedDuration()
|
||||
is TimerState.Running -> timer.state.tick.getFormattedDuration()
|
||||
}
|
||||
timer_time.setOnClickListener {
|
||||
changeDuration(timer)
|
||||
}
|
||||
|
||||
timer_delete.applyColorFilter(textColor)
|
||||
timer_delete.setOnClickListener {
|
||||
simpleActivity.timerHelper.deleteTimer(timer.id!!) {
|
||||
onRefresh.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
timer_reset.applyColorFilter(textColor)
|
||||
timer_reset.setOnClickListener {
|
||||
stopTimer(timer)
|
||||
}
|
||||
|
||||
timer_play_pause.background = simpleActivity.resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, adjustedPrimaryColor)
|
||||
timer_play_pause.applyColorFilter(if (adjustedPrimaryColor == Color.WHITE) Color.BLACK else Color.WHITE)
|
||||
timer_play_pause.setOnClickListener {
|
||||
when (val state = timer.state) {
|
||||
@ -148,31 +133,14 @@ class TimerAdapter(
|
||||
val state = timer.state
|
||||
val resetPossible = state is TimerState.Running || state is TimerState.Paused || state is TimerState.Finished
|
||||
timer_reset.beInvisibleIf(!resetPossible)
|
||||
timer_delete.beInvisibleIf(!(!resetPossible && itemCount > 1))
|
||||
val drawableId = if (state is TimerState.Running) R.drawable.ic_pause_vector else R.drawable.ic_play_vector
|
||||
val iconColor = if (adjustedPrimaryColor == Color.WHITE) Color.BLACK else Color.WHITE
|
||||
timer_play_pause.setImageDrawable(simpleActivity.resources.getColoredDrawableWithColor(drawableId, iconColor))
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeDuration(timer: Timer) {
|
||||
MyTimePickerDialogDialog(simpleActivity, timer.seconds) { seconds ->
|
||||
val timerSeconds = if (seconds <= 0) 10 else seconds
|
||||
updateTimer(timer.copy(seconds = timerSeconds))
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTimer(timer: Timer, refresh: Boolean = true) {
|
||||
simpleActivity.timerHelper.insertOrUpdateTimer(timer) {
|
||||
if (refresh) {
|
||||
onRefresh.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopTimer(timer: Timer) {
|
||||
EventBus.getDefault().post(TimerEvent.Reset(timer.id!!, timer.seconds.secondsToMillis))
|
||||
simpleActivity.hideTimerNotification()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,34 +12,30 @@
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/medium_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/timer_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/bigger_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="@dimen/small_margin"
|
||||
android:textSize="@dimen/stopwatch_text_size"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/timer_reset"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="00:00" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/timer_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="@dimen/small_margin"
|
||||
android:paddingEnd="@dimen/small_margin"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/timer_time"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/timer_time"
|
||||
tools:text="Cook rice" />
|
||||
@ -49,28 +45,17 @@
|
||||
android:id="@+id/timer_reset"
|
||||
android:layout_width="@dimen/stopwatch_button_small_size"
|
||||
android:layout_height="@dimen/stopwatch_button_small_size"
|
||||
android:layout_marginStart="@dimen/bigger_margin"
|
||||
android:layout_marginEnd="@dimen/bigger_margin"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/normal_margin"
|
||||
android:src="@drawable/ic_reset_vector"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/timer_play_pause"
|
||||
app:layout_constraintEnd_toStartOf="@+id/timer_play_pause"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/timer_time"
|
||||
app:layout_constraintTop_toTopOf="@id/timer_play_pause" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/timer_delete"
|
||||
android:layout_width="@dimen/stopwatch_button_small_size"
|
||||
android:layout_height="@dimen/stopwatch_button_small_size"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/normal_margin"
|
||||
android:src="@drawable/ic_delete_vector"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/timer_play_pause"
|
||||
app:layout_constraintEnd_toStartOf="@+id/timer_play_pause"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/timer_play_pause"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/timer_play_pause"
|
||||
@ -78,15 +63,15 @@
|
||||
android:layout_height="@dimen/stopwatch_button_size"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/big_margin"
|
||||
android:layout_marginBottom="@dimen/big_margin"
|
||||
android:layout_marginStart="@dimen/bigger_margin"
|
||||
android:layout_marginEnd="@dimen/bigger_margin"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:src="@drawable/ic_play_vector"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/timer_label" />
|
||||
app:layout_constraintStart_toEndOf="@id/timer_reset"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user