Darkempire78 / OpenCalc

A simple and beautiful calculator for Android
GNU General Public License v3.0
740 stars 83 forks source link

Do not allow duplicate math symbols on input #161

Closed lefterisgar closed 1 year ago

lefterisgar commented 1 year ago

This PR attempts to fix #126. It disables certain buttons, like divide or multiply if another symbol has been typed without a number separating the two. Only issue is that if you press for example the plus (+) button by accident, and you want a subtraction, clicking the minus (-) button will do nothing. You need to erase the + and then enter the -. Code-wise I think it doesn't look any clean but you will hopefully be able to make it better :)

Darkempire78 commented 1 year ago

Instead of blocking buttons, it will be better to replace the previous symbol when you click on another

lefterisgar commented 1 year ago

Instead of blocking buttons, it will be better to replace the previous symbol when you click on another

Yes, my approach is wrong.

lefterisgar commented 1 year ago

I've rewritten it from scratch! What do you think now? If you find any issues, let me know. 😀

Darkempire78 commented 1 year ago

I found a small bug, if I write 5x2, then I add a % between the 5 and the x, it will replace the x with the % (result : 5%2 instead of 5%x2)

lefterisgar commented 1 year ago

I found a small bug, if I write 5x2, then I add a % between the 5 and the x, it will replace the x with the % (result : 5%2 instead of 5%x2)

Is it fixed now?

Darkempire78 commented 1 year ago

It looks perfect

lefterisgar commented 1 year ago

Code-wise it's terrible but I trust you :)

Darkempire78 commented 1 year ago

I found another bug. If I write -5-, then if I set the cursor at the position 0 and I click to + for example, the result will be -5+ instead of +5-

Darkempire78 commented 1 year ago

Otherwise I think the code can be slightly simplified for more clarity

Darkempire78 commented 1 year ago

And the final bug is with the decimal separator symbol and the grouping separator symbol. For example if I write "5,555", the comma will be replaced if a add a + next to the comma. In addition do not forget that every country has its own separator, use the variable instead of writing it manually 😀 I will check tomorrow if there is more issues

lefterisgar commented 1 year ago

And the final bug is with the decimal separator symbol and the grouping separator symbol. For example if I write "5,555", the comma will be replaced if a add a + next to the comma. In addition do not forget that every country has its own separator, use the variable instead of writing it manually grinning I will check tomorrow if there is more issues

Hey! Everything you reported should be fixed now. However the code leaves a lot to be desired. It needs a refactor because it looks anything but clean...

lefterisgar commented 1 year ago

Small bug: Type "sq" "-" and then press "+". It will display: "sq" "+".

Darkempire78 commented 1 year ago

Small bug: Type "sq" "-" and then press "+". It will display: "sq" "+".

I did not understand the bug, sorry

lefterisgar commented 1 year ago

Small bug: Type "sq" "-" and then press "+". It will display: "sq" "+".

I did not understand the bug, sorry

No problem! I just realized that you aren't supposed to enter minus when inside a square root. However there is another related bug I found.

If you type an empty square root and then press a symbol (for example division) it will be accepted. Then we will have √/ or √^ for example. This shouldn't be allowed.

lefterisgar commented 1 year ago

Should be good now.