Closed mplekunov closed 2 years ago
So... The next step is to implement "expand" button which would give user an access to "functions", "parenthesizes" and all other additional stuff...
To do that less painfully, I need to have 2 different layouts for calculator:
Normal already exists, need to move source code back into "normal_layout".
So... After looking at fragments and layouts... the simplest way would be to create a different layout, then inflate that layout in the onCreateView() inside of the CalculatorFragment. Once it's inflated we can return binding object and use it in "Buttons" wrapper to map those buttons to Enums.
This idea works perfectly (I just tested it)... however, there is a problem... I want to have 2 different layouts. One for normal version of calculator and the other for expanded. I could inflate both of those and put them into the map... then, on button press I can attach needed inflated XML to the FrameLayout of CalculatorFragment.... This works fine until we realize that I need to pass "ViewDataBinding" object into the Buttons.... and.... in the case of two layouts... There are going to be different class names for each of them...
So currently there are two solutions:
So... I don't really need to use maps or anything like that... I can just use layout classes that extend ViewDataBinding to inflate them
then I can assign objects inflated by those classes in the calculatorFragment
And use those objects as needed... however the problem stays the same... I don't wanna pass several objects... I guess I need to clarify what EXACTLY I want before thinking how I can do it 🤣
So... After resting and thinking about this... The only way I could came up with is a bit "dirty"....
In essence... Positives: All classes of "editable" feature are easily expandable for the "expanded" version of the layout... That means I have followed an Open/Closed Principle... HOORAY 🥳 Negatives: The only way I could came up with regarding of how to remap buttons to Enums was... well... Remapping them each time when "change layout" button is pressed... It's quite easy but does take a bit of space which annoys me a lot... That being said, I don't see any other ways right now.
Changes between both layouts works btw... Everything is wired up without any problems... All the "old" features are working in the "new" layout
Need to fix layout aesthetically though, add new images and stuff
Code wise... I need to change the way calculator fragment (layout) is implemented... Originally, I wanted to make CalculatorFragment to load specific calculator layout based on situation... For instance, expanded calculator is one layout, normal calculator is another layout.
The idea was discarded due to complexity... it has to be fixed now.