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() .create()
.apply { .apply {
setOnShowListener { setOnShowListener {
getButton(AlertDialog.BUTTON_POSITIVE).setSuspendingOnClickListener( getButton(AlertDialog.BUTTON_POSITIVE)
lifecycleScope .setSuspendingOnClickListener(lifecycleScope) {
) { try {
try { val rawTime = dialogView.time
val rawTime = dialogView.time .text
.text .toString()
.toString() .toLong()
.toLong() val computedTime =
val checkedId = when (dialogView.timeUnit.checkedRadioButtonId) {
dialogView.timeUnit.checkedRadioButtonId R.id.seconds -> rawTime
val computedTime = if (checkedId == R.id.seconds) rawTime R.id.minutes -> rawTime * 60
else rawTime * 60 else -> rawTime * 3600
viewModel.disablePiHole(computedTime) }
dismiss() viewModel.disablePiHole(computedTime)
} catch (e: Exception) { dismiss()
dialogView.time.error = "Failed to disable Pi-hole" } catch (e: Exception) {
dialogView.time.error = "Failed to disable Pi-hole"
}
} }
}
} }
} }
.show() .show()

View file

@ -40,5 +40,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/duration_minutes" /> 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> </RadioGroup>
</LinearLayout> </LinearLayout>

View file

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