Do not refresh contacts when not required
This commit is contained in:
parent
8d65fab06c
commit
4193cefa60
4 changed files with 15 additions and 17 deletions
|
@ -104,7 +104,6 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
|
|
||||||
public void changeDisplayedContact(LinphoneContact newContact) {
|
public void changeDisplayedContact(LinphoneContact newContact) {
|
||||||
contact = newContact;
|
contact = newContact;
|
||||||
//contact.refresh();
|
|
||||||
displayContact(inflater, view);
|
displayContact(inflater, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +213,6 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACT_DETAIL);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACT_DETAIL);
|
||||||
LinphoneActivity.instance().hideTabBar(false);
|
LinphoneActivity.instance().hideTabBar(false);
|
||||||
}
|
}
|
||||||
contact.refresh();
|
|
||||||
if (contact.getFullName() == null || contact.getFullName().equals("")) {
|
if (contact.getFullName() == null || contact.getFullName().equals("")) {
|
||||||
//Contact has been deleted, return
|
//Contact has been deleted, return
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
LinphoneActivity.instance().displayContacts(false);
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class ContactsManager {
|
||||||
|
|
||||||
for (LinphoneContact c: getContacts()) {
|
for (LinphoneContact c: getContacts()) {
|
||||||
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
|
||||||
if ((noa.isSIPAddress() && (noa.getValue().equals(sipUri) || noa.getValue().equals(sipUri.substring(4)))) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
|
if ((noa.isSIPAddress() && noa.getValue().equals(sipUri)) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class ContactsManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void prepareContactsInBackground() {
|
public synchronized void fetchContacts() {
|
||||||
contacts = new ArrayList<LinphoneContact>();
|
contacts = new ArrayList<LinphoneContact>();
|
||||||
|
|
||||||
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
|
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
|
||||||
|
@ -137,15 +137,14 @@ public class ContactsManager {
|
||||||
|
|
||||||
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
|
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
c.moveToFirst();
|
while (c.moveToNext()) {
|
||||||
do {
|
|
||||||
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
|
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
|
||||||
LinphoneContact contact = new LinphoneContact();
|
LinphoneContact contact = new LinphoneContact();
|
||||||
contact.setAndroidId(id);
|
contact.setAndroidId(id);
|
||||||
contact.refresh();
|
contact.refresh();
|
||||||
contacts.add(contact);
|
contacts.add(contact);
|
||||||
}
|
}
|
||||||
while (c.moveToNext());
|
c.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
private RelativeLayout sideMenuContent, quitLayout, defaultAccount;
|
private RelativeLayout sideMenuContent, quitLayout, defaultAccount;
|
||||||
private ListView accountsList, sideMenuItemList;
|
private ListView accountsList, sideMenuItemList;
|
||||||
private ImageView menu;
|
private ImageView menu;
|
||||||
|
private boolean fetchedContactsOnce = false;
|
||||||
|
|
||||||
static final boolean isInstanciated() {
|
static final boolean isInstanciated() {
|
||||||
return instance != null;
|
return instance != null;
|
||||||
|
@ -1233,9 +1234,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
startService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
|
startService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName()) == PackageManager.PERMISSION_GRANTED){
|
if (getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName()) == PackageManager.PERMISSION_GRANTED && !fetchedContactsOnce) {
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
ContactsManager.getInstance().prepareContactsInBackground();
|
ContactsManager.getInstance().fetchContacts();
|
||||||
|
fetchedContactsOnce = true;
|
||||||
} else {
|
} else {
|
||||||
checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_READ_CONTACTS);
|
checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_READ_CONTACTS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,25 +214,24 @@ public final class LinphoneUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setImagePictureFromUri(Context c, ImageView view, Uri uri, Uri tUri) {
|
public static void setImagePictureFromUri(Context c, ImageView view, Uri pictureUri, Uri thumbnailUri) {
|
||||||
if (uri == null) {
|
if (pictureUri == null) {
|
||||||
view.setImageResource(R.drawable.avatar);
|
view.setImageResource(R.drawable.avatar);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (uri.getScheme().startsWith("http")) {
|
if (pictureUri.getScheme().startsWith("http")) {
|
||||||
Bitmap bm = downloadBitmap(uri);
|
Bitmap bm = downloadBitmap(pictureUri);
|
||||||
if (bm == null) view.setImageResource(R.drawable.avatar);
|
if (bm == null) view.setImageResource(R.drawable.avatar);
|
||||||
view.setImageBitmap(bm);
|
view.setImageBitmap(bm);
|
||||||
} else {
|
} else {
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
try {
|
try {
|
||||||
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(),uri);
|
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(), pictureUri);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (tUri != null) {
|
if (thumbnailUri != null) {
|
||||||
try {
|
try {
|
||||||
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(),tUri);
|
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(), thumbnailUri);
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
view.setImageURI(tUri);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue