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();
|
return this.presences.getMostAvailableStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhotoUri(String uri) {
|
public boolean setPhotoUri(String uri) {
|
||||||
|
if (uri != null && !uri.equals(this.photoUri)) {
|
||||||
this.photoUri = uri;
|
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) {
|
public void setServerName(String serverName) {
|
||||||
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.entities;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
@ -55,13 +56,16 @@ public class Roster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearSystemAccounts() {
|
public List<Contact> getWithSystemAccounts() {
|
||||||
for (Contact contact : getContacts()) {
|
List<Contact> with = getContacts();
|
||||||
contact.setPhotoUri(null);
|
for(Iterator<Contact> iterator = with.iterator(); iterator.hasNext();) {
|
||||||
contact.setSystemName(null);
|
Contact contact = iterator.next();
|
||||||
contact.setSystemAccount(null);
|
if (contact.getSystemAccount() == null) {
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return with;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Contact> getContacts() {
|
public List<Contact> getContacts() {
|
||||||
synchronized (this.contacts) {
|
synchronized (this.contacts) {
|
||||||
|
@ -927,7 +927,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
public void run() {
|
public void run() {
|
||||||
Log.d(Config.LOGTAG,"start merging phone contacts with roster");
|
Log.d(Config.LOGTAG,"start merging phone contacts with roster");
|
||||||
for (Account account : accounts) {
|
for (Account account : accounts) {
|
||||||
account.getRoster().clearSystemAccounts();
|
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
|
||||||
for (Bundle phoneContact : phoneContacts) {
|
for (Bundle phoneContact : phoneContacts) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Log.d(Config.LOGTAG,"interrupted merging phone contacts");
|
Log.d(Config.LOGTAG,"interrupted merging phone contacts");
|
||||||
@ -944,9 +944,18 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
+ "#"
|
+ "#"
|
||||||
+ phoneContact.getString("lookup");
|
+ phoneContact.getString("lookup");
|
||||||
contact.setSystemAccount(systemAccount);
|
contact.setSystemAccount(systemAccount);
|
||||||
contact.setPhotoUri(phoneContact.getString("photouri"));
|
if (contact.setPhotoUri(phoneContact.getString("photouri"))) {
|
||||||
getAvatarService().clear(contact);
|
getAvatarService().clear(contact);
|
||||||
|
}
|
||||||
contact.setSystemName(phoneContact.getString("displayname"));
|
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");
|
Log.d(Config.LOGTAG,"finished merging phone contacts");
|
||||||
|
@ -10,6 +10,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.CommonDataKinds;
|
import android.provider.ContactsContract.CommonDataKinds;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.Intents;
|
import android.provider.ContactsContract.Intents;
|
||||||
@ -126,6 +127,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
if (contact.getSystemAccount() == null) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
ContactDetailsActivity.this);
|
ContactDetailsActivity.this);
|
||||||
builder.setTitle(getString(R.string.action_add_phone_book));
|
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.setNegativeButton(getString(R.string.cancel), null);
|
||||||
builder.setPositiveButton(getString(R.string.add), addToPhonebook);
|
builder.setPositiveButton(getString(R.string.add), addToPhonebook);
|
||||||
builder.create().show();
|
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 {
|
} else {
|
||||||
contactJidTv.setText(contact.getJid().toString());
|
contactJidTv.setText(contact.getJid().toString());
|
||||||
}
|
}
|
||||||
accountJidTv.setText(getString(R.string.using_account, contact
|
accountJidTv.setText(getString(R.string.using_account, contact.getAccount().getJid().toBareJid()));
|
||||||
.getAccount().getJid().toBareJid()));
|
badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
|
||||||
prepareContactBadge(badge, contact);
|
badge.setOnClickListener(this.onBadgeClick);
|
||||||
if (contact.getSystemAccount() == null) {
|
|
||||||
badge.setOnClickListener(onBadgeClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
keys.removeAllViews();
|
keys.removeAllViews();
|
||||||
boolean hasKeys = false;
|
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) {
|
protected void confirmToDeleteFingerprint(final String fingerprint) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(R.string.delete_fingerprint);
|
builder.setTitle(R.string.delete_fingerprint);
|
||||||
|
Loading…
Reference in New Issue
Block a user