Feb 25 | 8:20 AM |
Mark M. | has entered the room |
Feb 25 | 8:25 AM |
Mark M. | turned on guest access |
Feb 25 | 8:45 AM |
Leora | has entered the room |
Leora |
Hi Mark, how are you?
|
Mark M. |
hello, Leora! I'm doing fine -- and you?
|
Leora |
Ok, just bewildered as usual hahaha
|
Mark M. |
welcome to the world of Android app development! :-)
|
Leora |
I've been in it 6 years and still bewildered
|
Leora |
2 questions
|
Mark M. |
fire away!
|
Leora |
First one, if there is a way to save fragments...without viewpager, since viewpager2 which I wasted a day implementing with it's spiffy toolbar...cannot disable the transition animation
|
Mark M. |
what do you mean by "save fragments"?
|
Feb 25 | 8:50 AM |
Leora |
I mean, my boss (also the developer of the iphone version) doesn't like the flicker that can be seen the first one or 2 times clicking on the tab for that fragment
|
Leora |
it takes a while to populate the recyclerview grid
|
Leora |
a while meaning a split second, but it is noticable
|
Mark M. |
are you caching the data that is used to populate the RecyclerView?
|
Leora |
he claims in iphone you can pre-load
|
Leora |
i am caching the images loaded into the cards using glide
|
Mark M. |
how about the model data that you use for the RecyclerView.Adapter?
|
Leora |
i don't think i am
|
Leora |
it 'settles' after the third click on the same tab...but first 2 are jolty
|
Mark M. |
you can tell ViewPager to be more aggressive about caching pages via setOffscreenPageLimit(): https://developer.android.com/reference/android...
|
Mark M. |
(that link didn't go to the method -- Campfire's URL parsing rules need work...)
|
Leora |
i did that...but viewpager 2 can only disable user swipe
|
Leora |
transitions from page 5 back to one is awful
|
Leora |
oh hahaha
|
Mark M. |
oh, sorry, I misread your earlier comment and though you were using ViewPager instead of ViewPager2
|
Leora |
no, i posted this last week
|
Leora | |
Feb 25 | 8:55 AM |
Leora |
but since then realized the class is final anywayz
|
Mark M. |
I have not used ViewPager2 yet, so I don't have any recommendations on that
|
Leora |
so i removed the viewpager
|
Mark M. |
(though ViewPager2 also has setOffscreenPageLimit() FWIW)
|
Leora |
any way to cache the fragments without ft.add() and hide()/show()?
|
Mark M. |
there is the attach()/detach() pair as well
|
Leora |
yes it caches nicely. but i can't disable the animation page transitions
|
Mark M. |
though I think those will force you to regenerate your views
|
Leora |
i think so too
|
Mark M. |
in terms of disabling the animation page transitions, will setPageTransformer(null) do that? or perhaps setPageTransformer(someTransformerThatDoesNothing)?
|
Leora |
hmmm i dunno. i threw it out
|
Leora |
what about when you asked if i cache the model data for the RecyclerView.Adapter
|
Leora |
how would i do that?
|
Mark M. |
that would depend a bit on your architecture, where the data is coming from, etc.
|
Mark M. |
for example, if you are using the Arch Components ViewModel, you might have an activity-level ViewModel that can load and cache the data
|
Feb 25 | 9:00 AM |
Mark M. |
that way, even if the fragment gets recreated, it can get the cached data from that activity-level ViewModel (e.g., by activityViewModels() in Kotlin)
|
Mark M. |
or, perhaps add caching in your repository layer, if you have one
|
Mark M. |
if your fragment is hitting a database or network API directly... then you would need to add a viewmodel or repository that can handle the caching
|
Leora |
i don't think retrieving the list of max 12 items is the problem though....would it?
|
Mark M. |
where is the list coming from? a server? a local database? something else?
|
Leora |
or is it the retrieving/renderring the images?
|
Leora |
no network. the lists are pre-defined
|
Mark M. |
pre-defined, meaning they are hard-coded in the app code?
|
Leora |
it's literally Category.getList()
|
Leora |
not hard-coded, but defined in onCreate() in Main
|
Mark M. |
so those objects are already around by the time that your fragment is created?
|
Leora |
yes they are
|
Mark M. |
OK, that's not going to be a problem then
|
Leora |
and i would think glide would cache those images the first time around...not the 3rd
|
Mark M. |
if there is other stuff in the cache, perhaps the LRU algorithm is getting confused
|
Mark M. |
you might want to check your Glide memory cache settings and see if they need tweaking: https://bumptech.github.io/glide/doc/configurat...
|
Leora |
ok i'll look
|
Feb 25 | 9:05 AM |
Leora |
is there any way to pre-cache all fragments images before the fragment is loaded?
|
Mark M. |
Glide has a pre-load API
|
Leora |
but then it will still be new fragment.replace?
|
Leora |
or create all fragments at once and then show/hide?
|
Mark M. |
that's up to you
|
Mark M. |
(BTW, use preload() with Glide to load the image into the memory cache, or downloadOnly() to download it just to the disk cache)
|
Leora |
then what's the default?
|
Mark M. |
"what's the default" for what?
|
Leora |
when you don't specify glide options -
|
Leora |
isn't that loading into memory cache?
|
Mark M. |
yes, but you asked "is there any way to pre-cache all fragments images before the fragment is loaded?"
|
Mark M. |
if you are relying on load() to populate the memory cache, at that point you are displaying the image in an ImageView (or whatever)
|
Mark M. |
so, for example, suppose you wanted to preload the images in Glide back where you define these objects for Category.getList()
|
Mark M. |
you don't have an ImageView there for those images
|
Mark M. |
so, you use preload() to get Glide to download the images and load them into the memory cache
|
Feb 25 | 9:10 AM |
Mark M. |
so, the next time you call load(), if those images are still in cache, they are used from the cache
|
Leora |
oh! this sounds promissing!
|
Leora |
by golly, i think that' it
|
Leora |
thanks so much Mark
|
Mark M. |
frequently, we do not know the image URLs in advance, so preload() is not an option -- in your case, probably it is an option
|
Mark M. |
you're welcome!
|
Leora |
yes it seems like it is!
|
Leora |
ok, shall we move on to preferences, settings, or whatever android makes us call them now?
|
Mark M. |
sure!
|
Leora |
ok, in my main flavor I have base preferences xml. then in my say, other flavors, i add to the prefs
|
Leora |
up to here, all is good
|
Leora |
however
|
Leora |
i want the flavor options to merge with the base categories...doesn't work
|
Feb 25 | 9:15 AM |
Leora |
more so, android studio tells me i have a duplicate category key :/
|
Feb 25 | 9:15 AM |
Mark M. |
are you getting that at compile time or at runtime?
|
Leora |
runtime
|
Leora |
i can ignore it, but anyway the flavor prefs are separated from the base prefs by a divider line
|
Leora |
instead of extending them like i want
|
Mark M. |
are you calling addPreferencesFromResource() twice, once for the base and once for the flavor?
|
Mark M. |
if not, how are you arranging to get both the base and the flavor preferences into your PreferenceFragmentCompat object?
|
Leora |
yes, addPreferencesFromResource() is twice
|
Mark M. |
and you have a PreferenceCategory with the same key in both preference XML resources?
|
Leora |
yes
|
Feb 25 | 9:20 AM |
Mark M. |
I'm not surprised at the error -- I do not think that the loading mechanism here is that sophisticated
|
Mark M. |
merges are probably beyond the capabilities of the loader
|
Leora |
so is there any way to include flavor prefs in the same category as base prefs?
|
Mark M. |
probably manually
|
Leora |
what do you mean? duplicate xml?
|
Leora |
or is include supported?
|
Leora |
(i think not)
|
Mark M. |
I mean making addPreference() calls on the PreferenceCategory to add the extra preferences
|
Mark M. |
I don't think <include> is supported here -- AFAIK, that is just for layouts
|
Leora |
ahhhh, i can call the actual preference category by it's key and then add it?
|
Leora |
add to it i mean
|
Mark M. |
after loading the base, you should be able to call findPreference(), passing in your key, to get to the PreferenceCategory defined in the base
|
Mark M. |
then, you would call addPreference() to add additional preferences to that
|
Leora |
that's a really good idea
|
Mark M. |
I do not know if there is a way to accomplish that by inflating your flavor preference XML though
|
Mark M. |
I cannot rule it out, but I am not seeing an option for that in the API
|
Leora |
oh
|
Leora |
so you mean, literally code the flavor prefs in
|
Leora |
oh gawd
|
Mark M. |
or parse the XML yourself, which is equally "oh gawd"
|
Leora |
yessireee indeed
|
Feb 25 | 9:25 AM |
Mark M. |
there is setPreferencesFromResource(), which takes a resource ID and a key, but I think it does a complete replace, based on the docs
|
Mark M. |
what you are trying to do isn't crazy, but I suspect that it is beyond the stock abilities of the preference stuff (both the deprecated framework stuff and AndroidX)
|
Leora |
yes, it replaces...my extended class with addPreferencesFromResource completely overrides the base class setPreferencesFromResource
|
Leora |
beyond the capabilities....as usual hahaha
|
Leora |
it seems so obvious to be able to do this!
|
Mark M. |
well, in fairness, while what you are trying to do isn't crazy, I will argue that it *is* a bit of an edge case
|
Leora |
i argue it is not sir! :)
|
Leora |
well thanks for the discussion
|
Mark M. |
sorry that I didn't have a better option for you for that one
|
Leora |
as usual it was both enlightening (you), comforting (you), and frustrating (android)
|
Leora |
:)
|
Mark M. |
I try to be useful!
|
Feb 25 | 9:30 AM |
Mark M. |
that's all for today's office hours chat
|
Leora |
listen, i made it to the android dev summit in october, and was shocked that the android api devs themselves didn't have answers to several questions i asked them directly!
|
Leora |
thanks so much, take care!
|
Mark M. |
the next chat is Thursday at 7:30pm US Eastern, and the next 8:30am chat is 5 March
|
Mark M. |
have a pleasant day!
|
Leora | has left the room |
Mark M. | turned off guest access |