# HG changeset patch # User Nikita Kozlov # Date 1268788577 -3600 # Node ID b4333628a4a375626835fe2ad8aa9bea7deb5f6c # Parent bbd54153f92c18c376e9a87e1028cecbda2b6ce9 beginning on chat by resource integration and a small fix for the TrustStore diff -r bbd54153f92c -r b4333628a4a3 res/menu/contactlist_context.xml --- a/res/menu/contactlist_context.xml Sun Mar 14 00:35:25 2010 +0100 +++ b/res/menu/contactlist_context.xml Wed Mar 17 02:16:17 2010 +0100 @@ -1,6 +1,9 @@ + android:title="@string/CDChat"> + + + + android:title="@string/userinfo_label_block" android:visible="false" /> diff -r bbd54153f92c -r b4333628a4a3 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sun Mar 14 00:35:25 2010 +0100 +++ b/src/com/beem/project/beem/BeemService.java Wed Mar 17 02:16:17 2010 +0100 @@ -142,6 +142,8 @@ } mConnectionConfiguration.setDebuggerEnabled(false); mConnectionConfiguration.setSendPresence(true); + mConnectionConfiguration.setTruststoreType("BKS"); + mConnectionConfiguration.setTruststorePath("/system/etc/security/cacerts.bks"); //FIXME: maybe not the universal path, but working on my galaxy } /** diff -r bbd54153f92c -r b4333628a4a3 src/com/beem/project/beem/service/BeemChatManager.java --- a/src/com/beem/project/beem/service/BeemChatManager.java Sun Mar 14 00:35:25 2010 +0100 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Wed Mar 17 02:16:17 2010 +0100 @@ -124,7 +124,7 @@ * @return the chat session */ public IChat createChat(String jid, IMessageListener listener) { - String key = StringUtils.parseBareAddress(jid); + String key = jid; ChatAdapter result; Log.d(TAG, "Get chat key = " + key); if (mChats.containsKey(key)) { @@ -171,7 +171,7 @@ * @return a chat adapter register in the manager */ private ChatAdapter getChat(Chat chat) { - String key = StringUtils.parseBareAddress(chat.getParticipant()); + String key = chat.getParticipant(); if (mChats.containsKey(key)) { return mChats.get(key); } diff -r bbd54153f92c -r b4333628a4a3 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Sun Mar 14 00:35:25 2010 +0100 +++ b/src/com/beem/project/beem/service/Contact.java Wed Mar 17 02:16:17 2010 +0100 @@ -80,6 +80,7 @@ private int mID; private int mStatus; private String mJID; + private String mSelectedRes; private String mMsgState; private List mRes; private List mGroups; @@ -99,6 +100,7 @@ mID = in.readInt(); mStatus = in.readInt(); mJID = in.readString(); + mSelectedRes = in.readString(); mName = in.readString(); mMsgState = in.readString(); mRes = new ArrayList(); @@ -118,6 +120,7 @@ mMsgState = null; mRes = new ArrayList(); String res = StringUtils.parseResource(jid); + mSelectedRes = res; if (!"".equals(res)) mRes.add(res); mGroups = new ArrayList(); @@ -137,7 +140,9 @@ mStatus = Status.CONTACT_STATUS_DISCONNECT; mMsgState = null; mRes = new ArrayList(); - mRes.add(StringUtils.parseResource(enduri)); + String res = StringUtils.parseResource(enduri); + mSelectedRes = res; + mRes.add(res); mGroups = new ArrayList(); } @@ -149,6 +154,7 @@ dest.writeInt(mID); dest.writeInt(mStatus); dest.writeString(mJID); + dest.writeString(mSelectedRes); dest.writeString(mName); dest.writeString(mMsgState); dest.writeStringList(getMRes()); @@ -194,7 +200,6 @@ */ @Override public int describeContents() { - // TODO Auto-generated method stub return 0; } @@ -223,6 +228,14 @@ } /** + * Get selected resource. + * @return the selected resource. + */ + public String getSelectedRes() { + return mSelectedRes; + } + + /** * Get the list of resource for the contact. * @return the mRes */ @@ -290,6 +303,14 @@ } /** + * Set the resource of the contact. + * @param resource to set. + */ + public void setSelectedRes(String resource) { + mSelectedRes = resource; + } + + /** * Set a list of resource for the contact. * @param mRes the mRes to set */ @@ -391,4 +412,15 @@ Uri u = Uri.parse(build.toString()); return u; } + + /** + * Get a JID to access the specific contact on this resource. + * @return the JID. + */ + public String getJIDWithRes() { + StringBuilder build = new StringBuilder(mJID); + if (!"".equals(mSelectedRes)) + build.append('/').append(mSelectedRes); + return build.toString(); + } } diff -r bbd54153f92c -r b4333628a4a3 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Sun Mar 14 00:35:25 2010 +0100 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Wed Mar 17 02:16:17 2010 +0100 @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -55,6 +56,7 @@ import org.jivesoftware.smack.RosterListener; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.util.StringUtils; import android.content.Context; import android.os.RemoteCallbackList; @@ -266,6 +268,12 @@ } catch (NullPointerException e) { Log.d(TAG, "Group list not ready"); } + Iterator iPres = mAdaptee.getPresences(user); + while (iPres.hasNext()) { + p = iPres.next(); + if (!p.getType().equals(Presence.Type.unavailable)) + c.addRes(StringUtils.parseResource(p.getFrom())); + } c.setName(entry.getName()); return c; } @@ -351,7 +359,7 @@ @Override public void entriesUpdated(Collection addresses) { Log.i(TAG, "Update de l'entry " + addresses.size() + " " + - addresses.toArray()[0]); + addresses.toArray()[0]); final int n = mRemoteRosListeners.beginBroadcast(); List tab = new ArrayList(); diff -r bbd54153f92c -r b4333628a4a3 src/com/beem/project/beem/ui/Chat.java --- a/src/com/beem/project/beem/ui/Chat.java Sun Mar 14 00:35:25 2010 +0100 +++ b/src/com/beem/project/beem/ui/Chat.java Wed Mar 17 02:16:17 2010 +0100 @@ -227,7 +227,6 @@ */ @Override protected void onSaveInstanceState(Bundle savedInstanceState) { - // TODO super.onSaveInstanceState(savedInstanceState); } @@ -237,7 +236,6 @@ @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); - // TODO } /** @@ -339,8 +337,12 @@ mChatManager.deleteChatNotification(mChat); } mContact = mRoster.getContact(contact.getJID()); + String res = contact.getSelectedRes(); if (mContact == null) mContact = contact; + if (!"".equals(res)) { + mContact.setSelectedRes(res); + } updateContactInformations(); updateContactStatusIcon(); @@ -570,8 +572,12 @@ */ private void updateContactInformations() { // Check for a contact name update - if (!(mContactNameTextView.getText().toString().equals(mContact.getName()))) - mContactNameTextView.setText(mContact.getName()); + String name = mContact.getName(); + String res = mContact.getSelectedRes(); + if (!"".equals(res)) + name += "(" + res + ")"; + if (!(mContactNameTextView.getText().toString().equals(name))) + mContactNameTextView.setText(name); // Check for a contact status message update if (!(mContactStatusMsgTextView.getText().toString().equals(mContact.getMsgState()))) { @@ -797,7 +803,7 @@ final String inputContent = mInputField.getText().toString(); if (!"".equals(inputContent)) { - Message msgToSend = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT); + Message msgToSend = new Message(mContact.getJIDWithRes(), Message.MSG_TYPE_CHAT); msgToSend.setBody(inputContent); try { @@ -840,8 +846,8 @@ if (locally) return; try { - String contactJid = StringUtils.parseBareAddress(mContact.getJID()); - String chatJid = StringUtils.parseBareAddress(chat.getParticipant().getJID()); + String contactJid = mContact.getJIDWithRes(); + String chatJid = chat.getParticipant().getJIDWithRes(); if (chatJid.equals(contactJid)) { // This should not be happened but to be sure if (mChat != null) { diff -r bbd54153f92c -r b4333628a4a3 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Sun Mar 14 00:35:25 2010 +0100 +++ b/src/com/beem/project/beem/ui/ContactList.java Wed Mar 17 02:16:17 2010 +0100 @@ -195,9 +195,16 @@ if (mContact != null) { switch (item.getItemId()) { case R.id.contact_list_context_menu_chat_item: - in = new Intent(this, Chat.class); - in.setData(mContact.toUri()); - startActivity(in); + List res = mContact.getMRes(); + if (res.isEmpty()) { + result = false; + break; + } + for (String resv : res) { + in = new Intent(this, Chat.class); + in.setData(mContact.toUri(resv)); + item.getSubMenu().add(resv).setIntent(in); + } result = true; break; case R.id.contact_list_context_menu_call_item: