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:
applicationmodeluiutil
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.xmllayout and examine the pre-createdTextViewfields. Take note of their names. - In the
displayProductDetailsmethod you'll want to set the fields from your model into the appropriateTextViewsin the layout. - Use the
TextUtilsyou defined from Part 3 - Display today's date in the
orderDateTextView. Use the appropriateDateUtilsmethod for formatting. - Search the code for any remaining
TODOitems, 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?