maxkeppeler / sheets-compose-dialogs

✨ Enhancing Android UIs: A Jetpack Compose Library supporting a wide range of common use-cases with Material Design 3 Dialogs, Popups, and Bottom Sheets. ✨
https://maxkeppeler.github.io/sheets-compose-dialogs/
Apache License 2.0
780 stars 32 forks source link

[Feature request] Allow submitting a Duration of zero when using DurationDialog #45

Closed PeterKastner closed 1 year ago

PeterKastner commented 1 year ago

Hi, first of all - thank you for this amazing library and all the work you have put into this project!

I am developing a work time tracking app, where users shall be able to input the duration of their pause / break time as well. For this I've already seen that using a DurationDialog would be just the perfect choice, as I've modelled the pause with a Duration.

I have a use case in which users can longtap on the duration of their pause of the respective tracked work time to input or adjust the duration of the pause / break - however, the DurationDialog does not allow to submit a Duration of zero - could this be added as a customisation option, so that a duration of zero / newTimeInSeconds of 0L could be submitted in onPositiveClick: (Long) -> Unit lambda?

As of right now, the positive click button remains in disabled state, "forcing" users to choose a duration > 0, leaving them unable to set a pause duration of Duration.ZERO if they would like to change it back again.

Screenshot of DurationDialog cleared with positive button disabled

I believe this would involve an enhancement of the libraries' internal class DurationState to allow validation of a timeInfoInseconds of = 0 in isValid()

Thank you in advance for considering this!

One day I hope to be able to submit a PR, however right now I'm too new to android development and programming in general...

Thanks you in advance for letting me know what you think about this feature request and thank you for this project!

Happy easter and best regards from the town of Karlsruhe =)

maxkeppeler commented 1 year ago

Hey Peter, thanks for the feature request. Happy to hear that you are using my library.

It's a quick and small change which makes absolutely sense, especially considering there's a min & max value support for the Duration View/ Dialog to restrict the value range. Your analysis is correct. I will make the change soon. 😁

Though it might take a bit longer until create a version of the sheets library. Usually, I want to include or fix a few more things.

No problem, one day then! If you need any help with Android/ Kotlin etc., feel free to contact me. Happy Easter to you as well! :)

maxkeppeler commented 1 year ago

I have implemented a check to ensure that the input falls within the minimum and maximum time bounds as defined in the DurationConfig. When a user enters a time value that is invalid due to it being outside the allowed range, a hint will be displayed to inform them about the time restrictions. However, when the minimum time is set to 1 and the user enters nothing or 0, the hint will not be displayed. This approach feels more natural as it avoids causing abrupt layout changes due to input invalidity, given that the default value in the DurationDialog is always zero and only gets updated with new values. Despite having an empty or zero input, the "Ok" button remains clickable.

PeterKastner commented 1 year ago

Hello Max, thanks a lot for implementing this feature so quickly, really neat!

The solution is interesting, I hadn't thought about all the things that have to be considered in order to allow a duration of zero - looking forward to the next version of the library then!

And also thanks for the offer, let's keep in touch here or on another platform - I feel that I can learn a lot about Android/Kotlin just from your project here.

Best regards,

Peter