From 38a9242955704232039272fd8b6011d47622495d Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 17 Jul 2014 00:03:37 +0200 Subject: [PATCH] brought muc invites back. + couple of bug fixes + refactoring --- AndroidManifest.xml | 9 +- res/layout/activity_choose_contact.xml | 13 ++ res/layout/activity_muc_details.xml | 4 +- res/menu/choose_contact.xml | 10 ++ res/menu/conversations.xml | 37 ++--- res/values/strings.xml | 6 +- .../conversations/parser/MessageParser.java | 7 +- .../services/XmppConnectionService.java | 36 +++-- .../ui/ChooseContactActivity.java | 140 ++++++++++++++++++ ...ty.java => ConferenceDetailsActivity.java} | 19 +-- .../ui/ContactDetailsActivity.java | 12 -- .../ui/ConversationActivity.java | 31 ++-- .../ui/ConversationFragment.java | 6 +- ...ditAccount.java => EditAccountDialog.java} | 4 +- .../ui/ManageAccountActivity.java | 10 +- .../conversations/ui/OnPresenceSelected.java | 5 - ...on.java => StartConversationActivity.java} | 44 +----- .../siacs/conversations/ui/XmppActivity.java | 26 ++++ .../adapter}/KnownHostsAdapter.java | 4 +- .../ui/adapter/ListItemAdapter.java | 39 +++++ .../siacs/conversations/utils/UIHelper.java | 1 - 21 files changed, 318 insertions(+), 145 deletions(-) create mode 100644 res/layout/activity_choose_contact.xml create mode 100644 res/menu/choose_contact.xml create mode 100644 src/eu/siacs/conversations/ui/ChooseContactActivity.java rename src/eu/siacs/conversations/ui/{MucDetailsActivity.java => ConferenceDetailsActivity.java} (93%) rename src/eu/siacs/conversations/ui/{EditAccount.java => EditAccountDialog.java} (97%) delete mode 100644 src/eu/siacs/conversations/ui/OnPresenceSelected.java rename src/eu/siacs/conversations/ui/{StartConversation.java => StartConversationActivity.java} (92%) rename src/eu/siacs/conversations/{utils => ui/adapter}/KnownHostsAdapter.java (93%) create mode 100644 src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a7bfbbe49..c04bb82b0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -49,11 +49,11 @@ + android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" > @@ -68,6 +68,9 @@ android:label="@string/title_activity_settings" android:parentActivityName="eu.siacs.conversations.ui.ConversationActivity" > + + diff --git a/res/layout/activity_choose_contact.xml b/res/layout/activity_choose_contact.xml new file mode 100644 index 000000000..248a7822c --- /dev/null +++ b/res/layout/activity_choose_contact.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/res/layout/activity_muc_details.xml b/res/layout/activity_muc_details.xml index d47c6b6ef..49b4cef3a 100644 --- a/res/layout/activity_muc_details.xml +++ b/res/layout/activity_muc_details.xml @@ -63,7 +63,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" - android:text="hallo hallo" android:textColor="@color/primarytext" android:textSize="18sp" /> @@ -72,7 +71,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" - android:text="Participant" android:textColor="@color/primarytext" android:textSize="14sp" /> @@ -123,7 +121,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="24dp" - android:text="@string/invite_contacts" /> + android:text="@string/invite_contact" /> \ No newline at end of file diff --git a/res/menu/choose_contact.xml b/res/menu/choose_contact.xml new file mode 100644 index 000000000..3f402664a --- /dev/null +++ b/res/menu/choose_contact.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/res/menu/conversations.xml b/res/menu/conversations.xml index 710a552e4..2621289a5 100644 --- a/res/menu/conversations.xml +++ b/res/menu/conversations.xml @@ -2,47 +2,44 @@ - + android:title="@string/action_add"/> - + android:title="@string/action_secure"/> - + android:title="@string/attach_file"/> - + - + - + android:title="@string/invite_contact"/> - - + android:title="@string/action_accounts"/> - + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 26e5dda5a..8cfff3684 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -47,10 +47,7 @@ OTR fingerprint No OTR Fingerprint generated. Just go ahead an start an encrypted conversation Start Conversation - Invite Contacts - Invite to existing conference - Create new conference - Create new contact + Invite Contact Contacts Search or enter Jabber ID Choose account @@ -272,4 +269,5 @@ This bookmark already exists You Edit conference subject + Choose contact diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 6c43a4d7d..728faf4b7 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -220,10 +220,13 @@ public class MessageParser extends AbstractParser implements } else if (packet.hasChild("x")) { Element x = packet.findChild("x"); if (x.hasChild("invite")) { - mXmppConnectionService + Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, packet.getAttribute("from"), true); - mXmppConnectionService.updateConversationUi(); + if (!conversation.getMucOptions().online()) { + mXmppConnectionService.joinMuc(conversation); + mXmppConnectionService.updateConversationUi(); + } } } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index abcb1f975..dd4363f44 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1189,21 +1189,18 @@ public class XmppConnectionService extends Service { }).start(); } - public void inviteToConference(Conversation conversation, - List contacts) { - for (Contact contact : contacts) { - MessagePacket packet = new MessagePacket(); - packet.setTo(conversation.getContactJid().split("/")[0]); - packet.setFrom(conversation.getAccount().getFullJid()); - Element x = new Element("x"); - x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user"); - Element invite = new Element("invite"); - invite.setAttribute("to", contact.getJid()); - x.addChild(invite); - packet.addChild(x); - Log.d(LOGTAG, packet.toString()); - sendMessagePacket(conversation.getAccount(),packet); - } + public void inviteToConference(Conversation conversation, String contactJid) { + Account account = conversation.getAccount(); + MessagePacket packet = new MessagePacket(); + packet.setTo(conversation.getContactJid().split("/")[0]); + packet.setFrom(account.getFullJid()); + Element x = new Element("x"); + x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user"); + Element invite = new Element("invite"); + invite.setAttribute("to", contactJid); + x.addChild(invite); + packet.addChild(x); + sendMessagePacket(account,packet); } @@ -1273,6 +1270,15 @@ public class XmppConnectionService extends Service { } return null; } + + public Conversation findConversationByUuid(String uuid) { + for (Conversation conversation : getConversations()) { + if (conversation.getUuid().equals(uuid)) { + return conversation; + } + } + return null; + } public void markRead(Conversation conversation) { conversation.markRead(); diff --git a/src/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/eu/siacs/conversations/ui/ChooseContactActivity.java new file mode 100644 index 000000000..4236ea703 --- /dev/null +++ b/src/eu/siacs/conversations/ui/ChooseContactActivity.java @@ -0,0 +1,140 @@ +package eu.siacs.conversations.ui; + +import java.util.ArrayList; +import java.util.Collections; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListView; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.ListItem; +import eu.siacs.conversations.ui.adapter.ListItemAdapter; + +public class ChooseContactActivity extends XmppActivity { + + private ListView mListView; + private ArrayList contacts = new ArrayList(); + private ArrayAdapter mContactsAdapter; + + private EditText mSearchEditText; + + private TextWatcher mSearchTextWatcher = new TextWatcher() { + + @Override + public void afterTextChanged(Editable editable) { + filterContacts(editable.toString()); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, + int count) { + } + }; + + private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() { + + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + mSearchEditText.post(new Runnable() { + + @Override + public void run() { + mSearchEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mSearchEditText, + InputMethodManager.SHOW_IMPLICIT); + } + }); + + return true; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), + InputMethodManager.HIDE_IMPLICIT_ONLY); + mSearchEditText.setText(""); + filterContacts(null); + return true; + } + }; + + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_choose_contact); + mListView = (ListView) findViewById(R.id.choose_contact_list); + mContactsAdapter = new ListItemAdapter(getApplicationContext(), contacts); + mListView.setAdapter(mContactsAdapter); + mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView arg0, View arg1, int position, + long arg3) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), + InputMethodManager.HIDE_IMPLICIT_ONLY); + Intent request = getIntent(); + Intent data = new Intent(); + data.putExtra("contact",contacts.get(position).getJid()); + data.putExtra("account",request.getStringExtra("account")); + data.putExtra("conversation",request.getStringExtra("conversation")); + setResult(RESULT_OK, data); + finish(); + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.choose_contact, menu); + MenuItem menuSearchView = (MenuItem) menu.findItem(R.id.action_search); + View mSearchView = menuSearchView.getActionView(); + mSearchEditText = (EditText) mSearchView + .findViewById(R.id.search_field); + mSearchEditText.addTextChangedListener(mSearchTextWatcher); + menuSearchView.setOnActionExpandListener(mOnActionExpandListener); + return true; + } + + @Override + void onBackendConnected() { + filterContacts(null); + } + + protected void filterContacts(String needle) { + this.contacts.clear(); + for (Account account : xmppConnectionService.getAccounts()) { + if (account.getStatus() != Account.STATUS_DISABLED) { + for (Contact contact : account.getRoster().getContacts()) { + if (contact.showInRoster() && contact.match(needle)) { + this.contacts.add(contact); + } + } + } + } + Collections.sort(this.contacts); + mContactsAdapter.notifyDataSetChanged(); + } + +} diff --git a/src/eu/siacs/conversations/ui/MucDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java similarity index 93% rename from src/eu/siacs/conversations/ui/MucDetailsActivity.java rename to src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 65f70a6dc..56903da89 100644 --- a/src/eu/siacs/conversations/ui/MucDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -31,7 +31,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; -public class MucDetailsActivity extends XmppActivity { +public class ConferenceDetailsActivity extends XmppActivity { public static final String ACTION_VIEW_MUC = "view_muc"; private Conversation conversation; private TextView mYourNick; @@ -48,12 +48,7 @@ public class MucDetailsActivity extends XmppActivity { @Override public void onClick(View v) { - /* - * Intent intent = new Intent(getApplicationContext(), - * ContactsActivity.class); intent.setAction("invite"); - * intent.putExtra("uuid",conversation.getUuid()); - * startActivity(intent); - */ + inviteToConversation(conversation); } }; @@ -155,11 +150,7 @@ public class MucDetailsActivity extends XmppActivity { this.uuid = getIntent().getExtras().getString("uuid"); } if (uuid != null) { - for (Conversation mConv : xmppConnectionService.getConversations()) { - if (mConv.getUuid().equals(uuid)) { - this.conversation = mConv; - } - } + this.conversation = xmppConnectionService.findConversationByUuid(uuid); if (this.conversation != null) { populateView(); } @@ -188,11 +179,11 @@ public class MucDetailsActivity extends XmppActivity { public void run() { populateView(); if (success) { - Toast.makeText(MucDetailsActivity.this, + Toast.makeText(ConferenceDetailsActivity.this, getString(R.string.your_nick_has_been_changed), Toast.LENGTH_SHORT).show(); } else { - Toast.makeText(MucDetailsActivity.this, + Toast.makeText(ConferenceDetailsActivity.this, getString(R.string.nick_in_use), Toast.LENGTH_SHORT).show(); } diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java index 3413353d3..a8527febd 100644 --- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -21,7 +21,6 @@ import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.QuickContactBadge; import android.widget.TextView; @@ -45,7 +44,6 @@ public class ContactDetailsActivity extends XmppActivity { private String accountJid; private String contactJid; - private EditText name; private TextView contactJidTv; private TextView accountJidTv; private TextView status; @@ -63,16 +61,6 @@ public class ContactDetailsActivity extends XmppActivity { } }; - private DialogInterface.OnClickListener editContactNameListener = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - contact.setServerName(name.getText().toString()); - activity.xmppConnectionService.pushContactToServer(contact); - populateView(); - } - }; - private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() { @Override diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 66db353be..ae1d218ae 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -98,7 +98,7 @@ public class ConversationActivity extends XmppActivity { swapConversationFragment(); } else { startActivity(new Intent(getApplicationContext(), - StartConversation.class)); + StartConversationActivity.class)); finish(); } } @@ -306,23 +306,26 @@ public class ConversationActivity extends XmppActivity { .findItem(R.id.action_muc_details); MenuItem menuContactDetails = (MenuItem) menu .findItem(R.id.action_contact_details); - MenuItem menuInviteContacts = (MenuItem) menu - .findItem(R.id.action_invite); MenuItem menuAttach = (MenuItem) menu.findItem(R.id.action_attach_file); MenuItem menuClearHistory = (MenuItem) menu .findItem(R.id.action_clear_history); + MenuItem menuManageAccounts = (MenuItem) menu.findItem(R.id.action_accounts); + MenuItem menuSettings = (MenuItem) menu.findItem(R.id.action_settings); + MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add); + MenuItem menuInviteContact = (MenuItem) menu.findItem(R.id.action_invite); if ((spl.isOpen() && (spl.isSlideable()))) { menuArchive.setVisible(false); menuMucDetails.setVisible(false); menuContactDetails.setVisible(false); menuSecure.setVisible(false); - menuInviteContacts.setVisible(false); + menuInviteContact.setVisible(false); menuAttach.setVisible(false); menuClearHistory.setVisible(false); } else { - ((MenuItem) menu.findItem(R.id.action_add)).setVisible(!spl - .isSlideable()); + menuAdd.setVisible(!spl.isSlideable()); + menuSettings.setVisible(!spl.isSlideable()); + menuManageAccounts.setVisible(!spl.isSlideable()); if (this.getSelectedConversation() != null) { if (this.getSelectedConversation().getLatestMessage() .getEncryption() != Message.ENCRYPTION_NONE) { @@ -333,7 +336,7 @@ public class ConversationActivity extends XmppActivity { menuAttach.setVisible(false); } else { menuMucDetails.setVisible(false); - menuInviteContacts.setVisible(false); + menuInviteContact.setVisible(false); } } } @@ -458,7 +461,7 @@ public class ConversationActivity extends XmppActivity { attachFilePopup.show(); break; case R.id.action_add: - startActivity(new Intent(this, StartConversation.class)); + startActivity(new Intent(this, StartConversationActivity.class)); break; case R.id.action_archive: this.endConversation(getSelectedConversation()); @@ -472,17 +475,13 @@ public class ConversationActivity extends XmppActivity { } break; case R.id.action_muc_details: - Intent intent = new Intent(this, MucDetailsActivity.class); - intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); + Intent intent = new Intent(this, ConferenceDetailsActivity.class); + intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC); intent.putExtra("uuid", getSelectedConversation().getUuid()); startActivity(intent); break; case R.id.action_invite: - /*Intent inviteIntent = new Intent(getApplicationContext(), - ContactsActivity.class); - inviteIntent.setAction("invite"); - inviteIntent.putExtra("uuid", getSelectedConversation().getUuid()); - startActivity(inviteIntent);*/ + inviteToConversation(getSelectedConversation()); break; case R.id.action_security: final Conversation conversation = getSelectedConversation(); @@ -699,7 +698,7 @@ public class ConversationActivity extends XmppActivity { finish(); } else if (conversationList.size() <= 0) { // add no history - startActivity(new Intent(this, StartConversation.class)); + startActivity(new Intent(this, StartConversationActivity.class)); finish(); } else { spl.openPane(); diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 47c764ac7..206e40a09 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -12,9 +12,9 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; -import eu.siacs.conversations.entities.MucOptions.OnRenameListener; import eu.siacs.conversations.services.ImageProvider; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.jingle.JingleConnection; import android.app.AlertDialog; @@ -118,8 +118,8 @@ public class ConversationFragment extends Fragment { @Override public void onClick(View v) { - Intent intent = new Intent(getActivity(), MucDetailsActivity.class); - intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); + Intent intent = new Intent(getActivity(), ConferenceDetailsActivity.class); + intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC); intent.putExtra("uuid", conversation.getUuid()); startActivity(intent); } diff --git a/src/eu/siacs/conversations/ui/EditAccount.java b/src/eu/siacs/conversations/ui/EditAccountDialog.java similarity index 97% rename from src/eu/siacs/conversations/ui/EditAccount.java rename to src/eu/siacs/conversations/ui/EditAccountDialog.java index 9a0b8d842..7c135fc16 100644 --- a/src/eu/siacs/conversations/ui/EditAccount.java +++ b/src/eu/siacs/conversations/ui/EditAccountDialog.java @@ -4,7 +4,7 @@ import java.util.List; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.utils.KnownHostsAdapter; +import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.utils.Validator; import android.app.AlertDialog; import android.app.Dialog; @@ -21,7 +21,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import android.widget.TextView; -public class EditAccount extends DialogFragment { +public class EditAccountDialog extends DialogFragment { protected Account account; diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index c3f1e105d..6fa1ec319 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -6,7 +6,7 @@ import java.util.List; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; -import eu.siacs.conversations.ui.EditAccount.EditAccountListener; +import eu.siacs.conversations.ui.EditAccountDialog.EditAccountListener; import eu.siacs.conversations.xmpp.OnTLSExceptionReceived; import eu.siacs.conversations.xmpp.XmppConnection; import android.app.Activity; @@ -221,7 +221,7 @@ public class ManageAccountActivity extends XmppActivity { } else if (account.getStatus() == Account.STATUS_ONLINE) { activity.startActivity(new Intent(activity .getApplicationContext(), - StartConversation.class)); + StartConversationActivity.class)); } else if (account.getStatus() != Account.STATUS_DISABLED) { editAccount(account); } @@ -513,7 +513,7 @@ public class ManageAccountActivity extends XmppActivity { @Override public boolean onNavigateUp() { if (xmppConnectionService.getConversations().size() == 0) { - Intent contactsIntent = new Intent(this, StartConversation.class); + Intent contactsIntent = new Intent(this, StartConversationActivity.class); contactsIntent.setFlags( // if activity exists in stack, pop the stack and go back to it Intent.FLAG_ACTIVITY_CLEAR_TOP | @@ -531,7 +531,7 @@ public class ManageAccountActivity extends XmppActivity { } private void editAccount(Account account) { - EditAccount dialog = new EditAccount(); + EditAccountDialog dialog = new EditAccountDialog(); dialog.setAccount(account); dialog.setEditAccountListener(new EditAccountListener() { @@ -550,7 +550,7 @@ public class ManageAccountActivity extends XmppActivity { protected void addAccount() { final Activity activity = this; - EditAccount dialog = new EditAccount(); + EditAccountDialog dialog = new EditAccountDialog(); dialog.setEditAccountListener(new EditAccountListener() { @Override diff --git a/src/eu/siacs/conversations/ui/OnPresenceSelected.java b/src/eu/siacs/conversations/ui/OnPresenceSelected.java deleted file mode 100644 index 1c967224a..000000000 --- a/src/eu/siacs/conversations/ui/OnPresenceSelected.java +++ /dev/null @@ -1,5 +0,0 @@ -package eu.siacs.conversations.ui; - -public interface OnPresenceSelected { - public void onPresenceSelected(); -} diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversationActivity.java similarity index 92% rename from src/eu/siacs/conversations/ui/StartConversation.java rename to src/eu/siacs/conversations/ui/StartConversationActivity.java index f23eb4202..5e22b65f1 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversationActivity.java @@ -21,11 +21,9 @@ import android.text.Editable; import android.text.TextWatcher; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; @@ -34,20 +32,19 @@ import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.ImageView; import android.widget.ListView; import android.widget.Spinner; -import android.widget.TextView; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.ListItem; -import eu.siacs.conversations.utils.KnownHostsAdapter; +import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; +import eu.siacs.conversations.ui.adapter.ListItemAdapter; import eu.siacs.conversations.utils.Validator; -public class StartConversation extends XmppActivity { +public class StartConversationActivity extends XmppActivity { private Tab mContactsTab; private Tab mConferencesTab; @@ -176,7 +173,7 @@ public class StartConversation extends XmppActivity { } }); - mConferenceAdapter = new ListItemAdapter(conferences); + mConferenceAdapter = new ListItemAdapter(getApplicationContext(),conferences); mConferenceListFragment.setListAdapter(mConferenceAdapter); mConferenceListFragment.setContextMenu(R.menu.conference_context); mConferenceListFragment @@ -189,7 +186,7 @@ public class StartConversation extends XmppActivity { } }); - mContactsAdapter = new ListItemAdapter(contacts); + mContactsAdapter = new ListItemAdapter(getApplicationContext(),contacts); mContactsListFragment.setListAdapter(mContactsAdapter); mContactsListFragment.setContextMenu(R.menu.contact_context); mContactsListFragment @@ -502,33 +499,6 @@ public class StartConversation extends XmppActivity { invalidateOptionsMenu(); } - private class ListItemAdapter extends ArrayAdapter { - - public ListItemAdapter(List objects) { - super(getApplicationContext(), 0, objects); - } - - @Override - public View getView(int position, View view, ViewGroup parent) { - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); - ListItem item = getItem(position); - if (view == null) { - view = (View) inflater.inflate(R.layout.contact, null); - } - TextView name = (TextView) view - .findViewById(R.id.contact_display_name); - TextView jid = (TextView) view.findViewById(R.id.contact_jid); - ImageView picture = (ImageView) view - .findViewById(R.id.contact_photo); - - jid.setText(item.getJid()); - name.setText(item.getDisplayName()); - picture.setImageBitmap(item.getImage(48, getApplicationContext())); - return view; - } - - } - public static class MyListFragment extends ListFragment { private AdapterView.OnItemClickListener mOnItemClickListener; private int mResContextMenu; @@ -558,7 +528,7 @@ public class StartConversation extends XmppActivity { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - StartConversation activity = (StartConversation) getActivity(); + StartConversationActivity activity = (StartConversationActivity) getActivity(); activity.getMenuInflater().inflate(mResContextMenu, menu); AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo; if (mResContextMenu == R.menu.conference_context) { @@ -570,7 +540,7 @@ public class StartConversation extends XmppActivity { @Override public boolean onContextItemSelected(MenuItem item) { - StartConversation activity = (StartConversation) getActivity(); + StartConversationActivity activity = (StartConversationActivity) getActivity(); switch (item.getItemId()) { case R.id.context_start_conversation: activity.openConversationForContact(); diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 2592bebca..2bf7cf5a1 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -23,6 +23,7 @@ import android.content.ServiceConnection; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; +import android.util.Log; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -31,6 +32,7 @@ import android.widget.EditText; public abstract class XmppActivity extends Activity { public static final int REQUEST_ANNOUNCE_PGP = 0x73731; + protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x341830; protected final static String LOGTAG = "xmppService"; @@ -41,6 +43,10 @@ public abstract class XmppActivity extends Activity { protected interface OnValueEdited { public void onValueEdited(String value); } + + public interface OnPresenceSelected { + public void onPresenceSelected(); + } protected ServiceConnection mConnection = new ServiceConnection() { @@ -187,6 +193,12 @@ public abstract class XmppActivity extends Activity { startActivity(intent); } + protected void inviteToConversation(Conversation conversation) { + Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class); + intent.putExtra("conversation",conversation.getUuid()); + startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION); + } + protected void announcePgp(Account account, final Conversation conversation) { xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback() { @@ -328,4 +340,18 @@ public abstract class XmppActivity extends Activity { } } } + + protected void onActivityResult(int requestCode, int resultCode, + final Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_INVITE_TO_CONVERSATION && resultCode == RESULT_OK) { + String contactJid = data.getStringExtra("contact"); + String conversationUuid = data.getStringExtra("conversation"); + Conversation conversation = xmppConnectionService.findConversationByUuid(conversationUuid); + if (conversation.getMode() == Conversation.MODE_MULTI) { + xmppConnectionService.inviteToConference(conversation, contactJid); + } + Log.d("xmppService","inviting "+contactJid+" to "+conversation.getName(true)); + } + } } diff --git a/src/eu/siacs/conversations/utils/KnownHostsAdapter.java b/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java similarity index 93% rename from src/eu/siacs/conversations/utils/KnownHostsAdapter.java rename to src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java index a0a223dda..040e62667 100644 --- a/src/eu/siacs/conversations/utils/KnownHostsAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java @@ -1,4 +1,4 @@ -package eu.siacs.conversations.utils; +package eu.siacs.conversations.ui.adapter; import java.util.ArrayList; import java.util.List; @@ -42,7 +42,7 @@ public class KnownHostsAdapter extends ArrayAdapter { @Override protected void publishResults(CharSequence constraint, FilterResults results) { - ArrayList filteredList = ((ArrayList) results.values); + ArrayList filteredList = (ArrayList) results.values; if (results != null && results.count > 0) { clear(); for (String c : filteredList) { diff --git a/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java new file mode 100644 index 000000000..9ef427fc5 --- /dev/null +++ b/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -0,0 +1,39 @@ +package eu.siacs.conversations.ui.adapter; + +import java.util.List; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.ListItem; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +public class ListItemAdapter extends ArrayAdapter { + + public ListItemAdapter(Context context, List objects) { + super(context, 0, objects); + } + + @Override + public View getView(int position, View view, ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + ListItem item = getItem(position); + if (view == null) { + view = (View) inflater.inflate(R.layout.contact, null); + } + TextView name = (TextView) view.findViewById(R.id.contact_display_name); + TextView jid = (TextView) view.findViewById(R.id.contact_jid); + ImageView picture = (ImageView) view.findViewById(R.id.contact_photo); + + jid.setText(item.getJid()); + name.setText(item.getDisplayName()); + picture.setImageBitmap(item.getImage(48, getContext())); + return view; + } + +} \ No newline at end of file diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index 4e902817d..1cd3403c6 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -13,7 +13,6 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.ui.ConversationActivity;