mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 11:42:15 -05:00
reworked handeling of system contacts
This commit is contained in:
parent
3eab3291de
commit
53e8964dc1
@ -237,8 +237,16 @@ public class Contact implements ListItem, Blockable {
|
||||
return this.presences.getMostAvailableStatus();
|
||||
}
|
||||
|
||||
public void setPhotoUri(String 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) {
|
||||
|
@ -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,13 +56,16 @@ 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() {
|
||||
synchronized (this.contacts) {
|
||||
|
@ -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"));
|
||||
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");
|
||||
|
@ -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,6 +127,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (contact.getSystemAccount() == null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
ContactDetailsActivity.this);
|
||||
builder.setTitle(getString(R.string.action_add_phone_book));
|
||||
@ -134,6 +136,14 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user