aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Contact.java12
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Roster.java14
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java15
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java42
4 files changed, 51 insertions, 32 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java
index 9dbca59a..e546f214 100644
--- a/src/main/java/eu/siacs/conversations/entities/Contact.java
+++ b/src/main/java/eu/siacs/conversations/entities/Contact.java
@@ -237,8 +237,16 @@ public class Contact implements ListItem, Blockable {
return this.presences.getMostAvailableStatus();
}
- public void setPhotoUri(String uri) {
- this.photoUri = uri;
+ public boolean setPhotoUri(String uri) {
+ if (uri != null && !uri.equals(this.photoUri)) {
+ this.photoUri = uri;
+ return true;
+ } else if (this.photoUri != null && uri == null) {
+ this.photoUri = null;
+ return true;
+ } else {
+ return false;
+ }
}
public void setServerName(String serverName) {
diff --git a/src/main/java/eu/siacs/conversations/entities/Roster.java b/src/main/java/eu/siacs/conversations/entities/Roster.java
index ce058004..d6777ef6 100644
--- a/src/main/java/eu/siacs/conversations/entities/Roster.java
+++ b/src/main/java/eu/siacs/conversations/entities/Roster.java
@@ -2,6 +2,7 @@ package eu.siacs.conversations.entities;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -55,12 +56,15 @@ public class Roster {
}
}
- public void clearSystemAccounts() {
- for (Contact contact : getContacts()) {
- contact.setPhotoUri(null);
- contact.setSystemName(null);
- contact.setSystemAccount(null);
+ public List<Contact> getWithSystemAccounts() {
+ List<Contact> with = getContacts();
+ for(Iterator<Contact> iterator = with.iterator(); iterator.hasNext();) {
+ Contact contact = iterator.next();
+ if (contact.getSystemAccount() == null) {
+ iterator.remove();
+ }
}
+ return with;
}
public List<Contact> getContacts() {
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index fa8dd7d6..7b5532a4 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -927,7 +927,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void run() {
Log.d(Config.LOGTAG,"start merging phone contacts with roster");
for (Account account : accounts) {
- account.getRoster().clearSystemAccounts();
+ List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
for (Bundle phoneContact : phoneContacts) {
if (Thread.interrupted()) {
Log.d(Config.LOGTAG,"interrupted merging phone contacts");
@@ -944,9 +944,18 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
+ "#"
+ phoneContact.getString("lookup");
contact.setSystemAccount(systemAccount);
- contact.setPhotoUri(phoneContact.getString("photouri"));
- getAvatarService().clear(contact);
+ if (contact.setPhotoUri(phoneContact.getString("photouri"))) {
+ getAvatarService().clear(contact);
+ }
contact.setSystemName(phoneContact.getString("displayname"));
+ withSystemAccounts.remove(contact);
+ }
+ for(Contact contact : withSystemAccounts) {
+ contact.setSystemAccount(null);
+ contact.setSystemName(null);
+ if (contact.setPhotoUri(null)) {
+ getAvatarService().clear(contact);
+ }
}
}
Log.d(Config.LOGTAG,"finished merging phone contacts");
diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
index f7156d7a..c190caed 100644
--- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -10,6 +10,7 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
@@ -126,14 +127,23 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void onClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(
- ContactDetailsActivity.this);
- builder.setTitle(getString(R.string.action_add_phone_book));
- builder.setMessage(getString(R.string.add_phone_book_text,
+ if (contact.getSystemAccount() == null) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(
+ ContactDetailsActivity.this);
+ builder.setTitle(getString(R.string.action_add_phone_book));
+ builder.setMessage(getString(R.string.add_phone_book_text,
contact.getJid()));
- builder.setNegativeButton(getString(R.string.cancel), null);
- builder.setPositiveButton(getString(R.string.add), addToPhonebook);
- builder.create().show();
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton(getString(R.string.add), addToPhonebook);
+ builder.create().show();
+ } else {
+ String[] systemAccount = contact.getSystemAccount().split("#");
+ long id = Long.parseLong(systemAccount[0]);
+ Uri uri = ContactsContract.Contacts.getLookupUri(id, systemAccount[1]);
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(uri);
+ startActivity(intent);
+ }
}
};
@@ -340,12 +350,9 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
} else {
contactJidTv.setText(contact.getJid().toString());
}
- accountJidTv.setText(getString(R.string.using_account, contact
- .getAccount().getJid().toBareJid()));
- prepareContactBadge(badge, contact);
- if (contact.getSystemAccount() == null) {
- badge.setOnClickListener(onBadgeClick);
- }
+ accountJidTv.setText(getString(R.string.using_account, contact.getAccount().getJid().toBareJid()));
+ badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
+ badge.setOnClickListener(this.onBadgeClick);
keys.removeAllViews();
boolean hasKeys = false;
@@ -419,15 +426,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
}
- private void prepareContactBadge(QuickContactBadge badge, Contact contact) {
- if (contact.getSystemAccount() != null) {
- String[] systemAccount = contact.getSystemAccount().split("#");
- long id = Long.parseLong(systemAccount[0]);
- badge.assignContactUri(Contacts.getLookupUri(id, systemAccount[1]));
- }
- badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
- }
-
protected void confirmToDeleteFingerprint(final String fingerprint) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete_fingerprint);