diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-07 02:57:36 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-07 02:57:36 +0100 |
commit | cda1c2c3a12b4c18f13771dd4b58aab6e465176b (patch) | |
tree | 9f246adce16c0951f64f4233c4c0ad8d00d7c8e1 /src/de/gultsch/chat/ui | |
parent | aa42eb544a1ebf99dc52d71c917b899d1fce628d (diff) |
refresh contact list
Diffstat (limited to '')
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationActivity.java | 35 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationFragment.java | 4 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/NewConversationActivity.java | 67 |
3 files changed, 77 insertions, 29 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index d9c497f8..7e4cd34d 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -40,7 +40,7 @@ public class ConversationActivity extends XmppActivity { protected SlidingPaneLayout spl; private List<Conversation> conversationList = new ArrayList<Conversation>(); - private int selectedConversation = 0; + private Conversation selectedConversation = null; private ListView listView; private boolean paneShouldBeOpen = true; @@ -50,7 +50,7 @@ public class ConversationActivity extends XmppActivity { @Override public void onConversationListChanged() { - final Conversation currentConv = conversationList.get(selectedConversation); + final Conversation currentConv = getSelectedConversation(); conversationList.clear(); conversationList.addAll(xmppConnectionService .getConversations()); @@ -59,14 +59,14 @@ public class ConversationActivity extends XmppActivity { @Override public void run() { updateConversationList(); - for(int i = 0; i < conversationList.size(); ++i) { - if (currentConv.equals(conversationList.get(i))) { - selectedConversation = i; + /*for(int i = 0; i < conversationList.size(); ++i) { + if (currentConv == conversationList.get(i)) { + selectedConversation = conversationList.get(i); break; } - } + }*/ if(paneShouldBeOpen) { - selectedConversation = 0; + selectedConversation = conversationList.get(0); if (conversationList.size() >= 1) { swapConversationFragment(); } else { @@ -88,7 +88,7 @@ public class ConversationActivity extends XmppActivity { return this.conversationList; } - public int getSelectedConversation() { + public Conversation getSelectedConversation() { return this.selectedConversation; } @@ -164,8 +164,8 @@ public class ConversationActivity extends XmppActivity { public void onItemClick(AdapterView<?> arg0, View clickedView, int position, long arg3) { paneShouldBeOpen = false; - if (selectedConversation != position) { - selectedConversation = position; + if (selectedConversation != conversationList.get(position)) { + selectedConversation = conversationList.get(position); swapConversationFragment(); //.onBackendConnected(conversationList.get(position)); } else { spl.closePane(); @@ -202,7 +202,7 @@ public class ConversationActivity extends XmppActivity { paneShouldBeOpen = false; if (conversationList.size() > 0) { getActionBar().setDisplayHomeAsUpEnabled(true); - getActionBar().setTitle(conversationList.get(selectedConversation).getName()); + getActionBar().setTitle(getSelectedConversation().getName()); invalidateOptionsMenu(); } } @@ -225,6 +225,11 @@ public class ConversationActivity extends XmppActivity { ((MenuItem) menu.findItem(R.id.action_security)).setVisible(false); } else { ((MenuItem) menu.findItem(R.id.action_add)).setVisible(false); + if (this.getSelectedConversation()!=null) { + if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) { + ((MenuItem) menu.findItem(R.id.action_security)).setVisible(false); + } + } } return true; } @@ -245,12 +250,12 @@ public class ConversationActivity extends XmppActivity { startActivity(new Intent(this, NewConversationActivity.class)); break; case R.id.action_archive: - Conversation conv = getConversationList().get(selectedConversation); + Conversation conv = getSelectedConversation(); conv.setStatus(Conversation.STATUS_ARCHIVED); paneShouldBeOpen = true; spl.openPane(); xmppConnectionService.archiveConversation(conv); - selectedConversation = 0; + selectedConversation = conversationList.get(0); break; default: break; @@ -333,7 +338,7 @@ public class ConversationActivity extends XmppActivity { for(int i = 0; i < conversationList.size(); ++i) { if (conversationList.get(i).getUuid().equals(convToView)) { - selectedConversation = i; + selectedConversation = conversationList.get(i); } } paneShouldBeOpen = false; @@ -356,7 +361,7 @@ public class ConversationActivity extends XmppActivity { selectedFragment.onBackendConnected(); } else { Log.d("gultsch","conversationactivity. no old fragment found. creating new one"); - selectedConversation = 0; + selectedConversation = conversationList.get(0); Log.d("gultsch","selected conversation is #"+selectedConversation); swapConversationFragment(); } diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index f2726945..319c3a31 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -161,7 +161,7 @@ public class ConversationFragment extends Fragment { final ConversationActivity activity = (ConversationActivity) getActivity(); if (activity.xmppConnectionServiceBound) { - this.conversation = activity.getConversationList().get(activity.getSelectedConversation()); + this.conversation = activity.getSelectedConversation(); updateMessages(); // rendering complete. now go tell activity to close pane if (!activity.shouldPaneBeOpen()) { @@ -176,7 +176,7 @@ public class ConversationFragment extends Fragment { public void onBackendConnected() { Log.d("gultsch","calling on backend connected in conversation fragment"); final ConversationActivity activity = (ConversationActivity) getActivity(); - this.conversation = activity.getConversationList().get(activity.getSelectedConversation()); + this.conversation = activity.getSelectedConversation(); updateMessages(); // rendering complete. now go tell activity to close pane if (!activity.shouldPaneBeOpen()) { diff --git a/src/de/gultsch/chat/ui/NewConversationActivity.java b/src/de/gultsch/chat/ui/NewConversationActivity.java index cbd68def..ec445e6c 100644 --- a/src/de/gultsch/chat/ui/NewConversationActivity.java +++ b/src/de/gultsch/chat/ui/NewConversationActivity.java @@ -27,6 +27,7 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ImageView; import android.annotation.SuppressLint; @@ -210,21 +211,25 @@ public class NewConversationActivity extends XmppActivity { } this.accounts = xmppConnectionService.getAccounts(); this.rosterContacts.clear(); - xmppConnectionService.getRoster(new OnRosterFetchedListener() { - - @Override - public void onRosterFetched(List<Contact> roster) { - rosterContacts.addAll(roster); - runOnUiThread(new Runnable() { - + for(int i = 0; i < accounts.size(); ++i) { + if (accounts.get(i).getStatus()==Account.STATUS_ONLINE) { + xmppConnectionService.getRoster(accounts.get(i),new OnRosterFetchedListener() { + @Override - public void run() { - updateAggregatedContacts(); + public void onRosterFetched(List<Contact> roster) { + rosterContacts.addAll(roster); + runOnUiThread(new Runnable() { + + @Override + public void run() { + updateAggregatedContacts(); + } + }); + } }); - - } - }); + } + } } @Override @@ -243,10 +248,48 @@ public class NewConversationActivity extends XmppActivity { case R.id.action_accounts: startActivity(new Intent(this, ManageAccountActivity.class)); break; + case R.id.action_refresh_contacts: + refreshContacts(); + break; default: break; } return super.onOptionsItemSelected(item); } + private void refreshContacts() { + final ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar1); + final EditText searchBar = (EditText) findViewById(R.id.new_conversation_search); + final TextView contactsHeader = (TextView) findViewById(R.id.contacts_header); + final ListView contactList = (ListView) findViewById(R.id.contactList); + searchBar.setVisibility(View.GONE); + contactsHeader.setVisibility(View.GONE); + contactList.setVisibility(View.GONE); + progress.setVisibility(View.VISIBLE); + this.accounts = xmppConnectionService.getAccounts(); + this.rosterContacts.clear(); + for (int i = 0; i < accounts.size(); ++i) { + if (accounts.get(i).getStatus()==Account.STATUS_ONLINE) { + xmppConnectionService.updateRoster(accounts.get(i), + new OnRosterFetchedListener() { + + @Override + public void onRosterFetched(final List<Contact> roster) { + runOnUiThread(new Runnable() { + + @Override + public void run() { + rosterContacts.addAll(roster); + progress.setVisibility(View.GONE); + searchBar.setVisibility(View.VISIBLE); + contactList.setVisibility(View.VISIBLE); + contactList.setVisibility(View.VISIBLE); + updateAggregatedContacts(); + } + }); + } + }); + } + } + } } |