Feb 12 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Feb 12 | 7:25 PM |
Sainath R. | has entered the room |
Mark M. |
hello, Sainath!
|
Mark M. |
how can I help you today?
|
Feb 12 | 7:30 PM |
Sainath R. |
Hello Mark. How are you doing today?
|
Mark M. |
OK, and you?
|
Sainath R. |
Im doing good too.
|
Mark M. |
do you have a question that I can try to answer?
|
Sainath R. |
View paste
|
Sainath R. |
I do not have any questions as of now.
|
Mark M. |
OK
|
Mark M. |
thanks for the kind words!
|
Sainath R. |
I was reading the Elements of Kotlin book and saw that the chat session is live.
|
Mark M. |
ah!
|
Sainath R. |
I dropped in just to say Hi.
|
Mark M. |
usually, people only come to the office hours when they have questions
|
Anshul V. | has entered the room |
Mark M. |
hello, Anshul!
|
Sainath R. |
Is there a place where we can know the schedule for the next office hours?
|
Anshul V. |
Hi Mark, hope you are doing well!
|
Mark M. |
Sainath: in the Warescription site, click on Ask > Office Hours in the nav bar
|
Feb 12 | 7:35 PM |
Mark M. |
Anshul: I am doing well -- and you?
|
Mark M. |
Anshul: do you have any questions that I can answer?
|
Anshul V. |
I am doing good, thank you for asking!
|
Sainath R. |
Thanks Mark, found it. Will keep an eye and join in the future.
|
Mark M. |
sounds good!
|
Mark M. |
if either of you have a question, just ask!
|
Anshul V. |
Yes, it is more of a design question. I am making an API call, and the result is a list<Profiles>, now depending on the age range of profiles, I need to show either a different screen layout with the list of profiles as radio button options or if there are no eligible profiles, I need to show a different layout. Should I implement two separate activities for this or should I just do setContentView() after the API call is completed and render the view accordingly?
|
Mark M. |
what is in the layout for the no-eligible-profiles case?
|
Feb 12 | 7:40 PM |
Anshul V. |
it just displays a text view saying no eligible profiles and a button to let the user add another profile within the age range if he/she wants to
|
Mark M. |
usually, that is handled by a single layout
|
Mark M. |
you would have a RecyclerView (or, in older days, a ListView) for the list of profiles
|
Mark M. |
the layout would also have widgets representing the "empty state", to show when the list is empty
|
Mark M. |
sometimes, there is also 1+ widgets for a "loading state", such as during the network I/O
|
Mark M. |
you toggle the visibility of the widgets as needed
|
Mark M. |
so, for example, your layout resource might start with the loading state widgets as visible and the list and empty states as invisible/gone
|
Mark M. |
then, when your network call completes, you make the loading state widgets be invisible/gone and make either the list or the empty state widgets be visible, depending on whether you have any data to display
|
Anshul V. |
Ah, I see, so if the list is there, no eligible screen views remain hidden, but if it is the other way around, list becomes hidden and the other views are shown.
|
Mark M. |
correct
|
Mark M. |
and all of that is managed by a single activity or fragment
|
Feb 12 | 7:45 PM |
Mark M. |
in "Exploring Android", the sample app has this sort of setup... or it did in Version 0.3
|
Mark M. |
I just released Version 0.4 ~10 hours ago, and as part of rewriting the book for Kotlin and the Jetpack libraries, I only have a subset of the tutorials right now
|
Mark M. |
but if you happen to have a copy of Version 0.3 that you downloaded, that will show the list + empty state approach
|
Anshul V. |
hmm, okay! Now, I am not sure if recycler view is a way to go since I am adding radio buttons dynamically based on the size of list, so user can choose any one of them and proceed with that profile.
|
Anshul V. |
Oh, yes, I do have v0.3 of the book! Thanks, I will check it out
|
Mark M. |
the same principle would hold if you are using a RadioGroup wrapped in a ScrollView
|
Anshul V. |
That makes sense, RadioGroup wrapped in a ScrollView
|
Mark M. |
so long as your list is not too long, and you really really really want radio buttons, that's the approach to take
|
Anshul V. |
Now, since the radiobuttons are being populated dynamically, we do not have any way to modify how we display those, for ex, spacing, or a view separator in between, do we depend on Android to render the views by itself?
|
Anshul V. |
Yes, that is the case, list not too long, and I really really really need radio buttons
|
Mark M. |
"we do not have any way to modify how we display those, for ex, spacing, or a view separator in between" -- padding, margins, and other Views interspersed in the list are all possible dynamically
|
Feb 12 | 7:50 PM |
Mark M. |
"do we depend on Android to render the views by itself?" -- sorry, but I am not certain what you mean by this
|
Mark M. |
and having radio buttons in a RecyclerView should be possible, though I haven't done that personally, and you would need to manage the mutual-exclusion stuff yourself
|
Anshul V. |
well, I implemented the dynamic populating of radio buttons with a radio group, and I did not mention any sort of conditions on how the layout should look like, but it gets populated as a list of radio buttons by itself without me mentioning any layout paddings/margins
|
Mark M. |
you used addView() to add the RadioButton widgets to the RadioGroup, right?
|
Anshul V. |
yes, that is correct
|
Mark M. |
one flavor of addView() takes a LayoutParams along with the View to be added, and in there, you specify margins
|
Anshul V. |
Ah, that is GTK!
|
Mark M. |
for padding, you call setPadding() on the RadioButton
|
Mark M. |
for a divider, you would create a View with a background color, and you would use addView() to add it with your desired height (to control the thickness of the divider)
|
Feb 12 | 7:55 PM |
Mark M. |
or, if you don't want a solid-color divider, use some sort of drawable as the background
|
Feb 12 | 7:55 PM |
Mark M. |
RadioGroup is really just a vertical LinearLayout with special support for RadioButton, so AFAIK you can add other non-RadioButton widgets to the RadioGroup if needed
|
Anshul V. |
that's awesome, I did not know that! I'd definitely add a solid-color layout
|
Anshul V. |
solid-color separator*
|
Anshul V. |
Now, building on the previous question, it might be the case that there's an intent from outside the app (a web deep link) can request either the radio button list view, or the no eligible profile views, does it still makes sense to keep them in the single activity?
|
Mark M. |
how would an outside party know whether or not there are eligible profile views?
|
Mark M. |
regardless, you could still handle that all in one activity, using an Intent extra, query parameter on the URL, or something else in the deep link to indicate what UI to use
|
Anshul V. |
well, via an email sent to the user who has created a profile/some profiles previously.
|
Feb 12 | 8:00 PM |
Mark M. |
unless you have something that limits the time for how long those URLs are good for, you cannot assume the state of your server when the user clicks the link
|
Anshul V. |
yep, the deep link has two separate paths, /no_eligible_profile and /select_profile
|
Anshul V. |
so basically 2 deep links
|
Mark M. |
if the normal case can be handled by a single activity toggling the visibility of widgets based on the API call response, supporting an "override" based on a path segment of the URL could still be handled by that activity
|
Mark M. |
I think you may run into problems, but those problems are more tied to assumptions about the state of the server, not so much rendering the UI
|
Mark M. |
for example...
|
Mark M. |
1. user creates a profile
|
Mark M. |
2. user gets email with the /select_profile link
|
Mark M. |
3. the profile is deleted (by the user, by a server problem, whatever)
|
Mark M. |
4. user clicks the /select_profile link
|
Mark M. |
if my understanding is correct, the default result would be that the user gets an empty list
|
Mark M. |
because you are trying to say "show the profiles" and there are none
|
Mark M. |
now, with sufficient smarts in the activity, you can try to handle these edge cases
|
Mark M. |
but -- bearing in mind that I know nothing about your app other than what you have written here -- my preference would be for there to be one deep link, just to the activity, which displays whatever it would normally display, based on the server contents
|
Feb 12 | 8:05 PM |
Anshul V. |
hmm, I see. Yes, that would be the way to go. Server checks the state of the saved user and based on that will send either /select_profile or /no_eligible_profile
|
Anshul V. |
so a user cannot receive /no_eligible_profile if he/she has made 1 or more profiles which are in the age range
|
Anshul V. |
so, there will be 2 methods in the activity toggling the views visibility based on the deep link received/or the api call contents, is what you'd suggest I do?
|
Mark M. |
in terms of whether to have one activity or two, yes
|
Feb 12 | 8:10 PM |
Anshul V. |
okay, thank you! Mark, this helps :)
|
Anshul V. |
Have a good evening!
|
Mark M. |
you too!
|
Anshul V. | has left the room |
Feb 12 | 8:15 PM |
Mark M. |
Sainath: if you have a question, feel free to ask!
|
Sainath R. |
View paste
|
Sainath R. |
Have a good evening!!
|
Mark M. |
you too!
|
Sainath R. |
thanks!
|
Sainath R. | has left the room |
Feb 12 | 8:25 PM |
Mark M. | turned off guest access |