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 {
|
public class Contact extends AbstractEntity implements Serializable {
|
||||||
private static final long serialVersionUID = -4570817093119419962L;
|
private static final long serialVersionUID = -4570817093119419962L;
|
||||||
|
|
||||||
|
|
||||||
public static final String TABLENAME = "contacts";
|
public static final String TABLENAME = "contacts";
|
||||||
|
|
||||||
public static final String DISPLAYNAME = "name";
|
public static final String DISPLAYNAME = "name";
|
||||||
|
@ -29,10 +28,10 @@ public class Contact extends AbstractEntity implements Serializable {
|
||||||
protected String openPGPKey;
|
protected String openPGPKey;
|
||||||
protected long lastPresence;
|
protected long lastPresence;
|
||||||
|
|
||||||
|
|
||||||
protected Account account;
|
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) {
|
if (account == null) {
|
||||||
this.accountUuid = null;
|
this.accountUuid = null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,7 +42,9 @@ public class Contact extends AbstractEntity implements Serializable {
|
||||||
this.photoUri = photoUri;
|
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.uuid = uuid;
|
||||||
this.accountUuid = account;
|
this.accountUuid = account;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
|
@ -68,21 +69,22 @@ public class Contact extends AbstractEntity implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean match(String needle) {
|
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
|
@Override
|
||||||
public ContentValues getContentValues() {
|
public ContentValues getContentValues() {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UUID,uuid);
|
values.put(UUID, uuid);
|
||||||
values.put(ACCOUNT,accountUuid);
|
values.put(ACCOUNT, accountUuid);
|
||||||
values.put(DISPLAYNAME, displayName);
|
values.put(DISPLAYNAME, displayName);
|
||||||
values.put(JID, jid);
|
values.put(JID, jid);
|
||||||
values.put(SUBSCRIPTION,subscription);
|
values.put(SUBSCRIPTION, subscription);
|
||||||
values.put(SYSTEMACCOUNT, systemAccount);
|
values.put(SYSTEMACCOUNT, systemAccount);
|
||||||
values.put(PHOTOURI,photoUri);
|
values.put(PHOTOURI, photoUri);
|
||||||
values.put(OPENPGPKEY,openPGPKey);
|
values.put(OPENPGPKEY, openPGPKey);
|
||||||
values.put(LASTPRESENCE,lastPresence);
|
values.put(LASTPRESENCE, lastPresence);
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +97,7 @@ public class Contact extends AbstractEntity implements Serializable {
|
||||||
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
||||||
cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
|
cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
|
||||||
cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
|
cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
|
||||||
cursor.getLong(cursor.getColumnIndex(LASTPRESENCE))
|
cursor.getLong(cursor.getColumnIndex(LASTPRESENCE)));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubscription(String subscription) {
|
public void setSubscription(String subscription) {
|
||||||
|
@ -119,4 +120,20 @@ public class Contact extends AbstractEntity implements Serializable {
|
||||||
public void setUuid(String uuid) {
|
public void setUuid(String uuid) {
|
||||||
this.uuid = 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() {
|
public int getMode() {
|
||||||
return this.mode;
|
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];
|
String jid = fullJid.split("/")[0];
|
||||||
counterPart = fullJid;
|
counterPart = fullJid;
|
||||||
Contact contact = findOrCreateContact(account,jid);
|
Contact contact = findOrCreateContact(account,jid);
|
||||||
conversation = findOrCreateConversation(account, contact);
|
conversation = findOrCreateConversation(account, contact,false);
|
||||||
} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {
|
} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {
|
||||||
String[] fromParts = fullJid.split("/");
|
String[] fromParts = fullJid.split("/");
|
||||||
if (fromParts.length != 2) {
|
if (fromParts.length != 2) {
|
||||||
|
@ -201,6 +201,9 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public void getRoster(Account account, final OnRosterFetchedListener listener) {
|
public void getRoster(Account account, final OnRosterFetchedListener listener) {
|
||||||
List<Contact> contacts = databaseBackend.getContacts(account);
|
List<Contact> contacts = databaseBackend.getContacts(account);
|
||||||
|
for(int i=0; i < contacts.size(); ++i) {
|
||||||
|
contacts.get(i).setAccount(account);
|
||||||
|
}
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onRosterFetched(contacts);
|
listener.onRosterFetched(contacts);
|
||||||
}
|
}
|
||||||
|
@ -339,27 +342,40 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conversation findOrCreateConversation(Account account,
|
public Conversation findOrCreateConversation(Account account,
|
||||||
Contact contact) {
|
Contact contact,boolean muc) {
|
||||||
// Log.d(LOGTAG,"was asked to find conversation for "+contact.getJid());
|
|
||||||
for (Conversation conv : this.getConversations()) {
|
for (Conversation conv : this.getConversations()) {
|
||||||
if ((conv.getAccount().equals(account))
|
if ((conv.getAccount().equals(account))
|
||||||
&& (conv.getContactJid().equals(contact.getJid()))) {
|
&& (conv.getContactJid().equals(contact.getJid()))) {
|
||||||
// Log.d(LOGTAG,"found one in memory");
|
|
||||||
return conv;
|
return conv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Conversation conversation = databaseBackend.findConversation(account,
|
Conversation conversation = databaseBackend.findConversation(account,
|
||||||
contact.getJid());
|
contact.getJid());
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
Log.d("gultsch", "found one. unarchive it");
|
|
||||||
conversation.setStatus(Conversation.STATUS_AVAILABLE);
|
conversation.setStatus(Conversation.STATUS_AVAILABLE);
|
||||||
conversation.setAccount(account);
|
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);
|
this.databaseBackend.updateConversation(conversation);
|
||||||
} else {
|
} else {
|
||||||
Log.d(LOGTAG, "didnt find one in archive. create new one");
|
if (muc) {
|
||||||
conversation = new Conversation(contact.getDisplayName(),
|
conversation = new Conversation(contact.getDisplayName(),
|
||||||
contact.getProfilePhoto(), account, contact.getJid(),
|
contact.getProfilePhoto(), account, contact.getJid(),
|
||||||
Conversation.MODE_SINGLE);
|
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.databaseBackend.createConversation(conversation);
|
||||||
}
|
}
|
||||||
this.conversations.add(conversation);
|
this.conversations.add(conversation);
|
||||||
|
@ -443,21 +459,22 @@ public class XmppConnectionService extends Service {
|
||||||
Conversation conversation = conversations.get(i);
|
Conversation conversation = conversations.get(i);
|
||||||
if ((conversation.getMode() == Conversation.MODE_MULTI)
|
if ((conversation.getMode() == Conversation.MODE_MULTI)
|
||||||
&& (conversation.getAccount() == account)) {
|
&& (conversation.getAccount() == account)) {
|
||||||
String muc = conversation.getContactJid();
|
joinMuc(account, conversation);
|
||||||
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");
|
|
||||||
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
|
|
||||||
packet.addChild(x);
|
|
||||||
connections.get(conversation.getAccount()).sendPresencePacket(
|
|
||||||
packet);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void joinMuc(Account account, Conversation conversation) {
|
||||||
|
String muc = conversation.getContactJid();
|
||||||
|
PresencePacket packet = new PresencePacket();
|
||||||
|
packet.setAttribute("to", muc + "/" + account.getUsername());
|
||||||
|
Element x = new Element("x");
|
||||||
|
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
|
||||||
|
packet.addChild(x);
|
||||||
|
connections.get(conversation.getAccount()).sendPresencePacket(
|
||||||
|
packet);
|
||||||
|
}
|
||||||
|
|
||||||
public void disconnectMultiModeConversations() {
|
public void disconnectMultiModeConversations() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,14 +130,16 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
Contact contact = getItem(position);
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = (View) inflater.inflate(R.layout.contact, null);
|
view = (View) inflater.inflate(R.layout.contact, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
((TextView) view.findViewById(R.id.contact_display_name))
|
((TextView) view.findViewById(R.id.contact_display_name))
|
||||||
.setText(getItem(position).getDisplayName());
|
.setText(getItem(position).getDisplayName());
|
||||||
((TextView) view.findViewById(R.id.contact_jid))
|
TextView contactJid = (TextView) view
|
||||||
.setText(getItem(position).getJid());
|
.findViewById(R.id.contact_jid);
|
||||||
|
contactJid.setText(contact.getJid());
|
||||||
String profilePhoto = getItem(position).getProfilePhoto();
|
String profilePhoto = getItem(position).getProfilePhoto();
|
||||||
ImageView imageView = (ImageView) view
|
ImageView imageView = (ImageView) view
|
||||||
.findViewById(R.id.contact_photo);
|
.findViewById(R.id.contact_photo);
|
||||||
|
@ -158,39 +160,61 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
public void onItemClick(AdapterView<?> arg0, final View view,
|
public void onItemClick(AdapterView<?> arg0, final View view,
|
||||||
int pos, long arg3) {
|
int pos, long arg3) {
|
||||||
final Contact clickedContact = aggregatedContacts.get(pos);
|
final Contact clickedContact = aggregatedContacts.get(pos);
|
||||||
Log.d("gultsch",
|
|
||||||
"clicked on " + clickedContact.getDisplayName());
|
|
||||||
|
|
||||||
final List<Account> accounts = xmppConnectionService
|
if ((clickedContact.getAccount()==null)&&(accounts.size()>1)) {
|
||||||
.getAccounts();
|
|
||||||
if (accounts.size() == 1) {
|
|
||||||
startConversation(clickedContact, accounts.get(0));
|
|
||||||
} else {
|
|
||||||
String[] accountList = new String[accounts.size()];
|
String[] accountList = new String[accounts.size()];
|
||||||
for (int i = 0; i < accounts.size(); ++i) {
|
for (int i = 0; i < accounts.size(); ++i) {
|
||||||
accountList[i] = accounts.get(i).getJid();
|
accountList[i] = accounts.get(i).getJid();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
AlertDialog.Builder accountChooser = new AlertDialog.Builder(
|
||||||
activity);
|
activity);
|
||||||
builder.setTitle("Choose account");
|
accountChooser.setTitle("Choose account");
|
||||||
builder.setItems(accountList, new OnClickListener() {
|
accountChooser.setItems(accountList, new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Account account = accounts.get(which);
|
clickedContact.setAccount(accounts.get(which));
|
||||||
startConversation(clickedContact, account);
|
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
|
Conversation conversation = xmppConnectionService
|
||||||
.findOrCreateConversation(account, contact);
|
.findOrCreateConversation(account, contact, muc);
|
||||||
|
|
||||||
Intent viewConversationIntent = new Intent(this,
|
Intent viewConversationIntent = new Intent(this,
|
||||||
ConversationActivity.class);
|
ConversationActivity.class);
|
||||||
|
@ -211,24 +235,25 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
this.accounts = xmppConnectionService.getAccounts();
|
this.accounts = xmppConnectionService.getAccounts();
|
||||||
this.rosterContacts.clear();
|
this.rosterContacts.clear();
|
||||||
for(int i = 0; i < accounts.size(); ++i) {
|
for (int i = 0; i < accounts.size(); ++i) {
|
||||||
if (accounts.get(i).getStatus()==Account.STATUS_ONLINE) {
|
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) {
|
|
||||||
rosterContacts.addAll(roster);
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void onRosterFetched(List<Contact> roster) {
|
||||||
updateAggregatedContacts();
|
rosterContacts.addAll(roster);
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateAggregatedContacts();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,26 +294,27 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
this.accounts = xmppConnectionService.getAccounts();
|
this.accounts = xmppConnectionService.getAccounts();
|
||||||
this.rosterContacts.clear();
|
this.rosterContacts.clear();
|
||||||
for (int i = 0; i < accounts.size(); ++i) {
|
for (int i = 0; i < accounts.size(); ++i) {
|
||||||
if (accounts.get(i).getStatus()==Account.STATUS_ONLINE) {
|
if (accounts.get(i).getStatus() == Account.STATUS_ONLINE) {
|
||||||
xmppConnectionService.updateRoster(accounts.get(i),
|
xmppConnectionService.updateRoster(accounts.get(i),
|
||||||
new OnRosterFetchedListener() {
|
new OnRosterFetchedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRosterFetched(final List<Contact> roster) {
|
public void onRosterFetched(
|
||||||
runOnUiThread(new Runnable() {
|
final List<Contact> roster) {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
rosterContacts.addAll(roster);
|
rosterContacts.addAll(roster);
|
||||||
progress.setVisibility(View.GONE);
|
progress.setVisibility(View.GONE);
|
||||||
searchBar.setVisibility(View.VISIBLE);
|
searchBar.setVisibility(View.VISIBLE);
|
||||||
contactList.setVisibility(View.VISIBLE);
|
contactList.setVisibility(View.VISIBLE);
|
||||||
contactList.setVisibility(View.VISIBLE);
|
contactList.setVisibility(View.VISIBLE);
|
||||||
updateAggregatedContacts();
|
updateAggregatedContacts();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,7 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendStartStream() {
|
private void sendStartStream() {
|
||||||
Tag stream = Tag.start("stream");
|
Tag stream = Tag.start("stream:stream");
|
||||||
stream.setAttribute("from", account.getJid());
|
stream.setAttribute("from", account.getJid());
|
||||||
stream.setAttribute("to", account.getServer());
|
stream.setAttribute("to", account.getServer());
|
||||||
stream.setAttribute("version", "1.0");
|
stream.setAttribute("version", "1.0");
|
||||||
|
|
Loading…
Reference in a new issue