fixed add contact detail fragment when launching application from native contact
This commit is contained in:
parent
e711e0750d
commit
05a440f27a
6 changed files with 84 additions and 7 deletions
|
@ -599,11 +599,13 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
|||
protected void changeFragment(Fragment fragment, String name, boolean isChild) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
||||
|
||||
if (transaction.isAddToBackStackAllowed()) {
|
||||
int count = fragmentManager.getBackStackEntryCount();
|
||||
if (count > 0) {
|
||||
FragmentManager.BackStackEntry entry =
|
||||
fragmentManager.getBackStackEntryAt(count - 1);
|
||||
|
||||
if (entry != null && name.equals(entry.getName())) {
|
||||
fragmentManager.popBackStack();
|
||||
if (!isChild) {
|
||||
|
|
|
@ -231,6 +231,7 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
|||
+ " contacts found in which "
|
||||
+ data.sipContacts.size()
|
||||
+ " are SIP");
|
||||
|
||||
for (LinphoneContact contact : data.contacts) {
|
||||
contact.createOrUpdateFriendFromNativeContact();
|
||||
}
|
||||
|
|
|
@ -291,6 +291,7 @@ public class ContactDetailsFragment extends Fragment implements ContactsUpdatedL
|
|||
}
|
||||
|
||||
String contactAddress = mContact.getContactFromPresenceModelForUriOrTel(noa.getValue());
|
||||
|
||||
if (!mDisplayChatAddressOnly) {
|
||||
v.findViewById(R.id.contact_call)
|
||||
.setOnClickListener(
|
||||
|
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
import android.Manifest;
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
@ -47,6 +48,7 @@ public class ContactsActivity extends MainActivity {
|
|||
super.onStart();
|
||||
|
||||
Fragment currentFragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||
|
||||
if (currentFragment == null) {
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
@ -54,6 +56,17 @@ public class ContactsActivity extends MainActivity {
|
|||
showContactsList();
|
||||
}
|
||||
handleIntentExtras(extras);
|
||||
|
||||
} else if (getIntent() != null && getIntent().getData() != null) {
|
||||
Uri uri = getIntent().getData();
|
||||
|
||||
if (isTablet()) {
|
||||
showContactsList();
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("uri", uri.toString());
|
||||
handleIntentExtras(bundle);
|
||||
|
||||
} else {
|
||||
showContactsList();
|
||||
if (isTablet()) {
|
||||
|
@ -67,18 +80,26 @@ public class ContactsActivity extends MainActivity {
|
|||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) {
|
||||
bundle = new Bundle();
|
||||
}
|
||||
|
||||
// Clean fragments stack upon return
|
||||
while (getFragmentManager().getBackStackEntryCount() > 0) {
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
}
|
||||
|
||||
handleIntentExtras(intent.getExtras());
|
||||
if (intent.getData() != null) {
|
||||
bundle.putString("uri", intent.getDataString());
|
||||
}
|
||||
|
||||
handleIntentExtras(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
mContactsSelected.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
@ -113,12 +134,27 @@ public class ContactsActivity extends MainActivity {
|
|||
private void handleIntentExtras(Bundle extras) {
|
||||
if (extras == null) return;
|
||||
|
||||
if (extras.containsKey("Contact")) {
|
||||
if (isTablet()) {
|
||||
showContactsList();
|
||||
}
|
||||
|
||||
if (extras.containsKey("uri")) {
|
||||
String uri = extras.getString("uri");
|
||||
Uri contactUri = Uri.parse(uri);
|
||||
String id = ContactsManager.getInstance().getAndroidContactIdFromUri(contactUri);
|
||||
|
||||
LinphoneContact linphoneContact =
|
||||
ContactsManager.getInstance().findContactFromAndroidId(id);
|
||||
if (linphoneContact != null) {
|
||||
showContactDetails(linphoneContact, isTablet());
|
||||
}
|
||||
} else if (extras.containsKey("Contact")) {
|
||||
LinphoneContact contact = (LinphoneContact) extras.get("Contact");
|
||||
|
||||
if (extras.containsKey("Edit")) {
|
||||
showContactEdit(contact, extras, false);
|
||||
showContactEdit(contact, extras, isTablet());
|
||||
} else {
|
||||
showContactDetails(contact, false);
|
||||
showContactDetails(contact, isTablet());
|
||||
}
|
||||
} else if (extras.containsKey("CreateOrEdit")) {
|
||||
mEditOnClick = extras.getBoolean("CreateOrEdit");
|
||||
|
@ -153,6 +189,7 @@ public class ContactsActivity extends MainActivity {
|
|||
if (contact != null) {
|
||||
extras.putSerializable("Contact", contact);
|
||||
}
|
||||
|
||||
ContactDetailsFragment fragment = new ContactDetailsFragment();
|
||||
fragment.setArguments(extras);
|
||||
changeFragment(fragment, "Contact detail", isChild);
|
||||
|
|
|
@ -327,8 +327,25 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
}
|
||||
}
|
||||
|
||||
public String getAndroidContactIdFromUri(Uri uri) {
|
||||
String[] projection = {ContactsContract.CommonDataKinds.SipAddress.CONTACT_ID};
|
||||
Cursor cursor =
|
||||
mContext.getApplicationContext()
|
||||
.getContentResolver()
|
||||
.query(uri, projection, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
|
||||
int nameColumnIndex =
|
||||
cursor.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.CONTACT_ID);
|
||||
String id = cursor.getString(nameColumnIndex);
|
||||
cursor.close();
|
||||
return id;
|
||||
}
|
||||
|
||||
public synchronized LinphoneContact findContactFromAndroidId(String androidId) {
|
||||
if (androidId == null) return null;
|
||||
if (androidId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (LinphoneContact c : getContacts()) {
|
||||
if (c.getAndroidId() != null && c.getAndroidId().equals(androidId)) {
|
||||
|
@ -427,7 +444,9 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
|
||||
private synchronized boolean refreshSipContact(Friend lf) {
|
||||
LinphoneContact contact = (LinphoneContact) lf.getUserData();
|
||||
|
||||
if (contact != null) {
|
||||
|
||||
if (!mSipContacts.contains(contact)) {
|
||||
mSipContacts.add(contact);
|
||||
return true;
|
||||
|
@ -484,8 +503,11 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
@Override
|
||||
public void onPresenceReceived(FriendList list, Friend[] friends) {
|
||||
boolean updated = false;
|
||||
|
||||
for (Friend lf : friends) {
|
||||
|
||||
boolean newContact = refreshSipContact(lf);
|
||||
|
||||
if (newContact) {
|
||||
updated = true;
|
||||
}
|
||||
|
|
|
@ -66,8 +66,10 @@ public class LinphoneContact extends AndroidContact
|
|||
|
||||
public static LinphoneContact createContact() {
|
||||
LinphoneContact contact = new LinphoneContact();
|
||||
|
||||
if (ContactsManager.getInstance().hasReadContactsAccess()) {
|
||||
contact.createAndroidContact();
|
||||
|
||||
} else {
|
||||
contact.createFriend();
|
||||
}
|
||||
|
@ -89,7 +91,9 @@ public class LinphoneContact extends AndroidContact
|
|||
int idComp = getAndroidId().compareTo(contact.getAndroidId());
|
||||
if (idComp == 0) return 0;
|
||||
List<LinphoneNumberOrAddress> noas1 = getNumbersOrAddresses();
|
||||
|
||||
List<LinphoneNumberOrAddress> noas2 = contact.getNumbersOrAddresses();
|
||||
|
||||
if (noas1.size() == noas2.size()) {
|
||||
if (noas1.containsAll(noas2) && noas2.containsAll(noas1)) {
|
||||
return 0;
|
||||
|
@ -333,6 +337,7 @@ public class LinphoneContact extends AndroidContact
|
|||
if (isFriend()) {
|
||||
mFriend.edit();
|
||||
mFriend.setName(mFullName);
|
||||
|
||||
if (mFriend.getVcard() != null) {
|
||||
mFriend.getVcard().setFamilyName(mLastName);
|
||||
mFriend.getVcard().setGivenName(mFirstName);
|
||||
|
@ -349,9 +354,13 @@ public class LinphoneContact extends AndroidContact
|
|||
mFriend.removePhoneNumber(phone);
|
||||
}
|
||||
}
|
||||
|
||||
for (LinphoneNumberOrAddress noa : getNumbersOrAddresses()) {
|
||||
|
||||
if (noa.isSIPAddress()) {
|
||||
|
||||
Address addr = core.interpretUrl(noa.getValue());
|
||||
|
||||
if (addr != null) {
|
||||
mFriend.addAddress(addr);
|
||||
}
|
||||
|
@ -415,7 +424,9 @@ public class LinphoneContact extends AndroidContact
|
|||
}
|
||||
|
||||
public String getContactFromPresenceModelForUriOrTel(String uri) {
|
||||
|
||||
if (mFriend != null && mFriend.getPresenceModelForUriOrTel(uri) != null) {
|
||||
|
||||
return mFriend.getPresenceModelForUriOrTel(uri).getContact();
|
||||
}
|
||||
return null;
|
||||
|
@ -467,6 +478,7 @@ public class LinphoneContact extends AndroidContact
|
|||
mOrganization = mFriend.getVcard().getOrganization();
|
||||
|
||||
Core core = LinphoneManager.getCore();
|
||||
|
||||
if (core != null && core.vcardSupported()) {
|
||||
for (Address addr : mFriend.getAddresses()) {
|
||||
if (addr != null) {
|
||||
|
@ -511,6 +523,7 @@ public class LinphoneContact extends AndroidContact
|
|||
public void syncValuesFromAndroidCusor(Cursor c) {
|
||||
String displayName =
|
||||
c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME_PRIMARY));
|
||||
|
||||
String mime = c.getString(c.getColumnIndex(ContactsContract.Data.MIMETYPE));
|
||||
String data1 = c.getString(c.getColumnIndex("data1"));
|
||||
String data2 = c.getString(c.getColumnIndex("data2"));
|
||||
|
@ -523,10 +536,12 @@ public class LinphoneContact extends AndroidContact
|
|||
|
||||
if (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mime)) {
|
||||
addNumberOrAddress(new LinphoneNumberOrAddress(data1, data4));
|
||||
|
||||
} else if (ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE.equals(mime)
|
||||
|| LinphoneService.instance()
|
||||
.getString(R.string.linphone_address_mime_type)
|
||||
.equals(mime)) {
|
||||
|
||||
addNumberOrAddress(new LinphoneNumberOrAddress(data1, true));
|
||||
} else if (ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE.equals(mime)) {
|
||||
setOrganization(data1, false);
|
||||
|
@ -543,7 +558,6 @@ public class LinphoneContact extends AndroidContact
|
|||
|
||||
public void delete() {
|
||||
deleteAndroidContact();
|
||||
|
||||
if (isFriend()) {
|
||||
deleteFriend();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue