Mark M. | has entered the room |
Mark M. | turned on guest access |
MyWay | has entered the room |
MyWay |
hi Mark
|
Mark M. |
hello, MyWay!
|
Mark M. |
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
|
MyWay |
I would like to still add messages to the adapter, but not to show in the listview
|
MyWay |
is there any way?
|
Mark M. |
buffer those messages elsewhere, and add them to the adapter when you are ready to show them
|
Mark M. |
not really
|
Mark M. |
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
|
MyWay |
do you think it's better to buffer all messages then, or only these messages?
|
MyWay |
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
|
Mark M. |
as I understand it, you are trying to pause normal updates to the ListView while the user is not viewing the latest messages
|
Mark M. |
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
|
MyWay |
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
|
MyWay |
and check if it wants*
|
Mark M. |
I'm not sure what "it" is in "doing it from the Service"
|
Aug 13 | 9:05 AM |
MyWay |
I'm adding messages to the adapter or to the buffer from the service
|
MyWay |
because maybe the app is not in foreground
|
Mark M. |
um, that's seriously bad
|
Mark M. |
your service should have no access whatsoever to your adapter
|
Mark M. |
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!"
|
Mark M. |
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
|
MyWay |
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"
|
Mark M. |
the fragment would tell the service "we're scrolled up, move into the paused state"
|
Mark M. |
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
|
MyWay |
and the service store it
|
Mark M. |
or startService()
|
Mark M. |
right
|
Mark M. |
what I am calling "paused" is a state, controlling the behavior of the service
|
Aug 13 | 9:10 AM |
Mark M. |
whether it sends incoming messages in real time or is buffering them
|
Aug 13 | 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
|
MyWay |
multiple channels, multiple private conversations
|
MyWay |
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
|
Aug 13 | 9:15 AM |
MyWay |
ok, thank you
|
MyWay |
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
|
MyWay |
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
|
MyWay |
is there any way to simulate lost of connection on the emulator?
|
Mark M. |
the Android Console may have an option for that
|
Mark M. |
telnet localhost 5554
|
Mark M. |
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
|
Aug 13 | 9:20 AM |
Mark M. |
there's commands for configuring the emulated network connection
|
Mark M. |
I know it handles stuff like simulated latency
|
Mark M. |
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!
|
Mark M. |
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
|
Nikhil k. |
View paste
|
Mark M. |
you will see uses of some of those in later chapters
|
Mark M. |
findViewById(), for example, might be on the next page
|
Mark M. |
however, there are plenty of cases where I point out capabilities at a high level but do not go into details
|
Aug 13 | 9:25 AM |
Nikhil k. |
So for details where should I focus on
|
Nikhil k. |
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
|
Mark M. |
MyWay: your turn! do you have another question?
|
MyWay |
no, thank you Mark
|
Nikhil k. | has left the room |
Aug 13 | 9:30 AM |
Mark M. |
OK, well, if you come up with another one, chime in
|
MyWay |
thanks
|
Aug 13 | 9:35 AM |
Nikhil k. | has entered the room |
Nikhil k. | has left the room |
Aug 13 | 10:00 AM |
Mark M. |
that is a wrap for today's office hours chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Tuesday at 4pm US Eastern
|
Mark M. |
have a pleasant day!
|
MyWay | has left the room |
Mark M. | turned off guest access |