muc invites in conference details

This commit is contained in:
Daniel Gultsch 2014-03-15 06:20:59 +01:00
parent afe1244709
commit 841c6e04a9
6 changed files with 166 additions and 81 deletions

View File

@ -8,7 +8,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" > android:orientation="vertical" >
<TextView <TextView
style="@style/sectionHeader" style="@style/sectionHeader"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -134,5 +133,13 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<Button
android:layout_marginTop="24dp"
android:id="@+id/invite"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/invite_contacts"
android:layout_gravity="center_horizontal"/>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -11,4 +11,8 @@
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:icon="@drawable/ic_action_chat" android:icon="@drawable/ic_action_chat"
android:title="@string/start_conversation" /> android:title="@string/start_conversation" />
<item
android:id="@+id/action_invite"
android:showAsAction="ifRoom"
android:title="@string/invite_contacts" />
</menu> </menu>

View File

@ -30,4 +30,5 @@
<string name="show_otr_key">OTR fingerprint</string> <string name="show_otr_key">OTR fingerprint</string>
<string name="no_otr_fingerprint">No OTR Fingerprint generated. Just go ahead an start an encrypted conversation</string> <string name="no_otr_fingerprint">No OTR Fingerprint generated. Just go ahead an start an encrypted conversation</string>
<string name="start_conversation">Start Conversation</string> <string name="start_conversation">Start Conversation</string>
<string name="invite_contacts">Invite Contacts</string>
</resources> </resources>

View File

@ -1271,6 +1271,7 @@ public class XmppConnectionService extends Service {
invite.setAttribute("to", contact.getJid()); invite.setAttribute("to", contact.getJid());
x.addChild(invite); x.addChild(invite);
packet.addChild(x); packet.addChild(x);
Log.d(LOGTAG,packet.toString());
conversation.getAccount().getXmppConnection().sendMessagePacket(packet); conversation.getAccount().getXmppConnection().sendMessagePacket(packet);
} }

View File

@ -9,6 +9,7 @@ import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -20,6 +21,7 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
@ -35,6 +37,7 @@ public class MucDetailsActivity extends XmppActivity {
private TextView mFullJid; private TextView mFullJid;
private LinearLayout membersView; private LinearLayout membersView;
private LinearLayout mMoreDetails; private LinearLayout mMoreDetails;
private Button mInviteButton;
private String uuid = null; private String uuid = null;
private OnClickListener changeNickListener = new OnClickListener() { private OnClickListener changeNickListener = new OnClickListener() {
@ -62,6 +65,18 @@ public class MucDetailsActivity extends XmppActivity {
} }
}; };
private OnClickListener inviteListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),
NewConversationActivity.class);
intent.setAction("invite");
intent.putExtra("uuid",conversation.getUuid());
startActivity(intent);
}
};
private List<User> users = new ArrayList<MucOptions.User>(); private List<User> users = new ArrayList<MucOptions.User>();
@Override @Override
@ -81,6 +96,8 @@ public class MucDetailsActivity extends XmppActivity {
mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details); mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
mMoreDetails.setVisibility(View.GONE); mMoreDetails.setVisibility(View.GONE);
mSubject = (EditText) findViewById(R.id.muc_subject); mSubject = (EditText) findViewById(R.id.muc_subject);
mInviteButton = (Button) findViewById(R.id.invite);
mInviteButton.setOnClickListener(inviteListener);
getActionBar().setHomeButtonEnabled(true); getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);

View File

@ -38,7 +38,6 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ImageView; import android.widget.ImageView;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -59,6 +58,7 @@ public class NewConversationActivity extends XmppActivity {
private List<Contact> selectedContacts = new ArrayList<Contact>(); private List<Contact> selectedContacts = new ArrayList<Contact>();
private boolean isActionMode = false; private boolean isActionMode = false;
private boolean inviteIntent = false;
private ActionMode actionMode = null; private ActionMode actionMode = null;
private AbsListView.MultiChoiceModeListener actionModeCallback = new AbsListView.MultiChoiceModeListener() { private AbsListView.MultiChoiceModeListener actionModeCallback = new AbsListView.MultiChoiceModeListener() {
@ -67,9 +67,10 @@ public class NewConversationActivity extends XmppActivity {
menu.clear(); menu.clear();
MenuInflater inflater = mode.getMenuInflater(); MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.newconversation_context, menu); inflater.inflate(R.menu.newconversation_context, menu);
SparseBooleanArray checkedItems = contactsView.getCheckedItemPositions(); SparseBooleanArray checkedItems = contactsView
.getCheckedItemPositions();
selectedContacts.clear(); selectedContacts.clear();
for(int i = 0; i < aggregatedContacts.size(); ++i) { for (int i = 0; i < aggregatedContacts.size(); ++i) {
if (checkedItems.get(i, false)) { if (checkedItems.get(i, false)) {
selectedContacts.add(aggregatedContacts.get(i)); selectedContacts.add(aggregatedContacts.get(i));
} }
@ -77,12 +78,19 @@ public class NewConversationActivity extends XmppActivity {
if (selectedContacts.size() == 0) { if (selectedContacts.size() == 0) {
menu.findItem(R.id.action_start_conversation).setVisible(false); menu.findItem(R.id.action_start_conversation).setVisible(false);
menu.findItem(R.id.action_contact_details).setVisible(false); menu.findItem(R.id.action_contact_details).setVisible(false);
} else if (selectedContacts.size() == 1) { menu.findItem(R.id.action_invite).setVisible(false);
} else if ((selectedContacts.size() == 1)&&(!inviteIntent)) {
menu.findItem(R.id.action_start_conversation).setVisible(true); menu.findItem(R.id.action_start_conversation).setVisible(true);
menu.findItem(R.id.action_contact_details).setVisible(true); menu.findItem(R.id.action_contact_details).setVisible(true);
} else { menu.findItem(R.id.action_invite).setVisible(false);
} else if (!inviteIntent){
menu.findItem(R.id.action_start_conversation).setVisible(true); menu.findItem(R.id.action_start_conversation).setVisible(true);
menu.findItem(R.id.action_contact_details).setVisible(false); menu.findItem(R.id.action_contact_details).setVisible(false);
menu.findItem(R.id.action_invite).setVisible(false);
} else {
menu.findItem(R.id.action_invite).setVisible(true);
menu.findItem(R.id.action_start_conversation).setVisible(false);
menu.findItem(R.id.action_contact_details).setVisible(false);
} }
return true; return true;
} }
@ -109,11 +117,15 @@ public class NewConversationActivity extends XmppActivity {
} }
break; break;
case R.id.action_contact_details: case R.id.action_contact_details:
Intent intent = new Intent(getApplicationContext(),ContactDetailsActivity.class); Intent intent = new Intent(getApplicationContext(),
ContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
intent.putExtra("uuid", selectedContacts.get(0).getUuid()); intent.putExtra("uuid", selectedContacts.get(0).getUuid());
startActivity(intent); startActivity(intent);
break; break;
case R.id.action_invite:
invite();
break;
default: default:
break; break;
} }
@ -127,8 +139,25 @@ public class NewConversationActivity extends XmppActivity {
} }
}; };
private void invite() {
List<Conversation> conversations = xmppConnectionService
.getConversations();
Conversation conversation = null;
for (Conversation tmpConversation : conversations) {
if (tmpConversation.getUuid().equals(
getIntent().getStringExtra("uuid"))) {
conversation = tmpConversation;
break;
}
}
if (conversation != null) {
xmppConnectionService.inviteToConference(conversation, selectedContacts);
}
finish();
}
private void startConference() { private void startConference() {
if (accounts.size()>1) { if (accounts.size() > 1) {
getAccountChooser(new OnClickListener() { getAccountChooser(new OnClickListener() {
@Override @Override
@ -144,19 +173,21 @@ public class NewConversationActivity extends XmppActivity {
private void startConference(Account account, List<Contact> contacts) { private void startConference(Account account, List<Contact> contacts) {
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
String mucName = new BigInteger(100,random).toString(32); String mucName = new BigInteger(100, random).toString(32);
String serverName = account.getXmppConnection().getMucServer(); String serverName = account.getXmppConnection().getMucServer();
String jid = mucName+"@"+serverName; String jid = mucName + "@" + serverName;
Conversation conversation = xmppConnectionService.findOrCreateConversation(account, jid , true); Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, jid, true);
StringBuilder subject = new StringBuilder(); StringBuilder subject = new StringBuilder();
for(int i = 0; i < selectedContacts.size(); ++i) { for (int i = 0; i < selectedContacts.size(); ++i) {
if (i+1!=selectedContacts.size()) { if (i + 1 != selectedContacts.size()) {
subject.append(selectedContacts.get(i).getDisplayName()+", "); subject.append(selectedContacts.get(i).getDisplayName() + ", ");
} else { } else {
subject.append(selectedContacts.get(i).getDisplayName()); subject.append(selectedContacts.get(i).getDisplayName());
} }
} }
xmppConnectionService.sendConversationSubject(conversation, subject.toString()); xmppConnectionService.sendConversationSubject(conversation,
subject.toString());
xmppConnectionService.inviteToConference(conversation, contacts); xmppConnectionService.inviteToConference(conversation, contacts);
switchToConversation(conversation, null); switchToConversation(conversation, null);
} }
@ -205,13 +236,24 @@ public class NewConversationActivity extends XmppActivity {
int position, long arg3) { int position, long arg3) {
if (!isActionMode) { if (!isActionMode) {
contactsView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); contactsView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
contactsView.setItemChecked(position,true); contactsView.setItemChecked(position, true);
actionMode = contactsView.startActionMode(actionModeCallback); actionMode = contactsView.startActionMode(actionModeCallback);
} }
return true; return true;
} }
}; };
@Override
protected void onStart() {
super.onStart();
inviteIntent = "invite".equals(getIntent().getAction());
if (inviteIntent) {
contactsHeader.setVisibility(View.GONE);
actionMode = contactsView.startActionMode(actionModeCallback);
search.setVisibility(View.GONE);
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -263,7 +305,8 @@ public class NewConversationActivity extends XmppActivity {
contactJid.setText(contact.getJid()); contactJid.setText(contact.getJid());
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo); .findViewById(R.id.contact_photo);
imageView.setImageBitmap(UIHelper.getContactPicture(contact,null,90,this.getContext())); imageView.setImageBitmap(UIHelper.getContactPicture(contact,
null, 90, this.getContext()));
return view; return view;
} }
}; };
@ -287,7 +330,7 @@ public class NewConversationActivity extends XmppActivity {
} }
public void startConversation(final Contact contact) { public void startConversation(final Contact contact) {
if ((contact.getAccount()==null)&&(accounts.size()>1)) { if ((contact.getAccount() == null) && (accounts.size() > 1)) {
getAccountChooser(new OnClickListener() { getAccountChooser(new OnClickListener() {
@Override @Override
@ -297,7 +340,7 @@ public class NewConversationActivity extends XmppActivity {
} }
}).show(); }).show();
} else { } else {
if (contact.getAccount()==null) { if (contact.getAccount() == null) {
contact.setAccount(accounts.get(0)); contact.setAccount(accounts.get(0));
} }
showIsMucDialogIfNeeded(contact); showIsMucDialogIfNeeded(contact);
@ -310,8 +353,7 @@ public class NewConversationActivity extends XmppActivity {
accountList[i] = accounts.get(i).getJid(); accountList[i] = accounts.get(i).getJid();
} }
AlertDialog.Builder accountChooser = new AlertDialog.Builder( AlertDialog.Builder accountChooser = new AlertDialog.Builder(this);
this);
accountChooser.setTitle("Choose account"); accountChooser.setTitle("Choose account");
accountChooser.setItems(accountList, listener); accountChooser.setItems(accountList, listener);
return accountChooser.create(); return accountChooser.create();
@ -326,19 +368,22 @@ public class NewConversationActivity extends XmppActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
startConversation(clickedContact, clickedContact.getAccount(),true); startConversation(clickedContact,
clickedContact.getAccount(), true);
} }
}); });
dialog.setNegativeButton("No", new OnClickListener() { dialog.setNegativeButton("No", new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
startConversation(clickedContact, clickedContact.getAccount(),false); startConversation(clickedContact,
clickedContact.getAccount(), false);
} }
}); });
dialog.create().show(); dialog.create().show();
} else { } else {
startConversation(clickedContact, clickedContact.getAccount(),false); startConversation(clickedContact, clickedContact.getAccount(),
false);
} }
} }
@ -349,7 +394,7 @@ public class NewConversationActivity extends XmppActivity {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, contact.getJid(), muc); .findOrCreateConversation(account, contact.getJid(), muc);
switchToConversation(conversation,null); switchToConversation(conversation, null);
} }
@Override @Override
@ -360,38 +405,44 @@ public class NewConversationActivity extends XmppActivity {
getActionBar().setHomeButtonEnabled(false); getActionBar().setHomeButtonEnabled(false);
String jid; String jid;
try { try {
jid = URLDecoder.decode(getIntent().getData().getEncodedPath(),"UTF-8").split("/")[1]; jid = URLDecoder.decode(getIntent().getData().getEncodedPath(),
"UTF-8").split("/")[1];
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
jid = null; jid = null;
} }
if (jid!=null) { if (jid != null) {
final String finalJid = jid; final String finalJid = jid;
if (this.accounts.size() > 1) { if (this.accounts.size() > 1) {
getAccountChooser(new OnClickListener() { getAccountChooser(new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(accounts.get(which), finalJid, false); Conversation conversation = xmppConnectionService
switchToConversation(conversation,null); .findOrCreateConversation(
accounts.get(which), finalJid,
false);
switchToConversation(conversation, null);
finish(); finish();
} }
}).show(); }).show();
} else { } else {
Conversation conversation = xmppConnectionService.findOrCreateConversation(this.accounts.get(0), jid, false); Conversation conversation = xmppConnectionService
switchToConversation(conversation,null); .findOrCreateConversation(this.accounts.get(0),
jid, false);
switchToConversation(conversation, null);
finish(); finish();
} }
} }
} }
if (xmppConnectionService.getConversationCount() == 0) { if (xmppConnectionService.getConversationCount() == 0) {
getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setHomeButtonEnabled(false); getActionBar().setHomeButtonEnabled(false);
} }
this.rosterContacts.clear(); this.rosterContacts.clear();
for (int i = 0; i < accounts.size(); ++i) { for (int i = 0; i < accounts.size(); ++i) {
rosterContacts.addAll(xmppConnectionService.getRoster(accounts.get(i))); rosterContacts.addAll(xmppConnectionService.getRoster(accounts
.get(i)));
} }
updateAggregatedContacts(); updateAggregatedContacts();
} }
@ -462,6 +513,9 @@ public class NewConversationActivity extends XmppActivity {
@Override @Override
public void onActionModeFinished(ActionMode mode) { public void onActionModeFinished(ActionMode mode) {
super.onActionModeFinished(mode); super.onActionModeFinished(mode);
if (inviteIntent) {
finish();
} else {
this.isActionMode = false; this.isActionMode = false;
contactsView.clearChoices(); contactsView.clearChoices();
contactsView.requestLayout(); contactsView.requestLayout();
@ -473,5 +527,6 @@ public class NewConversationActivity extends XmppActivity {
}); });
search.setEnabled(true); search.setEnabled(true);
} }
}
} }