aboutsummaryrefslogtreecommitdiffstats
path: root/src/de
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-07 02:57:36 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-07 02:57:36 +0100
commitcda1c2c3a12b4c18f13771dd4b58aab6e465176b (patch)
tree9f246adce16c0951f64f4233c4c0ad8d00d7c8e1 /src/de
parentaa42eb544a1ebf99dc52d71c917b899d1fce628d (diff)
refresh contact list
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/entities/Contact.java10
-rw-r--r--src/de/gultsch/chat/persistance/DatabaseBackend.java7
-rw-r--r--src/de/gultsch/chat/services/XmppConnectionService.java19
-rw-r--r--src/de/gultsch/chat/ui/ConversationActivity.java35
-rw-r--r--src/de/gultsch/chat/ui/ConversationFragment.java4
-rw-r--r--src/de/gultsch/chat/ui/NewConversationActivity.java67
6 files changed, 102 insertions, 40 deletions
diff --git a/src/de/gultsch/chat/entities/Contact.java b/src/de/gultsch/chat/entities/Contact.java
index 47549b22e..3478eac70 100644
--- a/src/de/gultsch/chat/entities/Contact.java
+++ b/src/de/gultsch/chat/entities/Contact.java
@@ -17,7 +17,7 @@ public class Contact extends AbstractEntity implements Serializable {
public static final String SYSTEMACCOUNT = "systemaccount";
public static final String PHOTOURI = "photouri";
public static final String OPENPGPKEY = "pgpkey";
- public static final String LASTONLINEPRESENCE = "presence";
+ public static final String LASTPRESENCE = "presence";
public static final String ACCOUNT = "accountUuid";
protected String accountUuid;
@@ -27,7 +27,7 @@ public class Contact extends AbstractEntity implements Serializable {
protected int systemAccount;
protected String photoUri;
protected String openPGPKey;
- protected long lastOnlinePresence;
+ protected long lastPresence;
protected Account account;
@@ -52,7 +52,7 @@ public class Contact extends AbstractEntity implements Serializable {
this.photoUri = photoUri;
this.systemAccount = systemAccount;
this.openPGPKey = pgpKey;
- this.lastOnlinePresence = lastseen;
+ this.lastPresence = lastseen;
}
public String getDisplayName() {
@@ -82,7 +82,7 @@ public class Contact extends AbstractEntity implements Serializable {
values.put(SYSTEMACCOUNT, systemAccount);
values.put(PHOTOURI,photoUri);
values.put(OPENPGPKEY,openPGPKey);
- values.put(LASTONLINEPRESENCE,lastOnlinePresence);
+ values.put(LASTPRESENCE,lastPresence);
return values;
}
@@ -95,7 +95,7 @@ public class Contact extends AbstractEntity implements Serializable {
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
- cursor.getLong(cursor.getColumnIndex(LASTONLINEPRESENCE))
+ cursor.getLong(cursor.getColumnIndex(LASTPRESENCE))
);
}
diff --git a/src/de/gultsch/chat/persistance/DatabaseBackend.java b/src/de/gultsch/chat/persistance/DatabaseBackend.java
index f28ad7606..ecf7152bf 100644
--- a/src/de/gultsch/chat/persistance/DatabaseBackend.java
+++ b/src/de/gultsch/chat/persistance/DatabaseBackend.java
@@ -53,7 +53,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("create table " + Contact.TABLENAME + "(" + Contact.UUID
+ " TEXT PRIMARY KEY, " + Contact.ACCOUNT + " TEXT, "
+ Contact.DISPLAYNAME + " TEXT," + Contact.JID + " TEXT,"
- + Contact.LASTONLINEPRESENCE + " NUMBER, " + Contact.OPENPGPKEY
+ + Contact.LASTPRESENCE + " NUMBER, " + Contact.OPENPGPKEY
+ " TEXT," + Contact.PHOTOURI + " TEXT," + Contact.SUBSCRIPTION
+ " TEXT," + Contact.SYSTEMACCOUNT + " NUMBER, "
+ "FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES "
@@ -217,10 +217,11 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
}
- public List<Contact> getContacts() {
+ public List<Contact> getContacts(Account account) {
List<Contact> list = new ArrayList<Contact>();
SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(Contact.TABLENAME, null, null, null, null,
+ String args[] = {account.getUuid()};
+ Cursor cursor = db.query(Contact.TABLENAME, null, Contact.ACCOUNT+"=?", args, null,
null, null);
while (cursor.moveToNext()) {
list.add(Contact.fromCursor(cursor));
diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java
index c5477ae08..457c06b67 100644
--- a/src/de/gultsch/chat/services/XmppConnectionService.java
+++ b/src/de/gultsch/chat/services/XmppConnectionService.java
@@ -18,6 +18,7 @@ import de.gultsch.chat.xmpp.IqPacket;
import de.gultsch.chat.xmpp.MessagePacket;
import de.gultsch.chat.xmpp.OnIqPacketReceived;
import de.gultsch.chat.xmpp.OnMessagePacketReceived;
+import de.gultsch.chat.xmpp.OnPresencePacketReceived;
import de.gultsch.chat.xmpp.OnStatusChanged;
import de.gultsch.chat.xmpp.PresencePacket;
import de.gultsch.chat.xmpp.XmppConnection;
@@ -123,6 +124,18 @@ public class XmppConnectionService extends Service {
}
}
};
+
+ private OnPresencePacketReceived presenceListener = new OnPresencePacketReceived() {
+
+ @Override
+ public void onPresencePacketReceived(Account account, PresencePacket packet) {
+ String jid = packet.getAttribute("from");
+ String type = packet.getAttribute("type");
+ if (type==null) {
+ Log.d(LOGTAG,"online presence from "+jid);
+ }
+ }
+ };
public class XmppConnectionBinder extends Binder {
public XmppConnectionService getService() {
@@ -157,6 +170,7 @@ public class XmppConnectionService extends Service {
XmppConnection connection = new XmppConnection(account, pm);
connection.setOnMessagePacketReceivedListener(this.messageListener);
connection.setOnStatusChangedListener(this.statusListener);
+ connection.setOnPresencePacketReceivedListener(this.presenceListener);
Thread thread = new Thread(connection);
thread.start();
return connection;
@@ -185,8 +199,8 @@ public class XmppConnectionService extends Service {
databaseBackend.updateMessage(message);
}
- public void getRoster(final OnRosterFetchedListener listener) {
- List<Contact> contacts = databaseBackend.getContacts();
+ public void getRoster(Account account, final OnRosterFetchedListener listener) {
+ List<Contact> contacts = databaseBackend.getContacts(account);
if (listener != null) {
listener.onRosterFetched(contacts);
}
@@ -249,7 +263,6 @@ public class XmppConnectionService extends Service {
if (roster != null) {
for (Element item : roster.getChildren()) {
Contact contact;
- Log.d(LOGTAG, item.toString());
String name = item.getAttribute("name");
String jid = item.getAttribute("jid");
if (phoneContacts.containsKey(jid)) {
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java
index d9c497f8e..7e4cd34d5 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 f2726945a..319c3a317 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 cbd68def8..ec445e6c2 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();
+ }
+ });
+ }
+ });
+ }
+ }
+ }
}