diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-02 16:05:15 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-02 16:05:15 +0100 |
commit | d365bbe480bdd26a042b425c45227785ab4fbf51 (patch) | |
tree | 4389b79b60d89724fd74eebf5674834888e9b436 /src/de/gultsch/chat/ui | |
parent | 53d9c9997a508985f0e19aba928bfa25c80ba23e (diff) |
fetching roster. fixed sending messages as type chat
Diffstat (limited to '')
4 files changed, 58 insertions, 51 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index 23d03a01..b06fa21d 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -49,26 +49,29 @@ public class ConversationActivity extends XmppActivity { @Override public void onConversationListChanged() { - Log.d("xmppService","on conversation list changed event received"); + final Conversation currentConv = conversationList.get(selectedConversation); conversationList.clear(); conversationList.addAll(xmppConnectionService .getConversations()); runOnUiThread(new Runnable() { @Override - public void run() { - listAdapter.notifyDataSetChanged(); + public void run() { + updateConversationList(); + for(int i = 0; i < conversationList.size(); ++i) { + if (currentConv.equals(conversationList.get(i))) { + selectedConversation = i; + break; + } + } 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"); } } }); @@ -98,19 +101,12 @@ public class ConversationActivity extends XmppActivity { public void updateConversationList() { if (conversationList.size() >= 1) { - Conversation currentConv = conversationList.get(selectedConversation); Collections.sort(this.conversationList, new Comparator<Conversation>() { @Override public int compare(Conversation lhs, Conversation rhs) { return (int) (rhs.getLatestMessageDate() - lhs.getLatestMessageDate()); } }); - for(int i = 0; i < conversationList.size(); ++i) { - if (currentConv == conversationList.get(i)) { - selectedConversation = i; - break; - } - } } this.listView.invalidateViews(); } @@ -198,6 +194,7 @@ public class ConversationActivity extends XmppActivity { @Override public void onPanelClosed(View arg0) { + paneShouldBeOpen = false; if (conversationList.size() > 0) { getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setTitle(conversationList.get(selectedConversation).getName()); @@ -248,6 +245,7 @@ public class ConversationActivity extends XmppActivity { paneShouldBeOpen = true; spl.openPane(); xmppConnectionService.archiveConversation(conv); + selectedConversation = 0; break; default: break; @@ -275,53 +273,36 @@ public class ConversationActivity extends XmppActivity { } return super.onKeyDown(keyCode, event); } - - @Override - public void onStart() { - super.onStart(); - if (xmppConnectionServiceBound) { - conversationList.clear(); - conversationList.addAll(xmppConnectionService - .getConversations()); - } - } @Override - public void onPause() { + protected 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()); - - for(Conversation conversation : conversationList) { - conversation.setMessages(xmppConnectionService.getMessages(conversation)); + if (conversationList.size()==0) { + Log.d("gultsch","conversation list is empty fetch new"); + conversationList.clear(); + conversationList.addAll(xmppConnectionService + .getConversations()); + + for(Conversation conversation : conversationList) { + conversation.setMessages(xmppConnectionService.getMessages(conversation)); + } + + this.updateConversationList(); } - this.updateConversationList(); - if ((getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { if (getIntent().getType().equals( ConversationActivity.VIEW_CONVERSATION)) { @@ -354,6 +335,7 @@ public class ConversationActivity extends XmppActivity { selectedFragment.onBackendConnected(); } else { Log.d("gultsch","conversationactivity. no old fragment found. creating new one"); + selectedConversation = 0; Log.d("gultsch","selected conversation is #"+selectedConversation); swapConversationFragment(); } diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index 57d4b1eb..b8edcbaf 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -54,7 +54,7 @@ public class ConversationFragment extends Fragment { return; Message message = new Message(conversation, chatMsg .getText().toString(), Message.ENCRYPTION_NONE); - activity.xmppConnectionService.sendMessage(message); + activity.xmppConnectionService.sendMessage(conversation.getAccount(),message); conversation.getMessages().add(message); chatMsg.setText(""); @@ -105,16 +105,12 @@ public class ConversationFragment extends Fragment { case SENT: view = (View) inflater.inflate(R.layout.message_sent, null); - Log.d("gultsch", "inflated new message_sent view"); break; case RECIEVED: view = (View) inflater.inflate( R.layout.message_recieved, null); - Log.d("gultsch", "inflated new message_recieved view"); break; } - } else { - Log.d("gultsch", "recylecd a view"); } ImageView imageView = (ImageView) view.findViewById(R.id.message_photo); if (type == RECIEVED) { @@ -128,7 +124,7 @@ public class ConversationFragment extends Fragment { imageView.setImageURI(profilePicture); } ((TextView) view.findViewById(R.id.message_body)).setText(item - .getBody()); + .getBody().trim()); TextView time = (TextView) view.findViewById(R.id.message_time); if (item.getStatus() == Message.STATUS_UNSEND) { time.setTypeface(null, Typeface.ITALIC); diff --git a/src/de/gultsch/chat/ui/NewConversationActivity.java b/src/de/gultsch/chat/ui/NewConversationActivity.java index b8061b23..b41ca761 100644 --- a/src/de/gultsch/chat/ui/NewConversationActivity.java +++ b/src/de/gultsch/chat/ui/NewConversationActivity.java @@ -51,6 +51,7 @@ public class NewConversationActivity extends XmppActivity { protected EditText search; protected String searchString = ""; private TextView contactsHeader; + private List<Account> accounts; protected void updateAggregatedContacts() { @@ -76,7 +77,7 @@ public class NewConversationActivity extends XmppActivity { if (Validator.isValidJid(searchString)) { String name = searchString.split("@")[0]; - Contact newContact = new Contact(name, searchString,null); + Contact newContact = new Contact(null,name, searchString,null); aggregatedContacts.add(newContact); contactsHeader.setText("Create new contact"); } else { @@ -87,6 +88,7 @@ public class NewConversationActivity extends XmppActivity { } contactsAdapter.notifyDataSetChanged(); + contactsView.setScrollX(0); } static final String[] PROJECTION = new String[] { @@ -229,7 +231,7 @@ public class NewConversationActivity extends XmppActivity { /*if (profilePhoto == null) { profilePhoto = DEFAULT_PROFILE_PHOTO; }*/ - Contact contact = new Contact( + Contact contact = new Contact(null, cursor.getString(cursor .getColumnIndex(ContactsContract.Data.DISPLAY_NAME)), cursor.getString(cursor @@ -250,6 +252,25 @@ public class NewConversationActivity extends XmppActivity { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); } + this.accounts = xmppConnectionService.getAccounts(); + this.rosterContacts.clear(); + for(Account account : this.accounts) { + xmppConnectionService.getRoster(account, new OnRosterFetchedListener() { + + @Override + public void onRosterFetched(List<Contact> roster) { + rosterContacts.addAll(roster); + runOnUiThread(new Runnable() { + + @Override + public void run() { + updateAggregatedContacts(); + } + }); + + } + }); + } } @Override diff --git a/src/de/gultsch/chat/ui/OnRosterFetchedListener.java b/src/de/gultsch/chat/ui/OnRosterFetchedListener.java new file mode 100644 index 00000000..ad3f6592 --- /dev/null +++ b/src/de/gultsch/chat/ui/OnRosterFetchedListener.java @@ -0,0 +1,8 @@ +package de.gultsch.chat.ui; + +import java.util.List; +import de.gultsch.chat.entities.Contact; + +public interface OnRosterFetchedListener { + public void onRosterFetched(List<Contact> roster); +} |