Mar 24 | 8:20 AM |
Mark M. | has entered the room |
Mar 24 | 8:25 AM |
Mark M. | turned on guest access |
Mar 24 | 8:30 AM |
Leora | has entered the room |
Leora |
Hi Mark!
|
Mark M. |
hello, Leora!
|
Mark M. |
how can I help you today?
|
Jan S. | has entered the room |
Mark M. |
and hello, Jan!
|
Leora |
A regular ol' question in these interesting times:
|
Jan S. |
Hello, everyone!
|
Leora |
Hi Jan!
|
Leora |
I have a recyclerView with a height of 0dp
|
Mark M. |
is that in a ConstraintLayout, so the height is determined by constraints?
|
Leora |
In my adapter I measure the height...it works great except for the first run on devices with a soft bottom navigation
|
Leora |
Yes
|
Mark M. |
why does your adapter need to measure the height?
|
Leora |
So I check the height of the navigation and add it...this also works great
|
Leora |
Oh, so the adapter takes the total height and does a calculation to determine the height of the items
|
Mark M. |
so, you're trying to exactly fit the items to the available space?
|
Leora |
Cause the number of items is set dynamically
|
Leora |
Yes
|
Leora |
Works excellent with hard nav buttons
|
Leora |
And now excellent with soft with first app run
|
Leora |
But
|
Mar 24 | 8:35 AM |
Leora |
when user clicks bottom nav, thus loading a new fragment, it STILL takes the height of the nav bar even though the bar is not visible
|
Leora |
When I implement onSystemUiVisibilityChange() it's too late
|
Leora |
(onBindViewHolder has already been called and the items already laid out)
|
Mark M. |
will this RecyclerView scroll? or are you trying to show all items at once?
|
Leora |
all items at once...static
|
Mark M. |
then I would not use RecyclerView
|
Mark M. |
no scrolling == no recyclingg
|
Mark M. |
er, recycling
|
Mark M. |
just put the items as children of the ConstraintLayout, and set up chains to allocate the whitespace
|
Leora |
actually I discussed this with you last year and came to the conclusion recycler best in this case
|
Mark M. |
OK
|
Mark M. |
I'll defer to "past me", then :-)
|
Leora |
i can't, the lite version shows banner adds and i animate the recyclerview children to smoosh them
|
Mark M. |
"when user clicks bottom nav, thus loading a new fragment, it STILL takes the height of the nav bar even though the bar is not visible" -- first, isn't the list gone? if not, where did this new fragment go?
|
Mar 24 | 8:40 AM |
Mark M. |
second, to be clear, the bar in question is the classic Android HOME/BACK/RECENTS bar? or by "bottom navigation" do you mean the Material Design bottom tabs thing?
|
Leora |
sorry, user clicks MY bottom toolbar
|
Leora |
and bar in question (for height and visibility) is android home etc
|
Leora |
the code i use to get the height is:
|
Leora |
View paste
|
Leora |
but it gets the height even when not visible :/
|
Mark M. |
you might want to look into the window insets stuff
|
Mark M. |
I think there is a Jetpack edition of those
|
Mark M. |
and I think it handles this scenario, more flexibly than relying on a magic resource
|
Leora |
i started to but the documentation says its waiting for the feature to be fully 'baked'
|
Mark M. |
even half-baked, it might help in your situation
|
Leora |
ok i'll try to muddle through it
|
Mark M. |
personally, I really try to avoid this full-screen stuff as much as possible, because it has always been a pain in various body parts
|
Mark M. |
and so when there's a Google library that aims to simplify it, I'd be all over that
|
Mark M. |
plus, the full-screen stuff is changing a bit in Android R
|
Leora |
how to avoid it? i need to measure item height
|
Mark M. |
I try to avoid that scenario, and when I can't, I try to let something else handle it (e.g., ConstraintLayout and chains)
|
Mar 24 | 8:45 AM |
Mark M. |
in your case, you may have no option
|
Leora |
could i still animate the views when a banner appears?
|
Mark M. |
with ConstraintLayout, yes -- you can animate the transition between ConsrtraintSets
|
Mark M. |
er, ConstraintSets
|
Mark M. |
(are typos a sign of COVID-19? if so, I'm doomed...)
|
Leora |
yes they are hahaha
|
Leora |
sorry to clear...
|
Leora |
i can animate the height of the items??? or only the constraints (margins) between them?
|
Mark M. |
I've used that sort of animation to animate the height of a bottom sheet, based upon changes in visibility of its contents
|
Mark M. |
there is probably a recipe for changing the actual item heights, though I can't be completely certain of that
|
Mark M. |
let me take a question from Jan, and I'll come back to you in a bit
|
Leora |
sure!
|
Mark M. |
Jan: your turn! do you have a question?
|
Jan S. |
View paste
|
Mark M. |
not directly
|
Mark M. |
MenuItem cannot go in a Bundle
|
Mar 24 | 8:50 AM |
Mark M. |
some future update to this book may use SavedStateHandle to save the current filter selection, to hold onto that across short-term process termination
|
Mark M. |
menuMap is just a cache for findItem() calls on the Menu, so I don't have to do that on the fly later on
|
Jan S. |
okay. One other about that book's example: Is the MasterDetail template provided by Studio a good model to use? I couldn't find any example in your book though the exploring android book mentioned you'd show it on tablet.
|
Mark M. |
doing a large-screen edition of this UI is another thing that I may add to some future version of the book
|
Mark M. |
in terms of the Studio templates... generally, I do not like them, but I have not looked at that one specifically in quite some time
|
Jan S. |
okay. Thanks.
|
Mark M. |
Google has also been backing away from master-detail, though IMHO it is still a useful pattern in some cases, this app in particular
|
Mark M. |
the problem with master-detail is for resizable windows, it makes for a harsh transition
|
Mark M. |
Google is steering developers towards more flexible "master" UIs that can leverage the additional screen space, such as a grid that adds/removes columns based upon changing window size
|
Mark M. |
and for some sorts of data, that works
|
Mar 24 | 8:55 AM |
Mark M. |
let me take another question from Leora, and I'll be back with you shortly
|
Mark M. |
Leora: back to you! do you have another question?
|
Leora |
nahhh i think i'm stuck looking at the insets for now
|
Mark M. |
the nice thing is that if you get those to work, they should handle other scenarios, such as if the user has gesture nav enabled, the lack of intruding nav on freeform windows (Chrome OS), etc.
|
Leora |
thanks Mark! Be safe :)
|
Leora |
You too Jan
|
Mark M. |
you too!
|
Mark M. |
OK, Jan, back to you! do you have another question?
|
Jan S. |
Storage Access Framework: any reason to use for read-only text files in app's local storage? AssetManager looks simpler to use and I presume has less overhead.
|
Leora |
"the lack of intruding nav on freeform windows (Chrome OS), etc" ?????
|
Mark M. |
Leora: IIRC, in Chrome OS, the nav bar is outside of your app window, so while the bar exists, you would not take it into account in your sorts of measurements
|
Mark M. |
Jan: AssetManager is for stuff that you ship with your app. If that's how you plan to get the read-only text to users, AssetManager is cheap and easy.
|
Leora |
ugh
|
Mark M. |
however, it is very read-only, so the only direct way of replacing the text is to update the app
|
Mark M. |
you can do stuff where you look for a local file (e.g., in getCacheDir()) that perhaps you downloaded, then fall back to an asset if that file does not exist
|
Mar 24 | 9:00 AM |
Mark M. |
and none of that would require the Storage Access Framework
|
Mark M. |
(Leora: you're starting to see why I really try to avoid messing with this stuff...)
|
Mark M. |
(it was never easy, and modern versions of Android really start to add to the combinations -- e.g., split-screen on phones, where once again the nav bar is not part of your window)
|
Leora |
I'm thinking of moving the whole layout from Constraint to good ole Linear
|
Jan S. |
The text files are shipping with app. But they may need to be updated without updating app. They will never be written by app due to something the user does.
|
Jan S. |
Leora: Linear sounds easy compared to what you are going to have to deal with in future.
|
Mark M. |
Jan: will the app be updating the text itself (e.g., downloading from a server)? or does the user download something themselves that serves as the update?
|
Leora |
I tried to be a good android soldier but....
|
Mar 24 | 9:05 AM |
Mark M. |
Leora: while ConstraintLayout is more flexible, there is nothing wrong with simple LinearLayout structures. Just be careful about too much nesting. From the description of your problem, I'm unconvinced that switching to LinearLayout will eliminate your need to do the measurement work, though.
|
Leora |
Me thinks you're correct
|
Jan S. |
A new version of the text file. For example, the child goes to next grade so the text's vocabulary needs to be updated. Not sure yet how we'll deal with it.
|
Mark M. |
if the app can handle downloading it directly, you would not need the Storage Access Framework -- just download to getCacheDir() and use the pre-packaged asset as the fallback
|
Mark M. |
if the user needs to download it, then you will want to consider the Storage Access Framework, particularly on Android 10
|
Mar 24 | 9:10 AM |
Jan S. |
Thanks. Very helpful. Should I be using viewModel (not using RecyclerView and at moment see no need for LiveData) to restore data (the text from the text file) through lifecycle changes. I get a little confused about all that.
|
Mark M. |
it would be faster than you re-loading it from the file or asset
|
Mark M. |
and, since I/O takes time, I would use LiveData, so you can do that I/O on a background thread and update the UI once it is ready
|
Jan S. |
Thanks. Mark. That's all I have. Have a great day!
|
Mark M. |
you too!
|
Jan S. | has left the room |
Leora | has left the room |
Mar 24 | 9:25 AM |
Mark M. | turned off guest access |