kdk-yahoo / tip-calculator

Kevin Keller's tip calculator project for the Code Path's Android course
0 stars 0 forks source link

[Android Bootcamp] Project 1 - Tip Calculator #1

Open kdk-yahoo opened 10 years ago

kdk-yahoo commented 10 years ago

I finished the project, though it doesn't look very pretty. I have a question. If you have a few buttons doing very similar things, like the tip buttons, do you recommend having several individual listener functions or one function with an if (or switch) statement and changing the behavior based off of which button is used?

Also a slight heads up, the code currently in the repo is a little more updated than what is shown in the gif. I changed the split feature from being an editText into a textView and added buttons to increment and decrement it. The feature is still there, but just don't want you to get confused since the gif and the code don't match up exactly.

Thanks, --Kevin Keller

/cc @nesquena @timothy1ee

nesquena commented 10 years ago

Notes: I my listener code is really ugly. How would you suggest I refactor it to make it cleaner?

Define the listeners as variables:

etPrice.addTextChangedListener(tipWatcher);

private TextWatcher tipWatcher = new new TextWatcher(){
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                //NOP
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                //NOP
            }

            @Override
            public void afterTextChanged(Editable s) {
                try{
                    price = Double.parseDouble(s.toString());
                    calcTip();
                }catch(NumberFormatException e){
                    s.clear();
                }
            }

});

Cleans it up a bit.

nesquena commented 10 years ago

If you have a few buttons doing very similar things, like the tip buttons, do you recommend having several individual listener functions or one function with an if (or switch) statement and changing the behavior based off of which button is used?

One listener and switch using the id to determine the behavior.

nesquena commented 10 years ago

:+1: Looks good Kevin, good to see you got in a number of optionals and played around with the UI. I have provided a detailed Project 1 Feedback Guide here which covers the most common issues with this submitted project. Read through the feedback guide point-by-point to determine how you could improve your submission. You should consider going back and implementing applicable feedback as well. Keep in mind that one of the most important parts of Android development is learning the correct patterns and conventions.

Hopefully this has given you a first sense of the RelativeLayout which is a very powerful layout system, probably one of the best responsive-first layout systems available across web and mobile platforms.

I would encourage you to also spend more time in future assignments improving the UI / UX as well by reviewing examples of good UI design.

The next assignment will build on top of the first concepts introduced here and will also introduce networking, api use, handling remote images and navigating between activities.

If you have any particular questions about the assignment in general or on any of the feedback, feel free to reply here or post on the discussion forum.