Oct 29 | 8:20 AM |
Mark M. | has entered the room |
Oct 29 | 8:25 AM |
Mark M. | turned on guest access |
Oct 29 | 9:15 AM |
Scott W. | has entered the room |
Mark M. |
hello, Scott!
|
Mark M. |
how can I help you today>
|
Mark M. |
er, today?
|
Scott W. |
Hey Mark
|
Scott W. |
well I was just coming to the site to see if one of the resources talked about Navigation
|
Scott W. |
I saw that office hours were live so I popped in.
|
Mark M. |
I cover some of the basics of the Navigation component in *Elements of Android Jetpack*
|
Mark M. |
and the app built in the tutorials in *Exploring Android* also uses navigation
|
Scott W. |
does it use androidx.navigation.safeargs?
|
Mark M. |
yes
|
Oct 29 | 9:20 AM |
Scott W. |
ok so I just tried implementing that following the d.android.com guide, and I'm completely lost
|
Scott W. |
it says it should generate some code for me, but I don't see what triggers the generation or where the code would be.
|
Mark M. |
there is a plugin that you add to your Gradle build file
|
Scott W. |
got it
|
Mark M. |
that will examine your navigation resources and generate classes for them
|
Scott W. |
ok I have a nav_graph.xml with 3 fragments and 2 actions connecting them
|
Mark M. |
the origin of each action gets a ...Directions class (e.g., RosterListFragmentDirections), with methods for each action starting at that origin, with the method names based on the action IDs
|
Scott W. |
I'm assuming I've set this up wrong then. So, if I fix it, how does safeargs know to try and generate the code again
|
Scott W. |
?
|
Mark M. |
I would hope it does it automatically -- worst-case, clean and rebuild the project from the Android Studio Build menu
|
Scott W. |
would the files be in app/src/main/java/com.whatever/?
|
Mark M. |
well, they are code-generated, so they will be in build/ somewhere
|
Oct 29 | 9:25 AM |
Mark M. |
the ...Directions class should be in the same package as is the origin fragment class
|
Scott W. |
I see
|
Mark M. |
for example, in https://gitlab.com/commonsguy/cw-jetpack-kotlin..., I refer to a ListFragmentDirections class, and I do not need an import for it, as it is in the same package as is ListFragment itself
|
Scott W. |
ok
|
Mark M. |
similarly, there will be an ...Args class generated for each destination (see https://gitlab.com/commonsguy/cw-jetpack-kotlin... and its use of DisplayFragmentArgs and navArgs())
|
Mark M. |
the chapter for those samples is https://wares.commonsware.com/app/internal/book...
|
Mark M. |
the chat is just about over -- any last questions?
|
Oct 29 | 9:30 AM |
Scott W. |
ah sorry I was reading
|
Scott W. |
yeah 1 question
|
Scott W. |
"A class to help code wishing to navigate to that screen provide the data, with the expected data types"
|
Scott W. |
this is in that chapter
|
Scott W. |
is that sentence correct? If so, what is code wishing?
|
Mark M. |
that sentence is a bit awkward, but I'd need to see it in context
|
Mark M. |
if you want to navigate from ListFragment to DisplayFragment, you use a ListFragmentDirections class
|
Scott W. |
ok. well I'll get to reading through this stuff. Thanks for the help!
|
Mark M. |
that will have static methods based on action IDs
|
Mark M. |
and those static methods take parameters based on the action's arguments
|
Mark M. |
where the parameter types are determined by how those action arguments are configured on the action
|
Mark M. |
sorry -- the arguments are on the destination, not the action
|
Mark M. |
so, for example, see https://gitlab.com/commonsguy/cw-jetpack-kotlin... -- the displayFragment takes a modelId argument that is of type String
|
Mark M. |
so, the displayModel() method on ListFragmentDirections takes a String parameter to supply as the argument to DisplayFragment
|
Mark M. |
and... that's a wrap for today's chat
|
Scott W. |
ok
|
Mark M. |
the transcript will go up on https://commonsware.com/office-hours/ shortyl
|
Mark M. |
er, shortly
|
Mark M. |
the next chat is Thursday at 7:30pm US Eastern
|
Scott W. |
thank you. I'm starting to get it
|
Oct 29 | 9:35 AM |
Mark M. |
good to hear!
|
Mark M. |
and, have a pleasant day!
|
Scott W. |
ok. Thank you thank you. Have a good day!
|
Scott W. | has left the room |
Mark M. | turned off guest access |