Fixes and improvements
This commit is contained in:
parent
8eadbbb52d
commit
aec6a066e5
2 changed files with 24 additions and 43 deletions
|
@ -33,7 +33,6 @@ import android.app.Dialog;
|
|||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
|
@ -41,7 +40,6 @@ import android.os.Bundle;
|
|||
import android.os.Environment;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -67,7 +65,7 @@ public class ContactEditorFragment extends Fragment {
|
|||
private static final int ADD_PHOTO = 1337;
|
||||
private static final int PHOTO_SIZE = 128;
|
||||
|
||||
private boolean isNewContact = true;
|
||||
private boolean isNewContact;
|
||||
private LinphoneContact contact;
|
||||
private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
||||
private int firstSipAddressIndex = -1;
|
||||
|
@ -80,6 +78,8 @@ public class ContactEditorFragment extends Fragment {
|
|||
this.inflater = inflater;
|
||||
|
||||
contact = null;
|
||||
isNewContact = true;
|
||||
|
||||
if (getArguments() != null) {
|
||||
Serializable obj = getArguments().getSerializable("Contact");
|
||||
if (obj != null) {
|
||||
|
@ -88,10 +88,8 @@ public class ContactEditorFragment extends Fragment {
|
|||
if (getArguments().getString("NewSipAdress") != null) {
|
||||
newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
|
||||
}
|
||||
|
||||
} else if (getArguments().getString("NewSipAdress") != null) {
|
||||
newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
|
||||
isNewContact = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +255,11 @@ public class ContactEditorFragment extends Fragment {
|
|||
}
|
||||
|
||||
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||
LinphoneUtils.setImagePictureFromUri(getActivity(), contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||
if (contact != null) {
|
||||
LinphoneUtils.setImagePictureFromUri(getActivity(), contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||
} else {
|
||||
contactPicture.setImageResource(R.drawable.avatar);
|
||||
}
|
||||
|
||||
contactPicture.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
@ -341,19 +343,6 @@ public class ContactEditorFragment extends Fragment {
|
|||
startActivityForResult(chooserIntent, ADD_PHOTO);
|
||||
}
|
||||
|
||||
public String getRealPathFromURI(Uri contentUri) {
|
||||
String[] proj = {MediaStore.Images.Media.DATA};
|
||||
CursorLoader loader = new CursorLoader(getActivity(), contentUri, proj, null, null, null);
|
||||
Cursor cursor = loader.loadInBackground();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||
String result = cursor.getString(column_index);
|
||||
cursor.close();
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
|
||||
|
|
|
@ -123,11 +123,13 @@ public class LinphoneContact implements Serializable {
|
|||
}
|
||||
} else {
|
||||
String id = findDataId(getAndroidId());
|
||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data._ID + "= ?", new String[] { id })
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
if (id != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data._ID + "= ?", new String[] { id })
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,15 +173,13 @@ public class LinphoneContact implements Serializable {
|
|||
}
|
||||
|
||||
public void save() {
|
||||
if (ContactsManager.getInstance().hasContactsAccess()) {
|
||||
if (isAndroidContact()) {
|
||||
try {
|
||||
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, changesToCommit);
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
} finally {
|
||||
changesToCommit = new ArrayList<ContentProviderOperation>();
|
||||
}
|
||||
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
||||
try {
|
||||
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, changesToCommit);
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
} finally {
|
||||
changesToCommit = new ArrayList<ContentProviderOperation>();
|
||||
}
|
||||
} else {
|
||||
if (friend == null) {
|
||||
|
@ -193,16 +193,8 @@ public class LinphoneContact implements Serializable {
|
|||
if (isAndroidContact()) {
|
||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
||||
String[] args = new String[] { getAndroidId() };
|
||||
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
|
||||
|
||||
ContentResolver cr = ContactsManager.getInstance().getContentResolver();
|
||||
try {
|
||||
cr.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
}
|
||||
changesToCommit.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
|
||||
save();
|
||||
}
|
||||
deleteFriend();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue