Office Hours — Today, November 7

Thursday, November 5

Nov 7
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
3:55 PM
Kai H.
has entered the room
Kai H.
Hello
Mark M.
hello, Kai!
how can I help you today?
Kai H.
Is this the start or the end of the office hours?
Mark M.
the start -- technically, it doesn't start for ~3 minutes :-)
I usually open the chat up 5 minutes early
Kai H.
Ok
When using ACtION_OPEN_DOCUMENT_TREE, where do I get an Uri for EXTRA_INITIAL_URI that will take me to the "Documents" folder?
Mark M.
you don't, technically speak
er, technically speaking
if you used ACTION_OPEN_DOCUMENT_TREE previously, and had that Uri, you could put it in EXTRA_INITIAL_URI
that would open the UI at the previously-chosen location
but you cannot get a Uri on some arbitrary location directly via your own code
4:00 PM
Kai H.
I think I just found your stackoverflow answer for that.
Well, that is a bummer. I thought I could have ACTION_OPEN_DOCUMENT_TREE jump to a certain pre-picked location.
Mark M.
only if was picked previously
Kai H.
*rolls eyes*
*puts face into hands for a bit*
Mark M.
from your app's standpoint, Documents/ shouldn't really be special -- if the user wants to store the content somewhere else, that's the user's choice
Kai H.
Anyway, if you remember the "opening a editable file with Word app" problem, that is "solved" by picking a directory via SAF and then using said directory.
And that's why I wanted to ask if I can pre-select the directory the SAF file picker will be in when requesting a directory.
Mark M.
ah
Kai H.
But you are right, it doesn't really matter. It's just me wanting the user to pick documents :D
Mark M.
but, again, Documents/ shouldn't be special -- for all you know, the Word file is somewhere else, right?
4:05 PM
Kai H.
It's internal at first, then a location get's picked with SAF, it's copied there, shared, edited, then read back.
Something that wasn't possible with MediaStore or other approaches.
Mark M.
due to some Word screwiness, based on our October 29th chat
Kai H.
Exactly.
Mark M.
but, does *Word* need it to be Documents/ ?
if not, then I'm still not certain why Documents/ is special
Kai H.
My OCD needs it ;-) Word only needs it to be in one of the public storage places.
And I was wondering how to get the EXTRA_INIAL_URI and thought I'd overlooked something. But now I know.
So the problem as such is "solved" for the time being, it was just me and my curiositry.
Mark M.
OK, glad to hear you at least have a flow working, despite it being cumbersome
Kai H.
I also needed to make sure that the directory still exists and there is still appropriate permissions on the next app restart.
4:10 PM
Kai H.
"Why, google, why?"
Mark M.
well, remember, a fair chunk of this is Microsoft's fault
FileProvider should work, and Microsoft appears to have screwed that up
Kai H.
Yes. I still do feel like Google made some things a lot more complicated for questionable reasons, leaving a lot of valid use cases in the dust and making others very hard or strange to implement.
Mark M.
yeah, that's the problem with having a very open system and then trying to lock it down more
even if the locking-down process is for good reasons (privacy, security)
Kai H.
Ah well.
My other question is about a side effect of startActivityForResult
4:15 PM
Kai H.
When using several startActivityForResult() (and one onActivityResult), there is a lot of "jumping" in the code.
And usually a switch-statement in the onActivityResult.
Is there any other way?
Mark M.
there is a new ActivityResult API that is in alpha right now that will be the long-term Jetpack-ular solution
whoops, sorry, it is up to a beta01
Kai H.
Huh. Interesting. I still have to use a callback though and it's not really "inline" to the flow.
On the other hand, how could it be, I guess.
Mark M.
right
4:20 PM
Mark M.
it is more "inline" than what you have right now
Kai H.
Yes
4:25 PM
Kai H.
Thanks :)
Mark M.
happy to help!
Kai H.
I have a question I am not so sure about, but I'll put it up anyway.
4:30 PM
Mark M.
fire away!
Kai H.
I have a "file system wrapper" that abstracts operations like opening a file stream, getting a directory for a certain path and so on. There is also data classes for a file with some extra attributes and that includes a path and if it's an internal or an external directory and which path it is.
(so pretty much you define a "path", then a "file", then do operations on said file with the file system wrapper).
And the question is pretty much how to test the wrapper, with part of the question being how to design it.
Mark M.
um, well, that's a bit difficult to answer in the abstract
but, whether you are using instrumented tests (on Android) or unit tests (on the JVM), java.io.File exists
4:35 PM
Mark M.
so, there's nothing stopping you from just writing ordinary tests that do real work
4:35 PM
Mark M.
and whether you can use unit tests will be determined by whether your wrapper uses Android framework classes or not
Kai H.
It does, so I need a Context at the least
Mark M.
well, that starts to get into the design questions
if this wrapper will have significant business logic, you might want to have it be isolated from platform considerations, so you can unit test better
Kai H.
It does some file encryption if the file is "external" for example, using EncryptedFile
Mark M.
oh
Kai H.
I don't really know what constitues for "business logic" in this case, but I'd say it doesn't have any.
Mark M.
yeah, OK, you're starting to head strongly in the "gotta use instrumented tests" direction
if it is a pure utility class, then it probably just *is* the abstraction, and if you want to test it, you will need to test on Android (instrumented tests)
Kai H.
I guess so.
4:40 PM
Kai H.
I did try to implement tests but wasn't very satisfied for a reason I don't remember now.
There where "unit" tests that ran with robolectric and integration tests that ran on the emulator.
Mark M.
I'm not a big Robolectric fan, but others are
Kai H.
Neither am I. It's just somethign I tried.
I'd like to get as close to the real thing as possible, which seems to be very hard.
The "edit file in word" case seems quite impossible.
Mark M.
testing that might be possible with UI Automation, though it will be tedious and fragile
Kai H.
I think part of the test would have to be to install word app, log into an account, then go to the app, ... VERY finicky and much effort
Mark M.
agreed
Kai H.
So yea, no automated tests for that part.
4:45 PM
Kai H.
Btw, thanks for your work on the books, blog articles and practice sites. It has once again proven a very good resource.
Mark M.
I'm glad to be useful!
Kai H.
That I have consulted quite a bit while trying to understand SAF and Scoped Storage and such.
ani
has entered the room
ani
Hi Mark, how are you doing?
Mark M.
oh, hello ani!
ani: how can I help you today?
4:50 PM
ani
I wanted to see if you have any experience with Google's Paging 2 library? I have a question regarding that.
Mark M.
actually, I bypassed 2 -- I played with 1 (hated it) and am using 3 on a project now (pretty decent)
2 has an API similar to 1
ani
Sorry, the question may be implementation dependent.
Mark M.
outside of a very narrow path (Room -> Paging -> RecyclerView), I can't help a lot on Paging 1/2 stuff
ani
haha, I wanted to avoid Paging 2 for that reason but 3 is in alpha, and I wanted to refrain from using that in production just yet.
Mark M.
I'm about to wind up using Paging 3 in production, and am hoping for the best
so far, I haven't had any problems with it, even for custom data sources
but, it definitely is a risk
ani
Great, I would be interested in knowing more on your experience may be after you have had it in prod for some time.
Mark M.
feel free to ask about it in early 2021!
4:55 PM
ani
nice, thanks
In paging 3, say if your datasource gives you duplicate items in a list across multiple pages, what would you suggest to remove those on the UI, say recycler view?
Mark M.
frankly, that does not sound like it will be fun at all
ani
View paste
Page 1- [id:1, val:ani], [id:2, val:mark], [id:3, val:Jason]
Page 2- [id:3, val:Jason], [id:4, val:Jon], [id:1, val:ani]
Mark M.
is it guaranteed that the duplication will be on a page boundary?
oh, wait, I missed the id:1 scenario there
ani
no, just a co-incidence
Mark M.
to be honest, I don't know of a good solution for that with Paging 3 (or 1 or 2, for that matter)
the Paging 3 API has some nice hooks for data transformation, both simple map()-style conversions and insertion of other elements (e.g., headers), but I do not recall it having anything to handle this case
5:00 PM
Mark M.
my experience with Paging 3 has been fairly pleasant but not broad -- just solving a problem for a customer
so I cannot rule out the possibility that there is something in there that you could use for this
but I will be honest, it would surprise me
ani
View paste
the thing keeping me from operating on recyvlervivw adapter is that it depends on PageList(paging 2 at least) and then that list is responsible for getting more data and reacting to boundary callbacks from what I remember..
If I remove duplicate items, it could mess the count and page size that implementation depends on.
Mark M.
agreed
Paging really assumes that your data source is responsible for data de-duplication and related concerns
and, that's a wrap for today's chat
the next one is Tuesday at 7:30pm US Eastern
Kai H.
Have a good time everyone.
Mark M.
have a pleasant day!
ani
View paste
Sure, thanks Mark.
Have a good day!
take care Kai
Kai H.
has left the room
ani
has left the room
Mark M.
turned off guest access

Thursday, November 5

 

Office Hours

People in this transcript

  • ani
  • Kai H.
  • Mark Murphy