@@ -5,10 +5,8 @@ import android.content.Intent
5
5
import android.net.Uri
6
6
import android.os.Bundle
7
7
import android.view.View
8
- import android.widget.EditText
9
8
import androidx.activity.result.PickVisualMediaRequest
10
9
import androidx.activity.result.contract.ActivityResultContracts
11
- import androidx.cardview.widget.CardView
12
10
import androidx.core.net.toUri
13
11
import androidx.core.widget.ImageViewCompat
14
12
import androidx.fragment.app.DialogFragment
@@ -21,8 +19,9 @@ import xyz.aprildown.timer.app.base.data.PreferenceData.getTypeColor
21
19
import xyz.aprildown.timer.app.base.ui.AppNavigator
22
20
import xyz.aprildown.timer.app.base.ui.StepUpdater
23
21
import xyz.aprildown.timer.app.base.utils.produceTime
22
+ import xyz.aprildown.timer.app.timer.edit.databinding.DialogUpdateStepBinding
23
+ import xyz.aprildown.timer.app.timer.edit.databinding.ItemEditStepBinding
24
24
import xyz.aprildown.timer.component.key.DurationPicker
25
- import xyz.aprildown.timer.component.key.RoundTextView
26
25
import xyz.aprildown.timer.component.key.behaviour.EditableBehaviourLayout
27
26
import xyz.aprildown.timer.domain.entities.BehaviourEntity
28
27
import xyz.aprildown.timer.domain.entities.BehaviourType
@@ -50,8 +49,7 @@ class UpdateStepDialog :
50
49
@Inject
51
50
lateinit var appNavigator: AppNavigator
52
51
53
- private lateinit var editName: EditText
54
- private lateinit var behaviourLayout: EditableBehaviourLayout
52
+ private lateinit var binding: ItemEditStepBinding
55
53
56
54
private var length = 0L
57
55
@@ -75,64 +73,64 @@ class UpdateStepDialog :
75
73
76
74
override fun onCreateDialog (savedInstanceState : Bundle ? ): Dialog {
77
75
val context = requireContext()
78
- val view = View .inflate(context, R .layout.dialog_update_step, null )
76
+ val dialogBinding = DialogUpdateStepBinding .inflate(layoutInflater)
77
+ binding = dialogBinding.layoutStep
79
78
val step = step
80
79
val onUpdate = onUpdate
81
80
if (step == null || onUpdate == null ) {
82
81
dismiss()
83
82
return super .onCreateDialog(savedInstanceState)
84
83
}
85
- view .setUpUpdateStepView(step)
84
+ binding .setUpUpdateStepView(step)
86
85
return MaterialAlertDialogBuilder (context)
87
86
.setCancelable(false )
88
87
.setTitle(RBase .string.edit_step)
89
88
.setView(view)
90
89
.setPositiveButton(android.R .string.ok) { _, _ ->
91
90
onUpdate.invoke(
92
91
StepEntity .Step (
93
- editName .text.toString(),
94
- length,
95
- behaviourLayout .getBehaviours(),
96
- step.type
92
+ label = binding.editStepName .text.toString(),
93
+ length = length ,
94
+ behaviour = binding.layoutBehaviour .getBehaviours(),
95
+ type = step.type,
97
96
)
98
97
)
99
98
}
100
99
.setNegativeButton(android.R .string.cancel, null )
101
100
.create()
102
101
}
103
102
104
- private fun View .setUpUpdateStepView (step : StepEntity .Step ) {
105
- val context = context
103
+ private fun ItemEditStepBinding .setUpUpdateStepView (step : StepEntity .Step ) {
104
+ val context = root. context
106
105
107
- findViewById< CardView >( R .id. cardEditStep) .cardElevation = 0f
106
+ cardEditStep.cardElevation = 0f
108
107
109
108
val color = step.type.getTypeColor(context)
110
- ImageViewCompat .setImageTintList(findViewById( R .id. colorStep) , color.toColorStateList())
111
- findViewById< View >( R .id. viewStepGroupIndicatorStart) .gone()
112
- findViewById< View >( R .id. viewStepGroupIndicatorEnd) .gone()
109
+ ImageViewCompat .setImageTintList(colorStep, color.toColorStateList())
110
+ viewStepGroupIndicatorStart.gone()
111
+ viewStepGroupIndicatorEnd.gone()
113
112
114
- editName = findViewById(R .id.editStepName)
115
- editName.setText(step.label)
113
+ editStepName.setText(step.label)
114
+
115
+ textStepLength.setBgColor(color)
116
116
117
- val lengthLabel = findViewById<RoundTextView >(R .id.textStepLength)
118
- lengthLabel.setBgColor(color)
119
- fun updateLength (length : Long ) {
120
- lengthLabel.text = length.produceTime()
121
- this @UpdateStepDialog.length = length
122
- }
123
117
updateLength(step.length)
124
- lengthLabel .setOnClickListener {
118
+ textStepLength .setOnClickListener {
125
119
DurationPicker (context) { hours, minutes, seconds ->
126
120
updateLength((hours * 3600L + minutes * 60L + seconds) * 1000L )
127
121
}.show()
128
122
}
129
123
130
- findViewById<View >(R .id.btnStepAdd).gone()
124
+ btnStepAdd.gone()
125
+
126
+ layoutBehaviour.setEnabledColor(color)
127
+ layoutBehaviour.setBehaviours(step.behaviour)
128
+ layoutBehaviour.setListener(this @UpdateStepDialog)
129
+ }
131
130
132
- behaviourLayout = findViewById(R .id.layoutBehaviour)
133
- behaviourLayout.setEnabledColor(color)
134
- behaviourLayout.setBehaviours(step.behaviour)
135
- behaviourLayout.setListener(this @UpdateStepDialog)
131
+ private fun updateLength (length : Long ) {
132
+ binding.textStepLength.text = length.produceTime()
133
+ this @UpdateStepDialog.length = length
136
134
}
137
135
138
136
override fun showBehaviourSettingsView (
@@ -177,7 +175,8 @@ class UpdateStepDialog :
177
175
changeBehaviour(BehaviourType .MUSIC ) {
178
176
it.toMusicAction().copy(loop = isChecked).toBehaviourEntity()
179
177
}
180
- }
178
+ },
179
+ onTrimStepDuration = ::updateLength,
181
180
)
182
181
}
183
182
BehaviourType .VIBRATION -> {
@@ -318,7 +317,7 @@ class UpdateStepDialog :
318
317
) {
319
318
var found = false
320
319
val newBehaviours = mutableListOf<BehaviourEntity >()
321
- behaviourLayout .getBehaviours().forEach {
320
+ binding.layoutBehaviour .getBehaviours().forEach {
322
321
if (it.type == type) {
323
322
newBehaviours + = transform.invoke(it)
324
323
found = true
@@ -329,7 +328,7 @@ class UpdateStepDialog :
329
328
if (! found) {
330
329
newBehaviours + = transform(BehaviourEntity (type))
331
330
}
332
- behaviourLayout .setBehaviours(newBehaviours)
331
+ binding.layoutBehaviour .setBehaviours(newBehaviours)
333
332
}
334
333
335
334
companion object : StepUpdater {
0 commit comments