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.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -300,9 +301,8 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
|||
int id = v.getId();
|
||||
|
||||
if (id == R.id.editContact) {
|
||||
LinphoneActivity.instance().editContact(contact);
|
||||
}
|
||||
if (id == R.id.deleteContact) {
|
||||
ContactsManager.getInstance().editContact(getActivity(), contact, null);
|
||||
} else if (id == R.id.deleteContact) {
|
||||
final Dialog dialog = LinphoneActivity.instance().displayDialog(getString(R.string.delete_text));
|
||||
Button delete = dialog.findViewById(R.id.dialog_delete_button);
|
||||
Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
|
||||
|
@ -324,8 +324,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
|||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
if (id == R.id.back) {
|
||||
} else if (id == R.id.back) {
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.provider.ContactsContract;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -114,10 +118,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
editConsumed = true;
|
||||
if (displayName != null)
|
||||
LinphoneActivity.instance().addContact(displayName, sipAddressToAdd);
|
||||
else
|
||||
LinphoneActivity.instance().addContact(null, sipAddressToAdd);
|
||||
ContactsManager.getInstance().createContact(getActivity(), displayName, sipAddressToAdd);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -154,7 +155,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
searchContacts(newText.toString());
|
||||
searchContacts(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -273,7 +274,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
LinphoneContact contact = (LinphoneContact) adapter.getItemAtPosition(position);
|
||||
if (editOnClick) {
|
||||
editConsumed = true;
|
||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||
ContactsManager.getInstance().editContact(getActivity(), contact, sipAddressToAdd);
|
||||
} else {
|
||||
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||
|
@ -289,7 +290,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
|
||||
} else if (editOnClick) {
|
||||
editConsumed = true;
|
||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||
ContactsManager.getInstance().editContact(getActivity(), contact, sipAddressToAdd);
|
||||
} else {
|
||||
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||
|
|
|
@ -25,7 +25,9 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
|
@ -36,6 +38,7 @@ import android.os.AsyncTask;
|
|||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.Data;
|
||||
|
||||
import org.linphone.LinphoneActivity;
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.settings.LinphonePreferences;
|
||||
import org.linphone.LinphoneService;
|
||||
|
@ -225,7 +228,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
try {
|
||||
accountManager.addAccountExplicitly(newAccount, null, null);
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
Log.e("[Contacts Manager] " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -319,7 +322,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
try {
|
||||
mContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
} 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 data3 = c.getString(c.getColumnIndex("data3"));
|
||||
String data4 = c.getString(c.getColumnIndex("data4"));
|
||||
String lookupKey = c.getString(c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
|
||||
|
||||
LinphoneContact contact = mAndroidContactsCache.get(id);
|
||||
if (contact == null) {
|
||||
nativeIds.add(id);
|
||||
contact = new LinphoneContact();
|
||||
contact.setAndroidId(id);
|
||||
contact.setAndroidLookupKey(lookupKey);
|
||||
contact.setFullName(displayName);
|
||||
mAndroidContactsCache.put(id, contact);
|
||||
}
|
||||
|
@ -505,7 +510,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||
if (noa.isSIPAddress()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +529,6 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
data.sipContacts.add(contact);
|
||||
}
|
||||
}
|
||||
contact.createOrUpdateFriendFromNativeContact();
|
||||
data.contacts.add(contact);
|
||||
}
|
||||
mAndroidContactsCache.clear();
|
||||
|
@ -540,6 +544,9 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||
listener.onContactsUpdated();
|
||||
}
|
||||
for (LinphoneContact contact : data.contacts) {
|
||||
contact.createOrUpdateFriendFromNativeContact();
|
||||
}
|
||||
|
||||
setContacts(data.contacts);
|
||||
setSipContacts(data.sipContacts);
|
||||
|
@ -557,4 +564,36 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
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 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 List<LinphoneNumberOrAddress> addresses;
|
||||
private transient ArrayList<ContentProviderOperation> changesToCommit;
|
||||
|
@ -60,6 +60,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
public LinphoneContact() {
|
||||
addresses = new ArrayList<>();
|
||||
androidId = null;
|
||||
androidLookupKey = null;
|
||||
thumbnailUri = null;
|
||||
photoUri = null;
|
||||
changesToCommit = new ArrayList<>();
|
||||
|
@ -463,10 +464,18 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
setPhotoUri(getContactPictureUri());
|
||||
}
|
||||
|
||||
public void setAndroidLookupKey(String lookupKey) {
|
||||
androidLookupKey = lookupKey;
|
||||
}
|
||||
|
||||
public String getAndroidId() {
|
||||
return androidId;
|
||||
}
|
||||
|
||||
public String getAndroidLookupKey() {
|
||||
return androidLookupKey;
|
||||
}
|
||||
|
||||
public Friend getFriend() {
|
||||
return friend;
|
||||
}
|
||||
|
@ -489,8 +498,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
if (isFriend()) {
|
||||
friend.edit();
|
||||
friend.setName(fullName);
|
||||
friend.getVcard().setFamilyName(lastName);
|
||||
friend.getVcard().setGivenName(firstName);
|
||||
if (friend.getVcard() != null) {
|
||||
friend.getVcard().setFamilyName(lastName);
|
||||
friend.getVcard().setGivenName(firstName);
|
||||
}
|
||||
if (organization != null) {
|
||||
friend.getVcard().setOrganization(organization);
|
||||
}
|
||||
|
|
|
@ -1225,7 +1225,7 @@ public class LinphonePreferences {
|
|||
lpc.setContactUriParameters(null);
|
||||
lpc.done();
|
||||
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 {
|
||||
String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId + ";pn-silent=1";
|
||||
String prevContactParams = lpc.getContactParameters();
|
||||
|
@ -1234,11 +1234,11 @@ public class LinphonePreferences {
|
|||
lpc.setContactUriParameters(contactInfos);
|
||||
lpc.done();
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
|
@ -1248,7 +1248,7 @@ public class LinphonePreferences {
|
|||
lpc.setContactUriParameters(null);
|
||||
lpc.done();
|
||||
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();
|
||||
}
|
||||
|
@ -1261,7 +1261,7 @@ public class LinphonePreferences {
|
|||
|
||||
public void setPushNotificationRegistrationID(String regId) {
|
||||
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 : "");
|
||||
setPushNotificationEnabled(isPushNotificationEnabled());
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@
|
|||
<bool name="hide_numbers_and_addresses_without_presence">false</bool>
|
||||
<bool name="hide_sip_contacts_without_presence">false</bool>
|
||||
<bool name="hide_non_linphone_contacts">false</bool>
|
||||
<bool name="use_native_contact_editor">false</bool>
|
||||
|
||||
<!-- Side Menu -->
|
||||
<bool name="hide_assistant_from_side_menu">false</bool>
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:contentAuthority="com.android.contacts"
|
||||
android:accountType="${applicationId}"
|
||||
android:accountType="@string/sync_account_type"
|
||||
android:supportsUploading="false"
|
||||
android:userVisible="false"/>
|
||||
|
|
Loading…
Reference in a new issue