Office Hours — Today, August 13

Tuesday, August 11

Mark M.
has entered the room
Mark M.
turned on guest access
MyWay
has entered the room
MyWay
hi Mark
Mark M.
hello, MyWay!
how can I help you today?
MyWay
always playing with the chat app, don't know if you remember, if the user scrolled up, I wanted to stop adding messages to the listview, to do so I've added an OnScrollListener listener, but then I thought I could simply stop sending notifyDataSetChanged, but I can't, or otherwise I get an error, because the listview isn't sync with the adapter
I would like to still add messages to the adapter, but not to show in the listview
is there any way?
Mark M.
buffer those messages elsewhere, and add them to the adapter when you are ready to show them
not really
I mean, you could try row layouts that are invisible or something, but I would expect UX oddities to result
Aug 13
9:00 AM
Mark M.
just buffer them, and when you want them shown (e.g., user scrolls back down), add them en masse
MyWay
ok, so I should buffer them elsewhere
do you think it's better to buffer all messages then, or only these messages?
I mean, like doing the buffer for the messages being added, too
Mark M.
um, I thought "these messages" were the "messages being added" while the user was scrolled up
as I understand it, you are trying to pause normal updates to the ListView while the user is not viewing the latest messages
if so, you are buffering while you are paused, and you are not buffering while you are not paused
MyWay
sorry, by these messages I meant the ones waiting for the user to scroll to the bottom
because currently I'm buffering the messages when the app is not in foreground, too
Mark M.
ah
MyWay
but I'm doing it from the Service and I don't know if it's a good practice to check if a fragment is there from the service and if it wants messages or not
and check if it wants*
Mark M.
I'm not sure what "it" is in "doing it from the Service"
9:05 AM
MyWay
I'm adding messages to the adapter or to the buffer from the service
because maybe the app is not in foreground
Mark M.
um, that's seriously bad
your service should have no access whatsoever to your adapter
at least, no direct access
MyWay
or better, not directly to the adapter, but to the list the adapter is using
Mark M.
in normal (non-paused) operation, the service should be using an event bus or a similar mechanism to say "hey! we got a chat message in!"
the fragment can be a subscriber to that event, and add the message to the adapter upon receipt
MyWay
yes, I add it to the underlying logic using eventbus
then when the activity is ready, I get these messages queued/buffered
Mark M.
well, perhaps you can extend the "activity is ready" to cover cases like when the user has scrolled up the transcript
MyWay
and I tought I could do the same for the scroll, but I don't know if checking for a fragment inside a service is a good thing
Mark M.
you wouldn't be "checking for a fragment inside a service"
the fragment would tell the service "we're scrolled up, move into the paused state"
and the fragment would tell the service "OK, the user scrolled back down again, resume normal delivery"
MyWay
ah, so the fragment should send a message, e.g. with eventbus to the service
and the service store it
Mark M.
or startService()
right
what I am calling "paused" is a state, controlling the behavior of the service
9:10 AM
Mark M.
whether it sends incoming messages in real time or is buffering them
9:10 AM
Mark M.
your UI layer needs to tell the service when to switch between these states
MyWay
yes, as I have many dynamic fragments I could use an hash with the name of the fragment and a boolean value
Mark M.
there are multiple channels, routing to different fragments?
MyWay
yes
multiple channels, multiple private conversations
but every fragment name is different
Mark M.
I don't know about the "hash" bit, but yes, presumably you need independent buffers per channel/conversation
MyWay
yes, something like that
Mark M.
I'd use some other identification system than a hash, such as unique int, or a UUID if these things are meant to be persistent
9:15 AM
MyWay
ok, thank you
I have a strange bug, too, which I didn't investigate, maybe you have some idea: sometimes when the user lost the connection and get reconnected, messages get added to the wrong fragment, e.g. my messages to you are added to another user, but I'm using findFragmentByTag to get the right fragment
maybe something happens because fragments have two references and get reused with a different tag?
Mark M.
sorry, no clue
MyWay
then I have Mark's fragment which now points to something else, too, have to investigate
is there any way to simulate lost of connection on the emulator?
Mark M.
the Android Console may have an option for that
telnet localhost 5554
where you replace 5554 with the number shown in the title bar of your emulator window
MyWay
ah, nice
Mark M.
help will list commands
9:20 AM
Mark M.
there's commands for configuring the emulated network connection
I know it handles stuff like simulated latency
I forget whether it handles off/on
MyWay
thank you, I'll check it
Nikhil k.
has entered the room
MyWay
hi
Nikhil k.
Hello
Mark M.
hello, Nikhil!
Nikhil: MyWay has had a chance to ask a question already, so it is your turn -- do you have a question?
Nikhil k.
I have read 200 pages of book and I have a question about format of book
View paste
In basic widget chapter there is a topic called useful methods which describe briefly methods like isEnabled(),setEnabled(), requestFocus(), getParent(), findViewById() etc. Will there be an elaborated chapter on how to implement these methods?
Mark M.
you will see uses of some of those in later chapters
findViewById(), for example, might be on the next page
however, there are plenty of cases where I point out capabilities at a high level but do not go into details
9:25 AM
Nikhil k.
So for details where should I focus on
Will it come by practice?
Mark M.
it will come when you find a need to use those capabilities
Nikhil k.
OK thank you. That will be all from my side
Mark M.
um, OK
MyWay: your turn! do you have another question?
MyWay
no, thank you Mark
Nikhil k.
has left the room
9:30 AM
Mark M.
OK, well, if you come up with another one, chime in
MyWay
thanks
9:35 AM
Nikhil k.
has entered the room
Nikhil k.
has left the room
10:00 AM
Mark M.
that is a wrap for today's office hours chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is Tuesday at 4pm US Eastern
have a pleasant day!
MyWay
has left the room
Mark M.
turned off guest access

Tuesday, August 11

 

Office Hours

People in this transcript

  • Mark Murphy
  • MyWay
  • Nikhil kaushik