1
0
mirror of https://github.com/etesync/android synced 2025-07-07 07:12:36 +00:00

Fix crash with missing contact downloader when importing.

This commit is contained in:
Tom Hacohen 2018-10-30 21:34:54 +00:00
parent 513dd21dbe
commit 3efa76579e
2 changed files with 11 additions and 3 deletions

View File

@ -160,7 +160,7 @@ public class ContactsSyncManager extends SyncManager {
protected void processSyncEntry(SyncEntry cEntry) throws IOException, ContactsStorageException, CalendarStorageException { protected void processSyncEntry(SyncEntry cEntry) throws IOException, ContactsStorageException, CalendarStorageException {
InputStream is = new ByteArrayInputStream(cEntry.getContent().getBytes(Charsets.UTF_8)); InputStream is = new ByteArrayInputStream(cEntry.getContent().getBytes(Charsets.UTF_8));
Contact.Downloader downloader = new ResourceDownloader(); Contact.Downloader downloader = new ResourceDownloader(context);
Contact[] contacts = Contact.fromStream(is, Charsets.UTF_8, downloader); Contact[] contacts = Contact.fromStream(is, Charsets.UTF_8, downloader);
if (contacts.length == 0) { if (contacts.length == 0) {
@ -242,7 +242,13 @@ public class ContactsSyncManager extends SyncManager {
// downloader helper class // downloader helper class
private class ResourceDownloader implements Contact.Downloader { public static class ResourceDownloader implements Contact.Downloader {
Context context;
public ResourceDownloader(Context context) {
this.context = context;
}
@Override @Override
public byte[] download(String url, String accepts) { public byte[] download(String url, String accepts) {
HttpUrl httpUrl = HttpUrl.parse(url); HttpUrl httpUrl = HttpUrl.parse(url);

View File

@ -25,6 +25,7 @@ import com.etesync.syncadapter.resource.LocalAddressBook;
import com.etesync.syncadapter.resource.LocalCalendar; import com.etesync.syncadapter.resource.LocalCalendar;
import com.etesync.syncadapter.resource.LocalContact; import com.etesync.syncadapter.resource.LocalContact;
import com.etesync.syncadapter.resource.LocalEvent; import com.etesync.syncadapter.resource.LocalEvent;
import com.etesync.syncadapter.syncadapter.ContactsSyncManager;
import com.etesync.syncadapter.ui.Refreshable; import com.etesync.syncadapter.ui.Refreshable;
import org.apache.commons.codec.Charsets; import org.apache.commons.codec.Charsets;
@ -288,7 +289,8 @@ public class ImportFragment extends DialogFragment {
} }
} else if (info.type.equals(CollectionInfo.Type.ADDRESS_BOOK)) { } else if (info.type.equals(CollectionInfo.Type.ADDRESS_BOOK)) {
// FIXME: Handle groups and download icon? // FIXME: Handle groups and download icon?
final Contact[] contacts = Contact.fromStream(importStream, Charsets.UTF_8, null); Contact.Downloader downloader = new ContactsSyncManager.ResourceDownloader(getContext());
final Contact[] contacts = Contact.fromStream(importStream, Charsets.UTF_8, downloader);
if (contacts.length == 0) { if (contacts.length == 0) {
App.log.warning("Empty/invalid file."); App.log.warning("Empty/invalid file.");