diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-01 15:07:20 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-01 15:07:20 +0100 |
commit | 53d9c9997a508985f0e19aba928bfa25c80ba23e (patch) | |
tree | 5e79bfe04db8d51091bcf9b94baa979217e9d542 /src/de/gultsch/chat/ui | |
parent | 43531113b798cda6b2f76257641f38b0af986437 (diff) |
more cleanup. more listeners
Diffstat (limited to 'src/de/gultsch/chat/ui')
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationActivity.java | 81 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationFragment.java | 13 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/OnConversationListChangedListener.java | 5 |
3 files changed, 77 insertions, 22 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index 79d1e218..23d03a01 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -43,6 +43,37 @@ public class ConversationActivity extends XmppActivity { private ListView listView; private boolean paneShouldBeOpen = true; + private ArrayAdapter<Conversation> listAdapter; + + private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() { + + @Override + public void onConversationListChanged() { + Log.d("xmppService","on conversation list changed event received"); + conversationList.clear(); + conversationList.addAll(xmppConnectionService + .getConversations()); + runOnUiThread(new Runnable() { + + @Override + public void run() { + listAdapter.notifyDataSetChanged(); + if(paneShouldBeOpen) { + selectedConversation = 0; + if (conversationList.size() >= 1) { + updateConversationList(); + swapConversationFragment(); + } else { + startActivity(new Intent(getApplicationContext(), NewConversationActivity.class)); + finish(); + } + } else { + Log.d("xmppService","pane wasnt open. dont swap fragment"); + } + } + }); + } + }; public List<Conversation> getConversationList() { @@ -93,7 +124,7 @@ public class ConversationActivity extends XmppActivity { listView = (ListView) findViewById(R.id.list); - listView.setAdapter(new ArrayAdapter<Conversation>(this, + this.listAdapter = new ArrayAdapter<Conversation>(this, R.layout.conversation_list_row, conversationList) { @Override public View getView(int position, View view, ViewGroup parent) { @@ -122,7 +153,9 @@ public class ConversationActivity extends XmppActivity { return view; } - }); + }; + + listView.setAdapter(this.listAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @@ -212,19 +245,9 @@ public class ConversationActivity extends XmppActivity { case R.id.action_archive: Conversation conv = getConversationList().get(selectedConversation); conv.setStatus(Conversation.STATUS_ARCHIVED); - xmppConnectionService.updateConversation(conv); - conversationList.remove(selectedConversation); - selectedConversation = 0; - if (conversationList.size() >= 1) { - paneShouldBeOpen = true; - swapConversationFragment(); - ((ArrayAdapter) listView.getAdapter()).notifyDataSetChanged(); - spl.openPane(); - } else { - startActivity(new Intent(this, NewConversationActivity.class)); - finish(); - } - //goto new + paneShouldBeOpen = true; + spl.openPane(); + xmppConnectionService.archiveConversation(conv); break; default: break; @@ -259,15 +282,39 @@ public class ConversationActivity extends XmppActivity { if (xmppConnectionServiceBound) { conversationList.clear(); conversationList.addAll(xmppConnectionService - .getConversations(Conversation.STATUS_AVAILABLE)); + .getConversations()); } } + + @Override + public void onPause() { + super.onPause(); + if (xmppConnectionServiceBound) { + Log.d("xmppService","called on pause. remove listener"); + xmppConnectionService.removeOnConversationListChangedListener(); + } + } + + @Override + protected void onStop() { + super.onStop(); + if (xmppConnectionServiceBound) { + Log.d("xmppService","called on stop. remove listener"); + xmppConnectionService.removeOnConversationListChangedListener(); + unbindService(mConnection); + xmppConnectionServiceBound = false; + } + } + @Override void onBackendConnected() { + + xmppConnectionService.setOnConversationListChangedListener(this.onConvChanged); + conversationList.clear(); conversationList.addAll(xmppConnectionService - .getConversations(Conversation.STATUS_AVAILABLE)); + .getConversations()); for(Conversation conversation : conversationList) { conversation.setMessages(xmppConnectionService.getMessages(conversation)); diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index c3b73ac5..57d4b1eb 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -116,13 +116,16 @@ public class ConversationFragment extends Fragment { } else { Log.d("gultsch", "recylecd a view"); } + ImageView imageView = (ImageView) view.findViewById(R.id.message_photo); if (type == RECIEVED) { - ((ImageView) view.findViewById(R.id.message_photo)) - .setImageURI(item.getConversation() - .getProfilePhotoUri()); + Uri uri = item.getConversation().getProfilePhotoUri(); + if (uri!=null) { + imageView.setImageURI(uri); + } else { + imageView.setImageBitmap(Beautifier.getUnknownContactPicture(item.getConversation().getName(), 200)); + } } else { - ((ImageView) view.findViewById(R.id.message_photo)) - .setImageURI(profilePicture); + imageView.setImageURI(profilePicture); } ((TextView) view.findViewById(R.id.message_body)).setText(item .getBody()); diff --git a/src/de/gultsch/chat/ui/OnConversationListChangedListener.java b/src/de/gultsch/chat/ui/OnConversationListChangedListener.java new file mode 100644 index 00000000..08b2bfb1 --- /dev/null +++ b/src/de/gultsch/chat/ui/OnConversationListChangedListener.java @@ -0,0 +1,5 @@ +package de.gultsch.chat.ui; + +public interface OnConversationListChangedListener { + public void onConversationListChanged(); +} |