In this project we'll begin to explore keeping code well-organized into logical packages.
- organize code between activities and models / classes
- explain the importance of packages for code organization
- learn how to keep code DRY
Start with the assignment project in the current repo.
Add packages called:
application
model
ui
util
Move the existing app code to the appropriate packages.
Open TextUtils
and complete the util methods, as specified in the comments. You'll have to look at the documentation and examples for the NumberFormat
class to complete this step.
This model will represent a product we're selling and will include the normal characteristics of a product. Fields defined in this model should include:
productName
- the product's nameproductDescription
- the product's descriptionproductPrice
- the product's priceproductTax
- the dollar-amount of tax for this itemproductDiscount
- the percent discount for this item
(Hint: You should use a Kotlin data class for the model.)
You'll need to complete the displayProductDetails
method in MainActivity.
- Instantiate the model from Part 4. You can give your product any kind of name, description and other characteristics that you want.
- Open the
activity_main.xml
layout and examine the pre-createdTextView
fields. Take note of their names. - In the
displayProductDetails
method you'll want to set the fields from your model into the appropriateTextViews
in the layout. - Use the
TextUtils
you defined from Part 3 - Display today's date in the
orderDate
TextView
. Use the appropriateDateUtils
method for formatting. - Search the code for any remaining
TODO
items, and fix any bugs.
How would you make your model available to every screen in your Application
? What are the pros and cons to doing this?