Office Hours — Today, September 23

Yesterday, September 22

Mark M.
has entered the room
Mark M.
turned on guest access
Sep 23
9:05 AM
tinoper
has entered the room
Mark M.
hello, tinoper!
how can I help you today?
Gabriele
has entered the room
Gabriele
hi all
Mark M.
hello, Gabriele!
tinoper: do you have a question?
tinoper: I will come back to you in a bit to see if you have a question
Gabriele: your turn! do you have a question?
9:10 AM
Gabriele
I'm playing with ArrayPagerAdapter, but probably I don't understand something. I'm looping over getExistingFragment, to check if a Fragment exists, if not I'm doing add(new SimplePageDescriptor(...)) and then looping again (or getting the last added) trying to get this fragment, but it's null, why?
I expected my fragment to get created, after calling add()
Mark M.
no, add() arranges for the page to be added
it will not actually be added until the ViewPager requests it
that will trigger your createFragment() call
and so you know at that point in time that the fragment is created, because you are creating it
Gabriele
hm, if createFragment don't get called, where can the problem be?
Mark M.
I have no idea
well, rephrase that
it will only be called when the fragment is needed
suppose your ViewPager has 5 pages in it
and you are presently showing page 0
and you add() a page, which is the 6th page
the fragment won't be created then, because there's no need for the fragment just yet, just as the fragment for position 4 won't have been created yet
Gabriele
oh true, when I swipe and the next page is mine, it gets called
9:15 AM
Mark M.
right
if you need the fragment in advance, you're welcome to create it, then return the already-created fragment in createFragment()
ArrayPagerAdapter, like FragmentPagerAdapter, is responsible for the FragmentTransaction
and so you wouldn't want to put the fragment in the UI itself, but you could create it
the real vision is that your PageDescriptor serves in this role instead, so that you create the descriptors in advance, and only create the fragments if/when needed
Gabriele
I see
after createFragment has been called, I'm doing: SubFragment f = ((SubFragment)mAdapter.getExistingFragment(i));, to get this fragment
(looping over i, always), but it's still null
now I don't understand why, if I made the fragment from createFragment
Mark M.
if you mean that you are looping inside of createFragment(), that won't work, as I won't have had any chance to use the fragment yet
Gabriele
no, I'm looping out from createFragment
Mark M.
and, there's still a FragmentTransaction that has to be processed
Gabriele
I thought that as I'm out of it, the fragment should be there... is there a way to check fragment that exists in my app? a sort of debug?
I can't understand if the fragment is there and the error is inside my code (probably) or whatever
Mark M.
not really
9:20 AM
Mark M.
getExistingFragment() is a one-liner
return (T)(fm.findFragmentByTag(getFragmentTag(position)));
tinoper
has left the room
Mark M.
it will only work once the FragmentTransaction has been processed for the newly-created fragment
which will be sometime after createFragment() has been called
but exactly when depends on the state of the main application thread's work queue
Gabriele
to understand better, I'm receiver a privatemessage from the irc client, as I receive it, I check if there exists a fragmentwindow for it
Mark M.
getExistingFragment() also requires stable fragment tags (i.e., your descriptor is not synthesizing some tag on the fly that might change from call to call for the same descriptor)
Gabriele
if not, I'm making it and then I should add the message received to the fragment
Mark M.
then call findFragmentByTag() yourself
Gabriele
yes, tag is stable
Mark M.
you know the tag, as you're defining it
getExistingFragment() is solely to find one by position
part of the reason why I am having you define the tag is so that you can retrieve the fragments by tag on your own
(as opposed to FragmentPagerAdapter, which generates tags for you using a private algorithm)
but just because a message comes in does not mean that the user has opened up the tab for the fragment
and so pushing the message into the fragment will not work
I'd raise an event on an event bus to indicate that a message was received
Gabriele
oh, damn; fragment is the hardest part, to me TT
Mark M.
and have existing fragments pull such messages
plus, as fragments are created, they need to retrieve the transcript for their private channel
which is part of your data model
Gabriele
you mean, received the message, send this message to all window/fragments, even if this is not the right window/fragment?
I can't understand what you mean, hm
Mark M.
"send this message to all window/fragments, even if this is not the right window/fragment?" -- sure
9:25 AM
Mark M.
the fragment can examine the event to see if the message is destined for it
the key is that the fragment may not exist, which an event bus pattern handles well
Gabriele
yes, but I thought it was a waste of messages :P
Mark M.
if you want to push the message into the fragment *if it exists*, that's fine
but do not create fragments just because you have IRC messages
fragments are your UI; they are not responsible for storing your data model
Gabriele
but if it does not exist, I have to create a new fragment/windows, to handle it
Mark M.
no, you do not
you have to create a fragment *when the user asks for it*
by swiping to that tab
Gabriele
this is the part I don't understand
Mark M.
OK, let's draw an analogy
Gabriele
so, I receive the message, send the event
but then, where I should store it?
Mark M.
you are using a Web browser to view this chat
Gabriele
yes
Mark M.
your Web browser does not have an open tab for every Web page on the Internet
if I add a page to my Web site, your Web browser will not automatically open a tab for that page, just because I updated my server
it opens a tab when you ask the browser to open a tab
Gabriele
yes
right, but if click on a link (supposing it has _blank)?
(similar to receveing a message from another user, how does he know he receveid it?)
Mark M.
at that point, you open a tab, in response to user input
no, receiving a message has nothing to do with user input
Gabriele
imagine I can write to you a private message, here. I send it, how do you know you've received it, if the tab don't appear to you?
Mark M.
that's up to you
I
I'd consider some sort of a badged indicator in the action bar
9:30 AM
Mark M.
with the badge showing the count of messages that you have received that you have not viewed
Gabriele
generally, on irc clients, I see an automatically-made tab, which I click
Mark M.
the act of receiving a message from the IRC server should update your model
it *may* update the UI, if the UI for that portion of the model exists
whether or not the UI for that portion of the model exists is largely up to the user
Gabriele
ah
as tab I thought I could use PagerTabStrip, can this be possible?
so I show it, even if the fragment isn't still there
Mark M.
sure, or the one in ViewPagerIndicator, or PagerSlidingTabStrip, or other open source implementations
adding a tab is reasonagble
Gabriele
but then when I tap it, I have to load from my model messages received
Mark M.
er, reasonable
right
Gabriele
so I should have a sort of MessageArchive, for every user
Mark M.
I'd call it a ChatTranscript, but that's just me :-)
Gabriele
I show the tab and when *he* likes, by swiping, I create the fragment for him
Mark M.
right
Gabriele
eheh
now it's clear, thank you
Mark M.
and, if when a message comes in, the fragment already exists, you can tell it that the data model has changed
for real-time updates
but if the fragment doesn't exist, don't worry about it, just add the message to the model
and the user will see the message when she eventually views that tab
Gabriele
to do real-time updates, you mean eventbus -> send an event for each message received, to all existent fragments, as you said before
Mark M.
or, if you know the fragment by tag, see if the fragment exists via findFragmentByTag()
9:35 AM
Mark M.
and only try updating it if the fragment exists
I'd go with an event bus, but that's not the only solution
Gabriele
yes, maybe this is better, as I know the tag, so I don't send a message to them all, when I don't need to
I will have to try both solutions, anyway, I'm not able to imagine a lot, I have to practice more :P
thank you for your patience, Mark, I think I've understand it, now
9:40 AM
Mark M.
if you have other questions, go right ahead
Gabriele
and as events are to be coupled with life cycle of activity, it's better and more comfortable, to handle events and the adapter, from the activity, right?
Mark M.
I am not sure what events you are referring to
Gabriele
I mean onEvent(BusMessageEvent ...) { ... }
Mark M.
whether you handle those at the activity or fragment level is up to you
Gabriele
inside the activity, which holds the adapter
because my messages are not related to fragments, but to the activity, I think
Mark M.
I wouldn't consider the ArrayPagerAdapter to be a likely candidate for handling the events
Gabriele
I think for today I've ended with questions :P
anyway, at least to me, fragments are harder thing to understand
I always get confused
Mark M.
they take getting used to
Gabriele
eheh, yes
9:45 AM
Gabriele
thank you again, Mark, see you the next time :)
Mark M.
OK
Gabriele
has left the room
9:55 AM
tinoper
has entered the room
9:55 AM
Mark M.
hello, tinoper!
tinoper
hi Mark
Mark M.
how can I help you today?
tinoper
I was building an app that only shows one layout after another.It's like mockup to show screens not functionality
Mark M.
OK... but what is your question?
tinoper
I means,you touch any place on first screen and it shows another.My problem was that it didn't work for more than two screens.
So, How do you suggest to do that?
Mark M.
I have no idea
10:00 AM
Mark M.
I have no idea what you wrote, and I have no idea what "it didn't work for more than two screens" means
tinoper
ok,sorry
Mark M.
and it is time for the chat to end, and so I don't have time to try to get the details from you now
this feels like a better fit for a Stack Overflow question
tinoper
No problem,have a nice day
Mark M.
or you can try in an upcoming chat
the next chat is Monday at 9am US Eastern Time (same time as today's)
sorry I could not help yo utoday
er, help you today
have a pleasant day!
tinoper
has left the room
Mark M.
turned off guest access

Yesterday, September 22

 

Office Hours

People in this transcript

  • Gabriele
  • Mark Murphy
  • tinoper