Calculator icon indicating copy to clipboard operation
Calculator copied to clipboard

Implement negative temperature conversion (#44)

Open Lionheart-Y2J opened this issue 8 months ago • 2 comments

What is it?

  • [ ] Bugfix
  • [x] Feature
  • [ ] Codebase improvement

Description of the changes in your PR

  • Added +/- button for temperature converter
  • Implemented toggleNegative() method in ConverterView to handle sign changes
  • Set conditional button visibility (only for temperature)

Before/After Screenshots/Screen Record

  • Before: No button for negative values before_temp

  • After: +/- button appears below numpad (only in temperature converter) after_temp

Fixes the following issue(s)

  • Fixes #44 (Add +/- to Temperature Unit Converter)

Relies on the following changes

  • Updated view_unit_converter.xml layout (new LinearLayout container with id plus_minus_layout)
  • Updated UnitConverterActivity.kt button click handler and visibility logic for the +/-
  • Updated ConverterView.kt with sign toggle method and numpadClicked

Acknowledgement

Lionheart-Y2J avatar Mar 31 '25 18:03 Lionheart-Y2J

I've tested and found two issues:

  • +/- button should also work when there's no value. Most people first enter -, then the rest of the number.
  • Deleting a negative number causes a crash.

There are also two issues that I'm not sure whether we should address them in this PR:

  • There's no such thing as negative Kelvins and negative Rankines. It shouldn't be possible to enter a negative value for these units.
  • By analogy, you shouldn't allow entering values for Celsius and Fahrenheit that are below absolute zero.

Aga-C avatar Mar 31 '25 18:03 Aga-C

I fixed the crash issue (deleting negative value resets to 0) and added the possibility to use the - before entering a number.

Concerning the other remarks, I made sure to enforce temperature limits during input by automatically adjusting values that exceed absolute zero for each unit type: Celsius cannot go below -273.15, Fahrenheit below -459.67, and Kelvin/Rankine are blocked entirely from being negative (minimum 0)

Lionheart-Y2J avatar Mar 31 '25 19:03 Lionheart-Y2J

Hello @Aga-C Just checking in to see if there's anything else needed on this PR. I haven't planned to make any changes unless needed so if everything looks good, a review would be much appreciated. Thanks

Lionheart-Y2J avatar May 23 '25 19:05 Lionheart-Y2J

Hi! @Lionheart-Y2J

I'll do a final review and merge this soon.

Thanks.

naveensingh avatar May 24 '25 02:05 naveensingh

The functionality itself seems to work. Left some comments and nitpicks regarding the code.

naveensingh avatar May 31 '25 05:05 naveensingh