Today I’ve been working thru chapter 3 of the book. Chapter 3 covered a lot.
Chapter 3 started off by discussing Activities. MainActivity extends ComponentActivity.
The entry point to MainActivity is configured in the AndroidManifest, and calls the
onCreate function. ComponentActivity defines a version of this function that is then overridden by the implementation of `MainActivity`.
Composable functions get the annotation of
Lifecycle functions include:
The example uses OutlinedTextField, which you have to import from Material Experimental API in order to use.
If you copy and paste code, be careful to make sure you end up having the correct package name otherwise your code will not compile. Also the package name relates to the directory structure, this is something that was carried over from Java.
Both Activities and Fragments are UI containers, they primarily exist in XML. Compose uses functions for the UI, they get set to the view with
setContent function. Fragments are more complex then Activities, but they also add reusability.
Strings have their own XML file that is useful for translation. Using
strings.xml, the book goes into how to set that up.
To convert the text input from hard coded, you need
It covers the basics of creating breakpoints and starting the application in
Debug mode. The icon to start in
Debug mode looks kinda like a bug.
It also goes thru Android Manifest. Which controls a lot about the application.
Next part of the day was going thru Chapter 5.
Jetpack Compose is a replacement for XML-based Layouts.
Moving MVVM (Model-View-View-Model) to MVI (Model-View-Intent). Another architecture acronym. MVI is setup in such a way that there is unidirectional dataflow. Datasources can be abstracted using Repository pattern. Something called
Flow exists that controls where the data transfers, has emitters and subscribers, kinda sounds like Broadcaster-Receiver thing.
It shows how to create a new Package, and alsao has us create a ConversationContent composable.
Components that I’ve seen so far in the book: Column, Button, Outlined TextField, Text.
Android specifically requires Component names to be in
If you want to jump into the class definition, CMD-Click or CTRL-Click, this is useful to show you all the parameters you can pass into a function.
Layout Groups; elements that help arrange UI; include:
It runs thru some information about how Android Preview system works.
If you want to make the application not compile cause you have an empty function scaffolded out, you can put
TODO("Not Yet Implemented") in the function to halt compilation.
Modifiers seem to power a lot of the functionality of Jetpack Compose.
Lists are very important to the structure of mobile apps, they come as
LazyRow in Compose.
There is a package for handling DateTime:
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0") this goes in the Gradle file.
Coming from Swift computed properties, I’m glad to see that Android has similar feature:
val authorImage: Int = if (userId == "me") R.drawable.profile_photo_android_developer else R.drawable.someone_else appears to be a computed property.
There is a modifier that is known as
.weight it is meant to help you lay out dynamic layouts promotional to the other component weights. If the others don’t have a
.weight on it it will take up all remaining space in the parent component.
It talks about bringing in Google Fonts into the application.
implementation("androidx.compose.ui:ui-text-google-fonts:1.5.4") is required for that.
That is it for the bootcamp for today, I’ll be working thru a video and building along with it tomorrow. See the notes from that on here tomorrow.