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!
|
Mark M. |
how can I help you today?
|
Gabriele | has entered the room |
Gabriele |
hi all
|
Mark M. |
hello, Gabriele!
|
Mark M. |
tinoper: do you have a question?
|
Mark M. |
tinoper: I will come back to you in a bit to see if you have a question
|
Mark M. |
Gabriele: your turn! do you have a question?
|
Sep 23 | 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?
|
Gabriele |
I expected my fragment to get created, after calling add()
|
Mark M. |
no, add() arranges for the page to be added
|
Mark M. |
it will not actually be added until the ViewPager requests it
|
Mark M. |
that will trigger your createFragment() call
|
Mark M. |
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
|
Mark M. |
well, rephrase that
|
Mark M. |
it will only be called when the fragment is needed
|
Mark M. |
suppose your ViewPager has 5 pages in it
|
Mark M. |
and you are presently showing page 0
|
Mark M. |
and you add() a page, which is the 6th page
|
Mark M. |
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
|
Sep 23 | 9:15 AM |
Mark M. |
right
|
Mark M. |
if you need the fragment in advance, you're welcome to create it, then return the already-created fragment in createFragment()
|
Mark M. |
ArrayPagerAdapter, like FragmentPagerAdapter, is responsible for the FragmentTransaction
|
Mark M. |
and so you wouldn't want to put the fragment in the UI itself, but you could create it
|
Mark M. |
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
|
Gabriele |
after createFragment has been called, I'm doing: SubFragment f = ((SubFragment)mAdapter.getExistingFragment(i));, to get this fragment
|
Gabriele |
(looping over i, always), but it's still null
|
Gabriele |
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?
|
Gabriele |
I can't understand if the fragment is there and the error is inside my code (probably) or whatever
|
Mark M. |
not really
|
Sep 23 | 9:20 AM |
Mark M. |
getExistingFragment() is a one-liner
|
Mark M. |
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
|
Mark M. |
which will be sometime after createFragment() has been called
|
Mark M. |
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
|
Mark M. |
getExistingFragment() is solely to find one by position
|
Mark M. |
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
|
Mark M. |
(as opposed to FragmentPagerAdapter, which generates tags for you using a private algorithm)
|
Mark M. |
but just because a message comes in does not mean that the user has opened up the tab for the fragment
|
Mark M. |
and so pushing the message into the fragment will not work
|
Mark M. |
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
|
Mark M. |
plus, as fragments are created, they need to retrieve the transcript for their private channel
|
Mark M. |
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?
|
Gabriele |
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
|
Sep 23 | 9:25 AM |
Mark M. |
the fragment can examine the event to see if the message is destined for it
|
Mark M. |
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
|
Mark M. |
but do not create fragments just because you have IRC messages
|
Mark M. |
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
|
Mark M. |
you have to create a fragment *when the user asks for it*
|
Mark M. |
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
|
Gabriele |
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
|
Mark M. |
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
|
Mark M. |
it opens a tab when you ask the browser to open a tab
|
Gabriele |
yes
|
Gabriele |
right, but if click on a link (supposing it has _blank)?
|
Gabriele |
(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
|
Mark M. |
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
|
Mark M. |
I
|
Mark M. |
I'd consider some sort of a badged indicator in the action bar
|
Sep 23 | 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
|
Mark M. |
it *may* update the UI, if the UI for that portion of the model exists
|
Mark M. |
whether or not the UI for that portion of the model exists is largely up to the user
|
Gabriele |
ah
|
Gabriele |
as tab I thought I could use PagerTabStrip, can this be possible?
|
Gabriele |
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
|
Mark M. |
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
|
Mark M. |
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
|
Gabriele |
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
|
Mark M. |
for real-time updates
|
Mark M. |
but if the fragment doesn't exist, don't worry about it, just add the message to the model
|
Mark M. |
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()
|
Sep 23 | 9:35 AM |
Mark M. |
and only try updating it if the fragment exists
|
Mark M. |
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
|
Gabriele |
I will have to try both solutions, anyway, I'm not able to imagine a lot, I have to practice more :P
|
Gabriele |
thank you for your patience, Mark, I think I've understand it, now
|
Sep 23 | 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
|
Gabriele |
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
|
Gabriele |
anyway, at least to me, fragments are harder thing to understand
|
Gabriele |
I always get confused
|
Mark M. |
they take getting used to
|
Gabriele |
eheh, yes
|
Sep 23 | 9:45 AM |
Gabriele |
thank you again, Mark, see you the next time :)
|
Mark M. |
OK
|
Gabriele | has left the room |
Sep 23 | 9:55 AM |
tinoper | has entered the room |
Sep 23 | 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.
|
tinoper |
So, How do you suggest to do that?
|
Mark M. |
I have no idea
|
Sep 23 | 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
|
Mark M. |
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
|
Mark M. |
the next chat is Monday at 9am US Eastern Time (same time as today's)
|
Mark M. |
sorry I could not help yo utoday
|
Mark M. |
er, help you today
|
Mark M. |
have a pleasant day!
|
tinoper | has left the room |
Mark M. | turned off guest access |