Skip to content

Commit 90c8106

Browse files
committed
fix duration view passing scroll to other fields
1 parent 7fce681 commit 90c8106

File tree

2 files changed

+27
-14
lines changed
  • features
    • feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/duration/customView
    • feature_statistics_detail/src/main/java/com/example/util/simpletimetracker/feature_statistics_detail/interactor

2 files changed

+27
-14
lines changed

features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/duration/customView/DurationView.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.example.util.simpletimetracker.domain.extension.orZero
1616
import com.example.util.simpletimetracker.domain.extension.toDuration
1717
import com.example.util.simpletimetracker.feature_dialogs.R
1818
import kotlin.math.round
19+
import androidx.core.content.withStyledAttributes
1920

2021
class DurationView @JvmOverloads constructor(
2122
context: Context,
@@ -122,11 +123,10 @@ class DurationView @JvmOverloads constructor(
122123
defStyleAttr: Int = 0,
123124
) {
124125
context
125-
.obtainStyledAttributes(
126+
.withStyledAttributes(
126127
attrs,
127128
R.styleable.DurationView, defStyleAttr, 0,
128-
)
129-
.run {
129+
) {
130130
textColor = getColor(
131131
R.styleable.DurationView_durationTextColor, Color.BLACK,
132132
)
@@ -139,8 +139,6 @@ class DurationView @JvmOverloads constructor(
139139
legendPadding = getDimensionPixelSize(
140140
R.styleable.DurationView_durationLegendPadding, 0,
141141
).toFloat()
142-
143-
recycle()
144142
}
145143
}
146144

@@ -365,18 +363,24 @@ class DurationView @JvmOverloads constructor(
365363
startSwipe(
366364
event = event,
367365
offset = offset,
366+
isOtherSwipingInProgress = fieldStateMinutes.isSwiping ||
367+
fieldStateSeconds.isSwiping,
368368
getState = { fieldStateHours },
369369
setState = { fieldStateHours = it },
370370
)
371371
startSwipe(
372372
event = event,
373373
offset = offset,
374+
isOtherSwipingInProgress = fieldStateHours.isSwiping ||
375+
fieldStateSeconds.isSwiping,
374376
getState = { fieldStateMinutes },
375377
setState = { fieldStateMinutes = it },
376378
)
377379
startSwipe(
378380
event = event,
379381
offset = offset,
382+
isOtherSwipingInProgress = fieldStateHours.isSwiping ||
383+
fieldStateMinutes.isSwiping,
380384
getState = { fieldStateSeconds },
381385
setState = { fieldStateSeconds = it },
382386
)
@@ -408,10 +412,15 @@ class DurationView @JvmOverloads constructor(
408412
private fun startSwipe(
409413
event: MotionEvent,
410414
offset: Float,
415+
isOtherSwipingInProgress: Boolean,
411416
getState: () -> FieldState,
412417
setState: (FieldState) -> Unit,
413418
) {
414-
if (event.x in getState().leftPx..getState().rightPx) {
419+
val coordinatesInRange = event.x in getState().leftPx..getState().rightPx
420+
if (
421+
(!isOtherSwipingInProgress && coordinatesInRange) ||
422+
getState().isSwiping
423+
) {
415424
// Cancel current animation on new swipe.
416425
if (getState().isSettling) {
417426
getState().animator?.cancel()

features/feature_statistics_detail/src/main/java/com/example/util/simpletimetracker/feature_statistics_detail/interactor/StatisticsDetailChartInteractor.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,19 @@ class StatisticsDetailChartInteractor @Inject constructor(
200200

201201
fun mapRangesToValue(list: List<RecordBase>, range: Range): Long {
202202
return when (chartMode) {
203-
ChartMode.DURATIONS -> list
204-
.map { record -> rangeMapper.clampToRange(record, range) }
205-
.let(rangeMapper::mapToDuration)
206-
ChartMode.COUNTS -> list.size.toLong()
207-
ChartMode.TAG_VALUE -> list
208-
.sumOf { record ->
203+
ChartMode.DURATIONS -> {
204+
list.map { record ->
205+
rangeMapper.clampToRange(record, range)
206+
}.let(rangeMapper::mapToDuration)
207+
}
208+
ChartMode.COUNTS -> {
209+
list.size.toLong()
210+
}
211+
ChartMode.TAG_VALUE -> {
212+
list.sumOf { record ->
209213
record.tags.sumOf { it.numericValue.orZero() * TAG_VALUE_PRECISION }
210-
}
211-
.roundToLong()
214+
}.roundToLong()
215+
}
212216
}
213217
}
214218

0 commit comments

Comments
 (0)