From 9260ed404750d7e718e12535030104ff4debda68 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 30 Jun 2014 20:39:15 +0200 Subject: inital activity --- src/eu/siacs/conversations/ui/StartConversation.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/eu/siacs/conversations/ui/StartConversation.java (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java new file mode 100644 index 00000000..f2dde78e --- /dev/null +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -0,0 +1,11 @@ +package eu.siacs.conversations.ui; + +public class StartConversation extends XmppActivity { + + @Override + void onBackendConnected() { + // TODO Auto-generated method stub + + } + +} -- cgit v1.2.3 From 502a1bdb9c3f6ddb8cdcf9be8c20862f4d55feaf Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 2 Jul 2014 16:13:25 +0200 Subject: changed support lib to v13. added tabs and fragments to start conversation activity --- .../conversations/ui/ConversationActivity.java | 2 +- .../siacs/conversations/ui/StartConversation.java | 80 ++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index c11e1d65..c29529ec 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -488,7 +488,7 @@ public class ConversationActivity extends XmppActivity { attachFilePopup.show(); break; case R.id.action_add: - startActivity(new Intent(this, ContactsActivity.class)); + startActivity(new Intent(this, StartConversation.class)); break; case R.id.action_archive: this.endConversation(getSelectedConversation()); diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index f2dde78e..9dccb411 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -1,7 +1,87 @@ package eu.siacs.conversations.ui; +import android.app.ActionBar; +import android.app.ActionBar.Tab; +import android.app.ActionBar.TabListener; +import android.app.Fragment; +import android.app.FragmentTransaction; +import android.app.ListFragment; +import android.os.Bundle; +import android.support.v13.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import eu.siacs.conversations.R; + public class StartConversation extends XmppActivity { + private Tab mContactsTab; + private Tab mConferencesTab; + private ViewPager mViewPager; + private ListFragment mContactsListFragment = new ListFragment(); + private ListFragment mConferenceListFragment = new ListFragment(); + + private TabListener mTabListener = new TabListener() { + + @Override + public void onTabUnselected(Tab tab, FragmentTransaction ft) { + // TODO Auto-generated method stub + + } + + @Override + public void onTabSelected(Tab tab, FragmentTransaction ft) { + mViewPager.setCurrentItem(tab.getPosition()); + } + + @Override + public void onTabReselected(Tab tab, FragmentTransaction ft) { + // TODO Auto-generated method stub + + } + }; + + private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + getActionBar().setSelectedNavigationItem(position); + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_start_conversation); + mViewPager = (ViewPager) findViewById(R.id.start_conversation_view_pager); + ActionBar actionBar = getActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + + mContactsTab = actionBar.newTab().setText(R.string.contacts) + .setTabListener(mTabListener); + mConferencesTab = actionBar.newTab().setText(R.string.conferences) + .setTabListener(mTabListener); + actionBar.addTab(mContactsTab); + actionBar.addTab(mConferencesTab); + + + mViewPager.setOnPageChangeListener(mOnPageChangeListener); + mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) { + + @Override + public int getCount() { + return 2; + } + + @Override + public Fragment getItem(int position) { + if (position==0) { + return mContactsListFragment; + } else { + return mConferenceListFragment; + } + } + }); + + } + @Override void onBackendConnected() { // TODO Auto-generated method stub -- cgit v1.2.3 From c1ee9e682a2f825e72260deb3f1c8579e21ed8de Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 4 Jul 2014 11:36:02 +0200 Subject: added action bar menu to start conversation --- .../siacs/conversations/ui/StartConversation.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 9dccb411..16161e36 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -9,6 +9,12 @@ import android.app.ListFragment; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.PopupMenu; +import android.widget.PopupMenu.OnMenuItemClickListener; import eu.siacs.conversations.R; public class StartConversation extends XmppActivity { @@ -81,6 +87,21 @@ public class StartConversation extends XmppActivity { }); } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.start_conversation, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + default: + break; + } + return super.onOptionsItemSelected(item); + } @Override void onBackendConnected() { -- cgit v1.2.3 From 7c3f3b2a3e878b1b1cfdcca102a38efe033dc6b7 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 4 Jul 2014 14:22:17 +0200 Subject: added group add button --- src/eu/siacs/conversations/ui/StartConversation.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 16161e36..ba603819 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -9,12 +9,8 @@ import android.app.ListFragment; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.widget.PopupMenu; -import android.widget.PopupMenu.OnMenuItemClickListener; import eu.siacs.conversations.R; public class StartConversation extends XmppActivity { @@ -36,6 +32,7 @@ public class StartConversation extends XmppActivity { @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); + invalidateOptionsMenu(); } @Override @@ -49,6 +46,7 @@ public class StartConversation extends XmppActivity { @Override public void onPageSelected(int position) { getActionBar().setSelectedNavigationItem(position); + invalidateOptionsMenu(); } }; @@ -91,6 +89,13 @@ public class StartConversation extends XmppActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.start_conversation, menu); + MenuItem menuCreateContact = (MenuItem) menu.findItem(R.id.action_create_contact); + MenuItem menuCreateConference = (MenuItem) menu.findItem(R.id.action_create_conference); + if (getActionBar().getSelectedNavigationIndex() == 0) { + menuCreateConference.setVisible(false); + } else { + menuCreateContact.setVisible(false); + } return true; } -- cgit v1.2.3 From 3bdf84b6a0170264a20795e7956a68421f312fa3 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 7 Jul 2014 09:32:10 +0200 Subject: filter contacts and starting confercenes --- .../siacs/conversations/ui/StartConversation.java | 171 +++++++++++++++++++-- 1 file changed, 156 insertions(+), 15 deletions(-) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index ba603819..3cf09a97 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -1,44 +1,71 @@ package eu.siacs.conversations.ui; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; import android.app.Fragment; import android.app.FragmentTransaction; import android.app.ListFragment; +import android.content.Context; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; +import android.view.MenuItem.OnActionExpandListener; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.SearchView; +import android.widget.SearchView.OnQueryTextListener; +import android.widget.TextView; 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.utils.UIHelper; public class StartConversation extends XmppActivity { private Tab mContactsTab; private Tab mConferencesTab; private ViewPager mViewPager; - private ListFragment mContactsListFragment = new ListFragment(); - private ListFragment mConferenceListFragment = new ListFragment(); + private SearchView mSearchView; + + private MyListFragment mContactsListFragment = new MyListFragment(); + private List contacts = new ArrayList(); + private ArrayAdapter mContactsAdapter; + + private MyListFragment mConferenceListFragment = new MyListFragment(); + private List conferences = new ArrayList(); + private ArrayAdapter mConferenceAdapter; private TabListener mTabListener = new TabListener() { @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { - // TODO Auto-generated method stub - + return; } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); - invalidateOptionsMenu(); + onTabChanged(); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { - // TODO Auto-generated method stub - + return; } }; @@ -46,7 +73,33 @@ public class StartConversation extends XmppActivity { @Override public void onPageSelected(int position) { getActionBar().setSelectedNavigationItem(position); + onTabChanged(); + } + }; + private OnQueryTextListener mOnQueryTextListener = new OnQueryTextListener() { + + @Override + public boolean onQueryTextSubmit(String query) { + return true; + } + + @Override + public boolean onQueryTextChange(String newText) { + filterContacts(newText); + return true; + } + }; + private OnActionExpandListener mOnSearchActionExpandListener = new OnActionExpandListener() { + + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return true; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { invalidateOptionsMenu(); + return true; } }; @@ -65,18 +118,17 @@ public class StartConversation extends XmppActivity { actionBar.addTab(mContactsTab); actionBar.addTab(mConferencesTab); - mViewPager.setOnPageChangeListener(mOnPageChangeListener); mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) { - + @Override public int getCount() { return 2; } - + @Override public Fragment getItem(int position) { - if (position==0) { + if (position == 0) { return mContactsListFragment; } else { return mConferenceListFragment; @@ -84,18 +136,44 @@ public class StartConversation extends XmppActivity { } }); + mConferenceAdapter = new ListItemAdapter(conferences); + mConferenceListFragment.setListAdapter(mConferenceAdapter); + + mContactsAdapter = new ListItemAdapter(contacts); + mContactsListFragment.setListAdapter(mContactsAdapter); + mContactsListFragment + .setOnListItemClickListener(new OnItemClickListener() { + + @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); + } + }); + } - + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.start_conversation, menu); - MenuItem menuCreateContact = (MenuItem) menu.findItem(R.id.action_create_contact); - MenuItem menuCreateConference = (MenuItem) menu.findItem(R.id.action_create_conference); + MenuItem menuCreateContact = (MenuItem) menu + .findItem(R.id.action_create_contact); + MenuItem menuCreateConference = (MenuItem) menu + .findItem(R.id.action_create_conference); + MenuItem menuSearch = (MenuItem) menu.findItem(R.id.action_search); if (getActionBar().getSelectedNavigationIndex() == 0) { menuCreateConference.setVisible(false); } else { menuCreateContact.setVisible(false); } + mSearchView = (SearchView) menuSearch.getActionView(); + mSearchView.setOnQueryTextListener(this.mOnQueryTextListener); + menuSearch + .setOnActionExpandListener(this.mOnSearchActionExpandListener); return true; } @@ -110,8 +188,71 @@ public class StartConversation extends XmppActivity { @Override void onBackendConnected() { - // TODO Auto-generated method stub + 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(); + } + + private void onTabChanged() { + if (mSearchView == null || mSearchView.isIconified()) { + 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(UIHelper.getContactPicture(item, 48, + this.getContext(), false)); + return view; + } + + } + + public static class MyListFragment extends ListFragment { + private AdapterView.OnItemClickListener mOnItemClickListener; + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + if (mOnItemClickListener != null) { + mOnItemClickListener.onItemClick(l, v, position, id); + } + } + + public void setOnListItemClickListener(AdapterView.OnItemClickListener l) { + this.mOnItemClickListener = l; + } } } -- cgit v1.2.3 From 203c85e11429c21d9c57e35b04692f2a6e61b10c Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 7 Jul 2014 14:23:13 +0200 Subject: made searchview text color white --- src/eu/siacs/conversations/ui/StartConversation.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 3cf09a97..ad129ea0 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -11,6 +11,7 @@ import android.app.Fragment; import android.app.FragmentTransaction; import android.app.ListFragment; import android.content.Context; +import android.graphics.Color; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; @@ -171,6 +172,9 @@ 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); + TextView textView = (TextView) mSearchView.findViewById(id); + textView.setTextColor(Color.WHITE); mSearchView.setOnQueryTextListener(this.mOnQueryTextListener); menuSearch .setOnActionExpandListener(this.mOnSearchActionExpandListener); -- cgit v1.2.3 From 2684ecda1ec085621d3b0b19f7ff7dd0c3193221 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 9 Jul 2014 23:13:23 +0200 Subject: small changes --- src/eu/siacs/conversations/ui/StartConversation.java | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index ad129ea0..664e50a8 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -18,7 +18,6 @@ import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; -import android.view.MenuItem.OnActionExpandListener; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -90,19 +89,6 @@ public class StartConversation extends XmppActivity { return true; } }; - private OnActionExpandListener mOnSearchActionExpandListener = new OnActionExpandListener() { - - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - invalidateOptionsMenu(); - return true; - } - }; @Override public void onCreate(Bundle savedInstanceState) { @@ -176,8 +162,6 @@ public class StartConversation extends XmppActivity { TextView textView = (TextView) mSearchView.findViewById(id); textView.setTextColor(Color.WHITE); mSearchView.setOnQueryTextListener(this.mOnQueryTextListener); - menuSearch - .setOnActionExpandListener(this.mOnSearchActionExpandListener); return true; } @@ -211,9 +195,7 @@ public class StartConversation extends XmppActivity { } private void onTabChanged() { - if (mSearchView == null || mSearchView.isIconified()) { - invalidateOptionsMenu(); - } + invalidateOptionsMenu(); } private class ListItemAdapter extends ArrayAdapter { -- cgit v1.2.3 From f8763015eb100568c69dfc89e8e25b4aa9b454e9 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 10 Jul 2014 01:55:19 +0200 Subject: added contextual menu for contacts --- .../conversations/ui/ConversationActivity.java | 7 +-- .../siacs/conversations/ui/StartConversation.java | 66 +++++++++++++++++++--- src/eu/siacs/conversations/ui/XmppActivity.java | 8 +++ 3 files changed, 68 insertions(+), 13 deletions(-) (limited to 'src/eu/siacs/conversations/ui') 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, -- cgit v1.2.3 From e97b5244552c8da06b3311bccb831be30c9a641a Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 10 Jul 2014 13:19:42 +0200 Subject: added create contact dialog --- .../siacs/conversations/ui/StartConversation.java | 65 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 45d61491..880b4a9b 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -7,10 +7,13 @@ import java.util.List; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; +import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentTransaction; import android.app.ListFragment; import android.content.Context; +import android.content.DialogInterface; +import android.database.DataSetObserver; import android.graphics.Color; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; @@ -26,10 +29,13 @@ import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.SearchView; +import android.widget.SpinnerAdapter; import android.widget.SearchView.OnQueryTextListener; +import android.widget.Spinner; import android.widget.TextView; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -37,6 +43,7 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.utils.Validator; public class StartConversation extends XmppActivity { @@ -52,6 +59,8 @@ public class StartConversation extends XmppActivity { private MyListFragment mConferenceListFragment = new MyListFragment(); private List conferences = new ArrayList(); private ArrayAdapter mConferenceAdapter; + + private List mActivatedAccounts = new ArrayList(); private TabListener mTabListener = new TabListener() { @@ -161,6 +170,53 @@ public class StartConversation extends XmppActivity { xmppConnectionService.deleteContactOnServer(contact); filterContacts(null); } + + protected void showCreateContactDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.create_contact); + View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null); + final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); + final EditText jid = (EditText) dialogView.findViewById(R.id.jid); + populateAccountSpinner(spinner); + builder.setView(dialogView); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.create, null); + final AlertDialog dialog = builder.create(); + dialog.show(); + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + if (Validator.isValidJid(jid.getText().toString())) { + String accountJid = (String) spinner.getSelectedItem(); + String contactJid = jid.getText().toString(); + Account account = xmppConnectionService.findAccountByJid(accountJid); + Contact contact = account.getRoster().getContact(contactJid); + if (contact.showInRoster()) { + jid.setError(getString(R.string.contact_already_exists)); + } else { + xmppConnectionService.createContact(contact); + switchToConversation(contact); + dialog.dismiss(); + } + } else { + jid.setError(getString(R.string.invalid_jid)); + } + } + }); + + } + + protected void switchToConversation(Contact contact) { + Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false); + switchToConversation(conversation, null, false); + } + + private void populateAccountSpinner(Spinner spinner) { + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, mActivatedAccounts); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -187,7 +243,8 @@ public class StartConversation extends XmppActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - default: + case R.id.action_create_contact: + showCreateContactDialog(); break; } return super.onOptionsItemSelected(item); @@ -196,6 +253,12 @@ public class StartConversation extends XmppActivity { @Override void onBackendConnected() { filterContacts(null); + this.mActivatedAccounts.clear(); + for (Account account : xmppConnectionService.getAccounts()) { + if (account.getStatus() != Account.STATUS_DISABLED) { + this.mActivatedAccounts.add(account.getJid()); + } + } } protected void filterContacts(String needle) { -- cgit v1.2.3