mplekunov / CalculatorApp

GNU General Public License v3.0
1 stars 0 forks source link

Calculator Fragment #13

Closed mplekunov closed 2 years ago

mplekunov commented 2 years ago

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.

mplekunov commented 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:

  1. Normal
  2. Expanded

Normal already exists, need to move source code back into "normal_layout".

mplekunov commented 2 years ago

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...

mplekunov commented 2 years ago

So currently there are two solutions:

  1. Just use one layout for both expanded and normal layouts (hide/show unused part of layout on button press)
  2. Somehow figure out how to either extend Buttons wrapper... or I don't know... do somethings which would allow me to pass Buttons object with ALL possible mappings
mplekunov commented 2 years ago

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

mplekunov commented 2 years ago

then I can assign objects inflated by those classes in the calculatorFragment

mplekunov commented 2 years ago

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 🤣

mplekunov commented 2 years ago

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.

mplekunov commented 2 years ago

Changes between both layouts works btw... Everything is wired up without any problems... All the "old" features are working in the "new" layout

mplekunov commented 2 years ago

Need to fix layout aesthetically though, add new images and stuff