Started to toy around with the native contact editor (disabled by default)
This commit is contained in:
parent
41858e4361
commit
d6811c3e5e
7 changed files with 76 additions and 25 deletions
|
@ -25,6 +25,7 @@ import android.app.Fragment;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -300,9 +301,8 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
int id = v.getId();
|
int id = v.getId();
|
||||||
|
|
||||||
if (id == R.id.editContact) {
|
if (id == R.id.editContact) {
|
||||||
LinphoneActivity.instance().editContact(contact);
|
ContactsManager.getInstance().editContact(getActivity(), contact, null);
|
||||||
}
|
} else if (id == R.id.deleteContact) {
|
||||||
if (id == R.id.deleteContact) {
|
|
||||||
final Dialog dialog = LinphoneActivity.instance().displayDialog(getString(R.string.delete_text));
|
final Dialog dialog = LinphoneActivity.instance().displayDialog(getString(R.string.delete_text));
|
||||||
Button delete = dialog.findViewById(R.id.dialog_delete_button);
|
Button delete = dialog.findViewById(R.id.dialog_delete_button);
|
||||||
Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
|
Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
|
||||||
|
@ -324,8 +324,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
} else if (id == R.id.back) {
|
||||||
if (id == R.id.back) {
|
|
||||||
getFragmentManager().popBackStackImmediate();
|
getFragmentManager().popBackStackImmediate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -114,10 +118,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
editConsumed = true;
|
editConsumed = true;
|
||||||
if (displayName != null)
|
ContactsManager.getInstance().createContact(getActivity(), displayName, sipAddressToAdd);
|
||||||
LinphoneActivity.instance().addContact(displayName, sipAddressToAdd);
|
|
||||||
else
|
|
||||||
LinphoneActivity.instance().addContact(null, sipAddressToAdd);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(String newText) {
|
||||||
searchContacts(newText.toString());
|
searchContacts(newText);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -273,7 +274,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
||||||
LinphoneContact contact = (LinphoneContact) adapter.getItemAtPosition(position);
|
LinphoneContact contact = (LinphoneContact) adapter.getItemAtPosition(position);
|
||||||
if (editOnClick) {
|
if (editOnClick) {
|
||||||
editConsumed = true;
|
editConsumed = true;
|
||||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
ContactsManager.getInstance().editContact(getActivity(), contact, sipAddressToAdd);
|
||||||
} else {
|
} else {
|
||||||
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||||
|
@ -289,7 +290,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
||||||
|
|
||||||
} else if (editOnClick) {
|
} else if (editOnClick) {
|
||||||
editConsumed = true;
|
editConsumed = true;
|
||||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
ContactsManager.getInstance().editContact(getActivity(), contact, sipAddressToAdd);
|
||||||
} else {
|
} else {
|
||||||
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||||
|
|
|
@ -25,7 +25,9 @@ import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentProviderOperation;
|
import android.content.ContentProviderOperation;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -36,6 +38,7 @@ import android.os.AsyncTask;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
|
|
||||||
|
import org.linphone.LinphoneActivity;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
import org.linphone.LinphoneService;
|
import org.linphone.LinphoneService;
|
||||||
|
@ -225,7 +228,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
try {
|
try {
|
||||||
accountManager.addAccountExplicitly(newAccount, null, null);
|
accountManager.addAccountExplicitly(newAccount, null, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(e);
|
Log.e("[Contacts Manager] " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,7 +322,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
try {
|
try {
|
||||||
mContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
mContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(e);
|
Log.e("[Contacts Manager] " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,12 +458,14 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
String data2 = c.getString(c.getColumnIndex("data2"));
|
String data2 = c.getString(c.getColumnIndex("data2"));
|
||||||
String data3 = c.getString(c.getColumnIndex("data3"));
|
String data3 = c.getString(c.getColumnIndex("data3"));
|
||||||
String data4 = c.getString(c.getColumnIndex("data4"));
|
String data4 = c.getString(c.getColumnIndex("data4"));
|
||||||
|
String lookupKey = c.getString(c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
|
||||||
|
|
||||||
LinphoneContact contact = mAndroidContactsCache.get(id);
|
LinphoneContact contact = mAndroidContactsCache.get(id);
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
nativeIds.add(id);
|
nativeIds.add(id);
|
||||||
contact = new LinphoneContact();
|
contact = new LinphoneContact();
|
||||||
contact.setAndroidId(id);
|
contact.setAndroidId(id);
|
||||||
|
contact.setAndroidLookupKey(lookupKey);
|
||||||
contact.setFullName(displayName);
|
contact.setFullName(displayName);
|
||||||
mAndroidContactsCache.put(id, contact);
|
mAndroidContactsCache.put(id, contact);
|
||||||
}
|
}
|
||||||
|
@ -505,7 +510,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||||
if (noa.isSIPAddress()) {
|
if (noa.isSIPAddress()) {
|
||||||
contact.setFullName(LinphoneUtils.getAddressDisplayName(noa.getValue()));
|
contact.setFullName(LinphoneUtils.getAddressDisplayName(noa.getValue()));
|
||||||
Log.w("Couldn't find a display name for contact " + contact.getFullName() + ", used SIP address display name / username instead...");
|
Log.w("[Contacts Manager] Couldn't find a display name for contact " + contact.getFullName() + ", used SIP address display name / username instead...");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,7 +529,6 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
data.sipContacts.add(contact);
|
data.sipContacts.add(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contact.createOrUpdateFriendFromNativeContact();
|
|
||||||
data.contacts.add(contact);
|
data.contacts.add(contact);
|
||||||
}
|
}
|
||||||
mAndroidContactsCache.clear();
|
mAndroidContactsCache.clear();
|
||||||
|
@ -540,6 +544,9 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||||
listener.onContactsUpdated();
|
listener.onContactsUpdated();
|
||||||
}
|
}
|
||||||
|
for (LinphoneContact contact : data.contacts) {
|
||||||
|
contact.createOrUpdateFriendFromNativeContact();
|
||||||
|
}
|
||||||
|
|
||||||
setContacts(data.contacts);
|
setContacts(data.contacts);
|
||||||
setSipContacts(data.sipContacts);
|
setSipContacts(data.sipContacts);
|
||||||
|
@ -557,4 +564,36 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
mSipContacts = c;
|
mSipContacts = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void editContact(Context context, LinphoneContact contact, String valueToAdd) {
|
||||||
|
if (context.getResources().getBoolean(R.bool.use_native_contact_editor)) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_EDIT);
|
||||||
|
Uri contactUri = ContactsContract.Contacts.getLookupUri(Long.parseLong(contact.getAndroidId()), contact.getAndroidLookupKey());
|
||||||
|
intent.setDataAndType(contactUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||||
|
intent.putExtra("finishActivityOnSaveCompleted", true); // So after save will go back here
|
||||||
|
if (valueToAdd != null) {
|
||||||
|
intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE, valueToAdd);
|
||||||
|
}
|
||||||
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
LinphoneActivity.instance().editContact(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createContact(Context context, String name, String valueToAdd) {
|
||||||
|
if (context.getResources().getBoolean(R.bool.use_native_contact_editor)) {
|
||||||
|
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
|
||||||
|
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
|
||||||
|
intent.putExtra("finishActivityOnSaveCompleted", true); // So after save will go back here
|
||||||
|
if (name != null) {
|
||||||
|
intent.putExtra(ContactsContract.Intents.Insert.NAME, name);
|
||||||
|
}
|
||||||
|
if (valueToAdd != null) {
|
||||||
|
intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE, valueToAdd);
|
||||||
|
}
|
||||||
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
LinphoneActivity.instance().addContact(name, valueToAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
private static final long serialVersionUID = 9015568163905205244L;
|
private static final long serialVersionUID = 9015568163905205244L;
|
||||||
|
|
||||||
private transient Friend friend;
|
private transient Friend friend;
|
||||||
private String fullName, firstName, lastName, androidId, androidRawId, androidTagId, organization;
|
private String fullName, firstName, lastName, androidId, androidRawId, androidTagId, organization, androidLookupKey;
|
||||||
private transient Uri photoUri, thumbnailUri;
|
private transient Uri photoUri, thumbnailUri;
|
||||||
private List<LinphoneNumberOrAddress> addresses;
|
private List<LinphoneNumberOrAddress> addresses;
|
||||||
private transient ArrayList<ContentProviderOperation> changesToCommit;
|
private transient ArrayList<ContentProviderOperation> changesToCommit;
|
||||||
|
@ -60,6 +60,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
public LinphoneContact() {
|
public LinphoneContact() {
|
||||||
addresses = new ArrayList<>();
|
addresses = new ArrayList<>();
|
||||||
androidId = null;
|
androidId = null;
|
||||||
|
androidLookupKey = null;
|
||||||
thumbnailUri = null;
|
thumbnailUri = null;
|
||||||
photoUri = null;
|
photoUri = null;
|
||||||
changesToCommit = new ArrayList<>();
|
changesToCommit = new ArrayList<>();
|
||||||
|
@ -463,10 +464,18 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
setPhotoUri(getContactPictureUri());
|
setPhotoUri(getContactPictureUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAndroidLookupKey(String lookupKey) {
|
||||||
|
androidLookupKey = lookupKey;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAndroidId() {
|
public String getAndroidId() {
|
||||||
return androidId;
|
return androidId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAndroidLookupKey() {
|
||||||
|
return androidLookupKey;
|
||||||
|
}
|
||||||
|
|
||||||
public Friend getFriend() {
|
public Friend getFriend() {
|
||||||
return friend;
|
return friend;
|
||||||
}
|
}
|
||||||
|
@ -489,8 +498,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
if (isFriend()) {
|
if (isFriend()) {
|
||||||
friend.edit();
|
friend.edit();
|
||||||
friend.setName(fullName);
|
friend.setName(fullName);
|
||||||
friend.getVcard().setFamilyName(lastName);
|
if (friend.getVcard() != null) {
|
||||||
friend.getVcard().setGivenName(firstName);
|
friend.getVcard().setFamilyName(lastName);
|
||||||
|
friend.getVcard().setGivenName(firstName);
|
||||||
|
}
|
||||||
if (organization != null) {
|
if (organization != null) {
|
||||||
friend.getVcard().setOrganization(organization);
|
friend.getVcard().setOrganization(organization);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1225,7 +1225,7 @@ public class LinphonePreferences {
|
||||||
lpc.setContactUriParameters(null);
|
lpc.setContactUriParameters(null);
|
||||||
lpc.done();
|
lpc.done();
|
||||||
if (lpc.getIdentityAddress() != null)
|
if (lpc.getIdentityAddress() != null)
|
||||||
Log.d("Push notif infos removed from proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
Log.d("[Push Notification] infos removed from proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
||||||
} else {
|
} else {
|
||||||
String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId + ";pn-silent=1";
|
String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId + ";pn-silent=1";
|
||||||
String prevContactParams = lpc.getContactParameters();
|
String prevContactParams = lpc.getContactParameters();
|
||||||
|
@ -1234,11 +1234,11 @@ public class LinphonePreferences {
|
||||||
lpc.setContactUriParameters(contactInfos);
|
lpc.setContactUriParameters(contactInfos);
|
||||||
lpc.done();
|
lpc.done();
|
||||||
if (lpc.getIdentityAddress() != null)
|
if (lpc.getIdentityAddress() != null)
|
||||||
Log.d("Push notif infos added to proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
Log.d("[Push Notification] infos added to proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.i("[Push Notification] Refreshing registers to ensure token is up to date" + regId);
|
Log.i("[Push Notification] Refreshing registers to ensure token is up to date: " + regId);
|
||||||
lc.refreshRegisters();
|
lc.refreshRegisters();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1248,7 +1248,7 @@ public class LinphonePreferences {
|
||||||
lpc.setContactUriParameters(null);
|
lpc.setContactUriParameters(null);
|
||||||
lpc.done();
|
lpc.done();
|
||||||
if (lpc.getIdentityAddress() != null)
|
if (lpc.getIdentityAddress() != null)
|
||||||
Log.d("Push notif infos removed from proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
Log.d("[Push Notification] infos removed from proxy config " + lpc.getIdentityAddress().asStringUriOnly());
|
||||||
}
|
}
|
||||||
lc.refreshRegisters();
|
lc.refreshRegisters();
|
||||||
}
|
}
|
||||||
|
@ -1261,7 +1261,7 @@ public class LinphonePreferences {
|
||||||
|
|
||||||
public void setPushNotificationRegistrationID(String regId) {
|
public void setPushNotificationRegistrationID(String regId) {
|
||||||
if (getConfig() == null) return;
|
if (getConfig() == null) return;
|
||||||
Log.i("[Push Notification] New token received" + regId);
|
Log.i("[Push Notification] New token received: " + regId);
|
||||||
getConfig().setString("app", "push_notification_regid", (regId != null) ? regId : "");
|
getConfig().setString("app", "push_notification_regid", (regId != null) ? regId : "");
|
||||||
setPushNotificationEnabled(isPushNotificationEnabled());
|
setPushNotificationEnabled(isPushNotificationEnabled());
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
<bool name="hide_numbers_and_addresses_without_presence">false</bool>
|
<bool name="hide_numbers_and_addresses_without_presence">false</bool>
|
||||||
<bool name="hide_sip_contacts_without_presence">false</bool>
|
<bool name="hide_sip_contacts_without_presence">false</bool>
|
||||||
<bool name="hide_non_linphone_contacts">false</bool>
|
<bool name="hide_non_linphone_contacts">false</bool>
|
||||||
|
<bool name="use_native_contact_editor">false</bool>
|
||||||
|
|
||||||
<!-- Side Menu -->
|
<!-- Side Menu -->
|
||||||
<bool name="hide_assistant_from_side_menu">false</bool>
|
<bool name="hide_assistant_from_side_menu">false</bool>
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
|
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:contentAuthority="com.android.contacts"
|
android:contentAuthority="com.android.contacts"
|
||||||
android:accountType="${applicationId}"
|
android:accountType="@string/sync_account_type"
|
||||||
android:supportsUploading="false"
|
android:supportsUploading="false"
|
||||||
android:userVisible="false"/>
|
android:userVisible="false"/>
|
||||||
|
|
Loading…
Reference in a new issue