Add radio button for seconds for custom sleep timer
This commit is contained in:
parent
c00d4cc30c
commit
788ef6f01f
|
@ -319,7 +319,15 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
if (items.none { it.id == config.lastSleepTimerSeconds }) {
|
||||
val lastSleepTimerMinutes = config.lastSleepTimerSeconds / 60
|
||||
val text = resources.getQuantityString(R.plurals.minutes, lastSleepTimerMinutes, lastSleepTimerMinutes)
|
||||
val lastSleepTimerSeconds = config.lastSleepTimerSeconds % 60
|
||||
val parts = mutableListOf<String>()
|
||||
if (lastSleepTimerMinutes != 0) {
|
||||
parts.add(resources.getQuantityString(R.plurals.minutes, lastSleepTimerMinutes, lastSleepTimerMinutes))
|
||||
}
|
||||
if (lastSleepTimerSeconds != 0) {
|
||||
parts.add(resources.getQuantityString(R.plurals.seconds, lastSleepTimerSeconds, lastSleepTimerSeconds))
|
||||
}
|
||||
val text = parts.joinToString(separator = " ")
|
||||
items.add(RadioItem(config.lastSleepTimerSeconds, text))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.flashlight.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.flashlight.R
|
||||
|
@ -11,23 +12,38 @@ class SleepTimerCustomDialog(val activity: Activity, val callback: (seconds: Int
|
|||
private val binding = DialogCustomSleepTimerPickerBinding.inflate(activity.layoutInflater)
|
||||
|
||||
init {
|
||||
binding.minutesHint.hint = activity.getString(R.string.minutes_raw).replaceFirstChar { it.uppercaseChar() }
|
||||
binding.dialogRadioView.check(R.id.dialog_radio_minutes)
|
||||
binding.timerValue.setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
dialogConfirmed()
|
||||
return@setOnEditorActionListener true
|
||||
}
|
||||
return@setOnEditorActionListener false
|
||||
}
|
||||
|
||||
activity.getAlertDialogBuilder()
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.apply {
|
||||
activity.setupDialogStuff(binding.root, this, R.string.sleep_timer) { alertDialog ->
|
||||
dialog = alertDialog
|
||||
alertDialog.showKeyboard(binding.minutes)
|
||||
alertDialog.showKeyboard(binding.timerValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialogConfirmed() {
|
||||
val value = binding.minutes.value
|
||||
val minutes = Integer.valueOf(if (value.isEmpty()) "0" else value)
|
||||
callback(minutes * 60)
|
||||
val value = binding.timerValue.value
|
||||
val minutes = Integer.valueOf(value.ifEmpty { "0" })
|
||||
val multiplier = getMultiplier(binding.dialogRadioView.checkedRadioButtonId)
|
||||
callback(minutes * multiplier)
|
||||
activity.hideKeyboard()
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
private fun getMultiplier(id: Int) = when (id) {
|
||||
R.id.dialog_radio_seconds -> 1
|
||||
R.id.dialog_radio_minutes -> 60
|
||||
else -> 60
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,19 +3,19 @@
|
|||
android:id="@+id/dialog_custom_sleep_timer_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextInputLayout
|
||||
android:id="@+id/minutes_hint"
|
||||
android:id="@+id/value_hint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/minutes_raw">
|
||||
android:hint="@string/value">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/minutes"
|
||||
android:id="@+id/timer_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
|
@ -24,7 +24,32 @@
|
|||
android:maxLength="5"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"
|
||||
android:imeOptions="actionDone"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
</com.simplemobiletools.commons.views.MyTextInputLayout>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/dialog_radio_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/normal_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_minutes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:text="@string/minutes_raw" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_seconds"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:text="@string/seconds_raw" />
|
||||
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue