diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-07-10 01:55:19 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-07-10 01:55:19 +0200 |
commit | f8763015eb100568c69dfc89e8e25b4aa9b454e9 (patch) | |
tree | 19a0c134fd35b73c1ca1cab44e5a3107940021a7 | |
parent | 2684ecda1ec085621d3b0b19f7ff7dd0c3193221 (diff) |
added contextual menu for contacts
Diffstat (limited to '')
-rw-r--r-- | res/menu/contact_context.xml | 14 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/eu/siacs/conversations/services/XmppConnectionService.java | 3 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 7 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/StartConversation.java | 66 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/XmppActivity.java | 8 |
6 files changed, 85 insertions, 15 deletions
diff --git a/res/menu/contact_context.xml b/res/menu/contact_context.xml new file mode 100644 index 00000000..11ac7d7c --- /dev/null +++ b/res/menu/contact_context.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" > + + <item + android:id="@+id/context_start_conversation" + android:title="@string/start_conversation"/> + <item + android:id="@+id/context_contact_details" + android:title="@string/view_contact_details"/> + <item + android:id="@+id/context_delete_contact" + android:title="@string/delete_contact"/> + +</menu>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index a2d04e96..8d66125e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -259,4 +259,6 @@ <string name="search">Search</string> <string name="create_contact">Create Contact</string> <string name="create_conference">Create Conference</string> + <string name="delete_contact">Delete Contact</string> + <string name="view_contact_details">View contact details</string> </resources>
\ No newline at end of file diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 3db52753..9993dd67 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1282,6 +1282,7 @@ public class XmppConnectionService extends Service { public void deleteContactOnServer(Contact contact) { contact.resetOption(Contact.Options.DIRTY_PUSH); + contact.setOption(Contact.Options.DIRTY_DELETE); Account account = contact.getAccount(); if (account.getStatus() == Account.STATUS_ONLINE) { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); @@ -1290,8 +1291,6 @@ public class XmppConnectionService extends Service { item.setAttribute("subscription", "remove"); account.getXmppConnection().sendIqPacket(iq, null); contact.resetOption(Contact.Options.DIRTY_DELETE); - } else { - contact.setOption(Contact.Options.DIRTY_DELETE); } } diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index c29529ec..1f3ab2fb 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -496,12 +496,7 @@ public class ConversationActivity extends XmppActivity { case R.id.action_contact_details: Contact contact = this.getSelectedConversation().getContact(); if (contact.showInRoster()) { - Intent intent = new Intent(this, ContactDetailsActivity.class); - intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); - intent.putExtra("account", this.getSelectedConversation() - .getAccount().getJid()); - intent.putExtra("contact", contact.getJid()); - startActivity(intent); + switchToContactDetails(contact); } else { showAddToRosterDialog(getSelectedConversation()); } diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 664e50a8..45d61491 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -15,12 +15,15 @@ import android.graphics.Color; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; +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.widget.AdapterView; +import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; @@ -134,16 +137,31 @@ public class StartConversation extends XmppActivity { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { - Contact contact = (Contact) contacts.get(position); - Conversation conversation = xmppConnectionService - .findOrCreateConversation(contact.getAccount(), - contact.getJid(), false); - switchToConversation(conversation, null, false); + openConversationForContact(position); } }); } + protected void openConversationForContact(int position) { + Contact contact = (Contact) contacts.get(position); + Conversation conversation = xmppConnectionService + .findOrCreateConversation(contact.getAccount(), + contact.getJid(), false); + switchToConversation(conversation, null, false); + } + + protected void openDetailsForContact(int position) { + Contact contact = (Contact) contacts.get(position); + switchToContactDetails(contact); + } + + protected void deleteContact(int position) { + Contact contact = (Contact) contacts.get(position); + xmppConnectionService.deleteContactOnServer(contact); + filterContacts(null); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.start_conversation, menu); @@ -158,7 +176,8 @@ public class StartConversation extends XmppActivity { menuCreateContact.setVisible(false); } mSearchView = (SearchView) menuSearch.getActionView(); - int id = mSearchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); + int id = mSearchView.getContext().getResources() + .getIdentifier("android:id/search_src_text", null, null); TextView textView = (TextView) mSearchView.findViewById(id); textView.setTextColor(Color.WHITE); mSearchView.setOnQueryTextListener(this.mOnQueryTextListener); @@ -228,6 +247,7 @@ public class StartConversation extends XmppActivity { public static class MyListFragment extends ListFragment { private AdapterView.OnItemClickListener mOnItemClickListener; + private int mContextPosition = -1; @Override public void onListItemClick(ListView l, View v, int position, long id) { @@ -239,6 +259,38 @@ public class StartConversation extends XmppActivity { public void setOnListItemClickListener(AdapterView.OnItemClickListener l) { this.mOnItemClickListener = l; } - } + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + registerForContextMenu(getListView()); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + getActivity().getMenuInflater().inflate(R.menu.contact_context, + menu); + AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo; + this.mContextPosition = acmi.position; + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + StartConversation activity = (StartConversation) getActivity(); + switch(item.getItemId()) { + case R.id.context_start_conversation: + activity.openConversationForContact(mContextPosition); + break; + case R.id.context_contact_details: + activity.openDetailsForContact(mContextPosition); + break; + case R.id.context_delete_contact: + activity.deleteContact(mContextPosition); + break; + } + return true; + } + } } diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index c95cbfec..96278a6d 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -170,6 +170,14 @@ public abstract class XmppActivity extends Activity { } startActivity(viewConversationIntent); } + + public void switchToContactDetails(Contact contact) { + Intent intent = new Intent(this, ContactDetailsActivity.class); + intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); + intent.putExtra("account", contact.getAccount().getJid()); + intent.putExtra("contact", contact.getJid()); + startActivity(intent); + } protected void announcePgp(Account account, final Conversation conversation) { xmppConnectionService.getPgpEngine().generateSignature(account, |