Add option to disable for hours

Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
William Brawner 2021-01-10 14:11:39 -07:00
parent 53cd8c7312
commit b6bf045fd0
3 changed files with 25 additions and 17 deletions

View file

@ -132,24 +132,25 @@ class MainFragment : Fragment() {
.create()
.apply {
setOnShowListener {
getButton(AlertDialog.BUTTON_POSITIVE).setSuspendingOnClickListener(
lifecycleScope
) {
try {
val rawTime = dialogView.time
.text
.toString()
.toLong()
val checkedId =
dialogView.timeUnit.checkedRadioButtonId
val computedTime = if (checkedId == R.id.seconds) rawTime
else rawTime * 60
viewModel.disablePiHole(computedTime)
dismiss()
} catch (e: Exception) {
dialogView.time.error = "Failed to disable Pi-hole"
getButton(AlertDialog.BUTTON_POSITIVE)
.setSuspendingOnClickListener(lifecycleScope) {
try {
val rawTime = dialogView.time
.text
.toString()
.toLong()
val computedTime =
when (dialogView.timeUnit.checkedRadioButtonId) {
R.id.seconds -> rawTime
R.id.minutes -> rawTime * 60
else -> rawTime * 3600
}
viewModel.disablePiHole(computedTime)
dismiss()
} catch (e: Exception) {
dialogView.time.error = "Failed to disable Pi-hole"
}
}
}
}
}
.show()

View file

@ -40,5 +40,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/duration_minutes" />
<RadioButton
android:id="@+id/hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/duration_hours" />
</RadioGroup>
</LinearLayout>

View file

@ -46,4 +46,5 @@
<string name="action_authenticate_api_key">Authenticate with API Key</string>
<string name="connecting_to_pihole">Connecting to Pi-hole…</string>
<string name="action_cancel">Cancel</string>
<string name="duration_hours">Hours</string>
</resources>