Remove views from DeckAdapter when corresponding conversation has gone missing

If a conversation disappears while the activity is paused (e.g. if the
user is kicked from a channel, or if another client attached to an
irssi-proxy has chosen to leave that channel), we currently aren't
removing the view from the DeckAdapter when we resume.  This results in
leaking a Conversation object until the user explicitly asks for the
conversation to be closed or the activity finishes, and is also
confusing because the user may not receive any indication that the
channel was parted in the first place.

There's a good case for leaving the MessageListView in place, with a
note indicating that the user has been kicked or parted from the
channel, but for that to work, we need to keep the Conversation object
in the server's list of conversations -- otherwise the behavior will
differ depending on whether the user left the activity via the Back
button or the Home button, which is counterintuitive.

For now, just remove the stale view from the DeckAdapter, which fixes
the leak and the potential user confusion.
This commit is contained in:
Steven Luo 2011-08-16 02:11:28 -07:00 committed by Sebastian Kaspari
parent f84369bc19
commit e07d99ed5d
1 changed files with 11 additions and 0 deletions

View File

@ -335,6 +335,17 @@ public class ConversationActivity extends Activity implements ServiceConnection,
}
}
// Remove views for conversations that ended while we were paused
int numViews = deckAdapter.getCount();
if (numViews > mConversations.size()) {
for (int i = 0; i < numViews; ++i) {
if (!mConversations.contains(deckAdapter.getItem(i))) {
deckAdapter.removeItem(i--);
--numViews;
}
}
}
// Join channel that has been selected in JoinActivity (onActivityResult())
if (joinChannelBuffer != null) {
new Thread() {