davidhealey / waistline

Libre calorie counter app for Android. Built with Cordova.
532 stars 63 forks source link

Allow calculations in quantity and serving size #221

Open davidhealey opened 3 years ago

davidhealey commented 3 years ago

I think it would be cool if you could do simple maths in these fields and have the other fields update accordingly.

For example if an item is a 200g serving and you want to know what half of it would be you could just enter into the box 200/2 or 200*0.5. Obviously with 200 it's not difficult to work out in your head but if it was a more obscure value like 372.5g it would be very helpful.

h-h-h-h commented 2 years ago

The vector graphics editor Inkscape can do this, e.g., in the little textboxes for x and y position or for width and height of a selected object.

I wanted to address my usage, anyway, which is related to this: I very often do before- and after-weighing to calculate the net material that really landed in my stomach. To save the before-weight, I set it as serving size divided by 1000 (so, e.g., .216 for 216 g). Later, I consult the value, do the after-weighing and calculate the actual value to be set as serving size.

This usage should actually find more support by the app and be made easier. For this, we'd need a new way to specify the value in "Serving Size" or "Number of Servings" as preliminary, incomplete or some such (also in the quantity popup). Meanwhile, it should be treated as 0, leading to 0 kcal. That state should be represented in the diary overview (subtly different background color?). Then, when you've got the after-weight, the "Serving Size" or "Number of Servings" textbox could do the subtraction calculation. For this, it'd be ideal, if a preliminary/incomplete entry would open in its edit mode with the respective textbox focused, cursor at the end and having content of the form 216-. After entering the after-weight and applying, the preliminary/incomplete state of the entry vanishes. EDIT: That state could, of course, just be called into existence whenever a textbox contains an incomplete calculation like 216-.

It'd be good, if both weights would still be accessible and not calculated away, e.g., in case you made a mistake and don't remember the values. EDIT: Besides always keeping the calculation in the textbox, this could also be accomplished with an icon button that appears only when the current value was derived from a calculation in the textbox and that, on tap, replaces the textbox contents with the previous calculation text; whenever the textbox is defocused it would replace its contents with the result.

EDIT: Another use case: I have a package Ferrero Pocket Coffee, type in the 100-g values, then do the following calculation in the "Serving Size" textbox: 100*2.25/18 (100 g grossed up to 225 g package weight, divided by 18 pieces per package). Then, I turn off linking and replace the now "12.5 g" with "1 piece(s)".