1
0
mirror of https://github.com/etesync/android synced 2024-11-22 16:08:13 +00:00

Read non-high-res photos, too (fixes #53 again); remove stale connection check because RetryStrategy should be enough

This commit is contained in:
rfc2822 2014-04-05 00:41:20 +02:00
parent f298d9dcb6
commit b8df91e12d
3 changed files with 28 additions and 17 deletions

View File

@ -306,22 +306,31 @@ public class LocalAddressBook extends LocalCollection<Contact> {
}
protected void populatePhoto(Contact c) throws RemoteException {
Uri photoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
try {
@Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
@Cleanup InputStream is = fd.createInputStream();
c.setPhoto(IOUtils.toByteArray(is));
} catch(IOException ex) {
Log.v(TAG, "Couldn't read contact photo", ex);
@Cleanup Cursor cursor = providerClient.query(dataURI(),
new String[] { Photo.PHOTO_FILE_ID, Photo.PHOTO },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext()) {
if (!cursor.isNull(0)) {
Uri photoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
try {
@Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
@Cleanup InputStream is = fd.createInputStream();
c.setPhoto(IOUtils.toByteArray(is));
} catch(IOException ex) {
Log.w(TAG, "Couldn't read high-res contact photo", ex);
}
} else
c.setPhoto(cursor.getBlob(1));
}
}
protected void populateOrganization(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(),
new String[] { Organization.COMPANY, Organization.DEPARTMENT, Organization.TITLE, Organization.JOB_DESCRIPTION },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
Organization.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Organization.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext()) {
String company = cursor.getString(0),
@ -345,7 +354,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
protected void populateIMPPs(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Im.DATA, Im.TYPE, Im.LABEL, Im.PROTOCOL, Im.CUSTOM_PROTOCOL },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
Im.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Im.CONTENT_ITEM_TYPE }, null);
while (cursor != null && cursor.moveToNext()) {
String handle = cursor.getString(0);
@ -411,7 +420,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
protected void populateNote(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Note.NOTE },
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
Note.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Note.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext())
c.setNote(cursor.getString(0));
@ -485,9 +494,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
protected void populateSipAddress(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(),
new String[] { CommonDataKinds.SipAddress.SIP_ADDRESS, CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.LABEL },
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE }, null);
new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE, SipAddress.LABEL },
SipAddress.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), SipAddress.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext()) {
Impp impp = new Impp("sip:" + cursor.getString(0));
switch (cursor.getInt(1)) {

View File

@ -82,7 +82,9 @@ public class SyncManager {
remotelyAdded.add(remoteResource);
}
}
try { Thread.sleep(2000); } catch (InterruptedException e) { }
// PHASE 3: pull remote changes from server
syncResult.stats.numInserts = pullNew(remotelyAdded.toArray(new Resource[0]));
syncResult.stats.numUpdates = pullChanged(remotelyUpdated.toArray(new Resource[0]));

View File

@ -36,7 +36,7 @@ public class DavHttpClient {
defaultRqConfig = RequestConfig.copy(RequestConfig.DEFAULT)
.setConnectTimeout(20*1000)
.setSocketTimeout(20*1000)
.setStaleConnectionCheckEnabled(true)
.setStaleConnectionCheckEnabled(false)
.build();
// enable logging