maltaisn/calcdialoglib

Implement a way to calculate a long expression

Closed this issue · 6 comments

Implement a way to calculate expressions like 2+4*5+5*2-3 = 29

Today the lib give us the result when tap any operation signal. But some situations need put an expression and ask for the result when tap on = button.

I think is better show all expression, not clear the textView when tap any operation signal.

Yes, the library was inspired by simpler calculators and meant for simple calculations, but I agree it would be extremely useful to show the expression when it is longer. I would add a setting like setShowExpression(boolean) to the dialog, which would show an expression beside the current value, and the expression is appended every time an operation is clicked (like most calculators do). The expression view would probably need to be scrollable. There are a few things that would need to be adjusted, like the answer value, but nothing too complicated.

I think you deleted your comment, but if you're still interested in making a pull-request for this feature I would be glad to review it. Otherwise, I will probably make a new release this weekend.

Great!
I found a good library to make easy the calc if you like: https://lallafa.objecthunter.net/exp4j/

I really want help you but I deleted my comment because I won't time to focus right now. I expect back soon.

I probably won't use the library since I don't want to introduce a new dependency to the library. Evaluating a simple expression isn't the most complicated thing to do anyway.

I just looked at the code and realized it needs major refactoring. I'm going to replace all formatting settings with the use of NumberFormat and provide better Kotlin support notably.

So don't mind making a pull request, I'll release 2.0.0 with many breaking changes (but no functionality lost), the expression view and operation priority in a few weeks.

I just finished adding all the new features and refactoring, you can take a look at the full changes in the changelog. You can test the expression to see if that's what you expected. I'll release 2.0.0 soon.

Added in v2.0.0