reworked new conversation activity again. less asking more knowing. mucs are now connected on creation of the conversation. no reconnect required
This commit is contained in:
parent
86dbb2f411
commit
95068ee776
|
@ -8,7 +8,6 @@ import android.database.Cursor;
|
|||
public class Contact extends AbstractEntity implements Serializable {
|
||||
private static final long serialVersionUID = -4570817093119419962L;
|
||||
|
||||
|
||||
public static final String TABLENAME = "contacts";
|
||||
|
||||
public static final String DISPLAYNAME = "name";
|
||||
|
@ -29,10 +28,10 @@ public class Contact extends AbstractEntity implements Serializable {
|
|||
protected String openPGPKey;
|
||||
protected long lastPresence;
|
||||
|
||||
|
||||
protected Account account;
|
||||
|
||||
public Contact(Account account, String displayName, String jid, String photoUri) {
|
||||
public Contact(Account account, String displayName, String jid,
|
||||
String photoUri) {
|
||||
if (account == null) {
|
||||
this.accountUuid = null;
|
||||
} else {
|
||||
|
@ -43,7 +42,9 @@ public class Contact extends AbstractEntity implements Serializable {
|
|||
this.photoUri = photoUri;
|
||||
}
|
||||
|
||||
public Contact(String uuid, String account, String displayName, String jid, String subscription, String photoUri, int systemAccount, String pgpKey, long lastseen) {
|
||||
public Contact(String uuid, String account, String displayName, String jid,
|
||||
String subscription, String photoUri, int systemAccount,
|
||||
String pgpKey, long lastseen) {
|
||||
this.uuid = uuid;
|
||||
this.accountUuid = account;
|
||||
this.displayName = displayName;
|
||||
|
@ -68,7 +69,8 @@ public class Contact extends AbstractEntity implements Serializable {
|
|||
}
|
||||
|
||||
public boolean match(String needle) {
|
||||
return (jid.toLowerCase().contains(needle.toLowerCase()) || (displayName.toLowerCase().contains(needle.toLowerCase())));
|
||||
return (jid.toLowerCase().contains(needle.toLowerCase()) || (displayName
|
||||
.toLowerCase().contains(needle.toLowerCase())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,8 +97,7 @@ public class Contact extends AbstractEntity implements Serializable {
|
|||
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
||||
cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
|
||||
cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
|
||||
cursor.getLong(cursor.getColumnIndex(LASTPRESENCE))
|
||||
);
|
||||
cursor.getLong(cursor.getColumnIndex(LASTPRESENCE)));
|
||||
}
|
||||
|
||||
public void setSubscription(String subscription) {
|
||||
|
@ -119,4 +120,20 @@ public class Contact extends AbstractEntity implements Serializable {
|
|||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public boolean couldBeMuc() {
|
||||
String[] split = this.getJid().split("@");
|
||||
if (split.length != 2) {
|
||||
return false;
|
||||
} else {
|
||||
String[] domainParts = split[1].split("\\.");
|
||||
if (domainParts.length < 3) {
|
||||
return false;
|
||||
} else {
|
||||
return (domainParts[0].equals("conf")
|
||||
|| domainParts[0].equals("conference") || domainParts[0]
|
||||
.equals("muc"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,4 +160,8 @@ public class Conversation extends AbstractEntity {
|
|||
public int getMode() {
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class XmppConnectionService extends Service {
|
|||
String jid = fullJid.split("/")[0];
|
||||
counterPart = fullJid;
|
||||
Contact contact = findOrCreateContact(account,jid);
|
||||
conversation = findOrCreateConversation(account, contact);
|
||||
conversation = findOrCreateConversation(account, contact,false);
|
||||
} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {
|
||||
String[] fromParts = fullJid.split("/");
|
||||
if (fromParts.length != 2) {
|
||||
|
@ -201,6 +201,9 @@ public class XmppConnectionService extends Service {
|
|||
|
||||
public void getRoster(Account account, final OnRosterFetchedListener listener) {
|
||||
List<Contact> contacts = databaseBackend.getContacts(account);
|
||||
for(int i=0; i < contacts.size(); ++i) {
|
||||
contacts.get(i).setAccount(account);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onRosterFetched(contacts);
|
||||
}
|
||||
|
@ -339,27 +342,40 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
|
||||
public Conversation findOrCreateConversation(Account account,
|
||||
Contact contact) {
|
||||
// Log.d(LOGTAG,"was asked to find conversation for "+contact.getJid());
|
||||
Contact contact,boolean muc) {
|
||||
for (Conversation conv : this.getConversations()) {
|
||||
if ((conv.getAccount().equals(account))
|
||||
&& (conv.getContactJid().equals(contact.getJid()))) {
|
||||
// Log.d(LOGTAG,"found one in memory");
|
||||
return conv;
|
||||
}
|
||||
}
|
||||
Conversation conversation = databaseBackend.findConversation(account,
|
||||
contact.getJid());
|
||||
if (conversation != null) {
|
||||
Log.d("gultsch", "found one. unarchive it");
|
||||
conversation.setStatus(Conversation.STATUS_AVAILABLE);
|
||||
conversation.setAccount(account);
|
||||
if (muc) {
|
||||
conversation.setMode(Conversation.MODE_MULTI);
|
||||
if (account.getStatus()==Account.STATUS_ONLINE) {
|
||||
joinMuc(account, conversation);
|
||||
}
|
||||
} else {
|
||||
conversation.setMode(Conversation.MODE_SINGLE);
|
||||
}
|
||||
this.databaseBackend.updateConversation(conversation);
|
||||
} else {
|
||||
Log.d(LOGTAG, "didnt find one in archive. create new one");
|
||||
if (muc) {
|
||||
conversation = new Conversation(contact.getDisplayName(),
|
||||
contact.getProfilePhoto(), account, contact.getJid(),
|
||||
Conversation.MODE_MULTI);
|
||||
if (account.getStatus()==Account.STATUS_ONLINE) {
|
||||
joinMuc(account, conversation);
|
||||
}
|
||||
} else {
|
||||
conversation = new Conversation(contact.getDisplayName(),
|
||||
contact.getProfilePhoto(), account, contact.getJid(),
|
||||
Conversation.MODE_SINGLE);
|
||||
}
|
||||
this.databaseBackend.createConversation(conversation);
|
||||
}
|
||||
this.conversations.add(conversation);
|
||||
|
@ -443,9 +459,13 @@ public class XmppConnectionService extends Service {
|
|||
Conversation conversation = conversations.get(i);
|
||||
if ((conversation.getMode() == Conversation.MODE_MULTI)
|
||||
&& (conversation.getAccount() == account)) {
|
||||
joinMuc(account, conversation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void joinMuc(Account account, Conversation conversation) {
|
||||
String muc = conversation.getContactJid();
|
||||
Log.d(LOGTAG,
|
||||
"join muc " + muc + " with account " + account.getJid());
|
||||
PresencePacket packet = new PresencePacket();
|
||||
packet.setAttribute("to", muc + "/" + account.getUsername());
|
||||
Element x = new Element("x");
|
||||
|
@ -453,9 +473,6 @@ public class XmppConnectionService extends Service {
|
|||
packet.addChild(x);
|
||||
connections.get(conversation.getAccount()).sendPresencePacket(
|
||||
packet);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnectMultiModeConversations() {
|
||||
|
|
|
@ -130,14 +130,16 @@ public class NewConversationActivity extends XmppActivity {
|
|||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
Contact contact = getItem(position);
|
||||
if (view == null) {
|
||||
view = (View) inflater.inflate(R.layout.contact, null);
|
||||
}
|
||||
|
||||
((TextView) view.findViewById(R.id.contact_display_name))
|
||||
.setText(getItem(position).getDisplayName());
|
||||
((TextView) view.findViewById(R.id.contact_jid))
|
||||
.setText(getItem(position).getJid());
|
||||
TextView contactJid = (TextView) view
|
||||
.findViewById(R.id.contact_jid);
|
||||
contactJid.setText(contact.getJid());
|
||||
String profilePhoto = getItem(position).getProfilePhoto();
|
||||
ImageView imageView = (ImageView) view
|
||||
.findViewById(R.id.contact_photo);
|
||||
|
@ -158,39 +160,61 @@ public class NewConversationActivity extends XmppActivity {
|
|||
public void onItemClick(AdapterView<?> arg0, final View view,
|
||||
int pos, long arg3) {
|
||||
final Contact clickedContact = aggregatedContacts.get(pos);
|
||||
Log.d("gultsch",
|
||||
"clicked on " + clickedContact.getDisplayName());
|
||||
|
||||
final List<Account> accounts = xmppConnectionService
|
||||
.getAccounts();
|
||||
if (accounts.size() == 1) {
|
||||
startConversation(clickedContact, accounts.get(0));
|
||||
} else {
|
||||
if ((clickedContact.getAccount()==null)&&(accounts.size()>1)) {
|
||||
String[] accountList = new String[accounts.size()];
|
||||
for (int i = 0; i < accounts.size(); ++i) {
|
||||
accountList[i] = accounts.get(i).getJid();
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
AlertDialog.Builder accountChooser = new AlertDialog.Builder(
|
||||
activity);
|
||||
builder.setTitle("Choose account");
|
||||
builder.setItems(accountList, new OnClickListener() {
|
||||
accountChooser.setTitle("Choose account");
|
||||
accountChooser.setItems(accountList, new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Account account = accounts.get(which);
|
||||
startConversation(clickedContact, account);
|
||||
clickedContact.setAccount(accounts.get(which));
|
||||
showIsMucDialogIfNeeded(clickedContact);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
accountChooser.create().show();
|
||||
} else {
|
||||
clickedContact.setAccount(accounts.get(0));
|
||||
showIsMucDialogIfNeeded(clickedContact);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void startConversation(Contact contact, Account account) {
|
||||
public void showIsMucDialogIfNeeded(final Contact clickedContact) {
|
||||
if (clickedContact.couldBeMuc()) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
||||
dialog.setTitle("Multi User Conference");
|
||||
dialog.setMessage("Are you trying to join a conference?");
|
||||
dialog.setPositiveButton("Yes", new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startConversation(clickedContact, clickedContact.getAccount(),true);
|
||||
}
|
||||
});
|
||||
dialog.setNegativeButton("No", new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startConversation(clickedContact, clickedContact.getAccount(),false);
|
||||
}
|
||||
});
|
||||
dialog.create().show();
|
||||
} else {
|
||||
startConversation(clickedContact, clickedContact.getAccount(),false);
|
||||
}
|
||||
}
|
||||
|
||||
public void startConversation(Contact contact, Account account, boolean muc) {
|
||||
Conversation conversation = xmppConnectionService
|
||||
.findOrCreateConversation(account, contact);
|
||||
.findOrCreateConversation(account, contact, muc);
|
||||
|
||||
Intent viewConversationIntent = new Intent(this,
|
||||
ConversationActivity.class);
|
||||
|
@ -213,7 +237,8 @@ public class NewConversationActivity extends XmppActivity {
|
|||
this.rosterContacts.clear();
|
||||
for (int i = 0; i < accounts.size(); ++i) {
|
||||
if (accounts.get(i).getStatus() == Account.STATUS_ONLINE) {
|
||||
xmppConnectionService.getRoster(accounts.get(i),new OnRosterFetchedListener() {
|
||||
xmppConnectionService.getRoster(accounts.get(i),
|
||||
new OnRosterFetchedListener() {
|
||||
|
||||
@Override
|
||||
public void onRosterFetched(List<Contact> roster) {
|
||||
|
@ -274,7 +299,8 @@ public class NewConversationActivity extends XmppActivity {
|
|||
new OnRosterFetchedListener() {
|
||||
|
||||
@Override
|
||||
public void onRosterFetched(final List<Contact> roster) {
|
||||
public void onRosterFetched(
|
||||
final List<Contact> roster) {
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -321,7 +321,7 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
private void sendStartStream() {
|
||||
Tag stream = Tag.start("stream");
|
||||
Tag stream = Tag.start("stream:stream");
|
||||
stream.setAttribute("from", account.getJid());
|
||||
stream.setAttribute("to", account.getServer());
|
||||
stream.setAttribute("version", "1.0");
|
||||
|
|
Loading…
Reference in a new issue