Office Hours — Today, October 29

Saturday, October 26

Oct 29
8:20 AM
Mark M.
has entered the room
8:25 AM
Mark M.
turned on guest access
9:15 AM
Scott W.
has entered the room
Mark M.
hello, Scott!
how can I help you today>
er, today?
Scott W.
Hey Mark
well I was just coming to the site to see if one of the resources talked about Navigation
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*
and the app built in the tutorials in *Exploring Android* also uses navigation
Scott W.
does it use androidx.navigation.safeargs?
Mark M.
yes
9:20 AM
Scott W.
ok so I just tried implementing that following the d.android.com guide, and I'm completely lost
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
?
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
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())
the chat is just about over -- any last questions?
9:30 AM
Scott W.
ah sorry I was reading
yeah 1 question
"A class to help code wishing to navigate to that screen provide the data, with the expected data types"
this is in that chapter
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
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
and those static methods take parameters based on the action's arguments
where the parameter types are determined by how those action arguments are configured on the action
sorry -- the arguments are on the destination, not the action
so, for example, see https://gitlab.com/commonsguy/cw-jetpack-kotlin... -- the displayFragment takes a modelId argument that is of type String
so, the displayModel() method on ListFragmentDirections takes a String parameter to supply as the argument to DisplayFragment
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
er, shortly
the next chat is Thursday at 7:30pm US Eastern
Scott W.
thank you. I'm starting to get it
9:35 AM
Mark M.
good to hear!
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

Saturday, October 26

 

Office Hours

People in this transcript

  • Mark Murphy
  • Scott Wehby