diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/durationpicker/DurationPicker.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/durationpicker/DurationPicker.kt index 09299192e0c77f584149029b4a4c54f6041403c4..69a59f987cecd5639cfa77f882ec3090c88313bb 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/durationpicker/DurationPicker.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/durationpicker/DurationPicker.kt @@ -1,18 +1,18 @@ package de.rki.coronawarnapp.ui.durationpicker import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import androidx.annotation.IntRange import androidx.fragment.app.DialogFragment +import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.DurationPickerBinding +import de.rki.coronawarnapp.util.ui.viewBindingLazy import org.joda.time.Duration import org.joda.time.format.PeriodFormatter import org.joda.time.format.PeriodFormatterBuilder import kotlin.math.max -class DurationPicker : DialogFragment() { +class DurationPicker : DialogFragment(R.layout.duration_picker) { fun interface OnChangeListener { fun onChange(duration: Duration) @@ -23,32 +23,28 @@ class DurationPicker : DialogFragment() { private val title by lazy { requireArguments().getString(TITLE_KEY).orEmpty() } private val minutesArray by lazy { requireArguments().getStringArray(MINUTES_KEY).orEmpty() } - private val binding: Lazy<DurationPickerBinding> = lazy { DurationPickerBinding.inflate(layoutInflater) } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - return binding.value.root - } + private val binding: DurationPickerBinding by viewBindingLazy() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - with(binding.value.hours) { + with(binding.hours) { minValue = 0 maxValue = hoursArray.size - 1 displayedValues = hoursArray } - with(binding.value.minutes) { + with(binding.minutes) { minValue = 0 maxValue = minutesArray.size - 1 displayedValues = minutesArray } - with(binding.value.title) { + with(binding.title) { text = title } - with(binding.value) { + with(binding) { var duration = requireArguments().getString(DURATION_KEY)!!.split(":").toTypedArray() if (duration.size < 2) duration = arrayOf("00", "00") @@ -68,7 +64,7 @@ class DurationPicker : DialogFragment() { } private fun getDuration(): Duration { - val durationString = hoursArray[binding.value.hours.value] + ":" + minutesArray[binding.value.minutes.value] + val durationString = hoursArray[binding.hours.value] + ":" + minutesArray[binding.minutes.value] val formatter: PeriodFormatter = PeriodFormatterBuilder() .appendHours() .appendLiteral(":")