1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

LocalCalendar: accept JournalEntity, not CollectionInfo when creating and updating.

Some of the information is now saved there, and more will be transferred
soon. CollectionInfo includes the encrypted part, and journalentity the
non-encrypted part of the journal info, so both are needed.
This commit is contained in:
Tom Hacohen 2017-04-21 11:08:20 +01:00
parent f8d0878003
commit df3db6b357
2 changed files with 17 additions and 15 deletions

View File

@ -25,6 +25,7 @@ import android.text.TextUtils;
import com.etesync.syncadapter.App;
import com.etesync.syncadapter.model.CollectionInfo;
import com.etesync.syncadapter.model.JournalEntity;
import net.fortuna.ical4j.model.component.VTimeZone;
@ -64,8 +65,8 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
super(account, provider, LocalEvent.Factory.INSTANCE, id);
}
public static Uri create(@NonNull Account account, @NonNull ContentProviderClient provider, @NonNull CollectionInfo info) throws CalendarStorageException {
ContentValues values = valuesFromCollectionInfo(info, true);
public static Uri create(@NonNull Account account, @NonNull ContentProviderClient provider, @NonNull JournalEntity journalEntity) throws CalendarStorageException {
ContentValues values = valuesFromCollectionInfo(journalEntity, true);
// ACCOUNT_NAME and ACCOUNT_TYPE are required (see docs)! If it's missing, other apps will crash.
values.put(Calendars.ACCOUNT_NAME, account.name);
@ -79,8 +80,8 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
return create(account, provider, values);
}
public void update(CollectionInfo info, boolean updateColor) throws CalendarStorageException {
update(valuesFromCollectionInfo(info, updateColor));
public void update(JournalEntity journalEntity, boolean updateColor) throws CalendarStorageException {
update(valuesFromCollectionInfo(journalEntity, updateColor));
}
public static LocalCalendar findByName(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, String name) throws FileNotFoundException, CalendarStorageException {
@ -93,7 +94,8 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
}
}
private static ContentValues valuesFromCollectionInfo(CollectionInfo info, boolean withColor) {
private static ContentValues valuesFromCollectionInfo(JournalEntity journalEntity, boolean withColor) {
CollectionInfo info = journalEntity.getInfo();
ContentValues values = new ContentValues();
values.put(Calendars.NAME, info.uid);
values.put(Calendars.CALENDAR_DISPLAY_NAME, info.displayName);

View File

@ -111,10 +111,10 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
EntityDataStore<Persistable> data = ((App) getContext().getApplicationContext()).getData();
ServiceEntity service = JournalModel.Service.fetch(data, account.name, CollectionInfo.Type.CALENDAR);
Map<String, CollectionInfo> remote = new HashMap<>();
List<CollectionInfo> remoteCollections = JournalEntity.getCollections(data, service);
for (CollectionInfo info : remoteCollections) {
remote.put(info.uid, info);
Map<String, JournalEntity> remote = new HashMap<>();
List<JournalEntity> remoteJournals = JournalEntity.getJournals(data, service);
for (JournalEntity journalEntity : remoteJournals) {
remote.put(journalEntity.getUid(), journalEntity);
}
LocalCalendar[] local = (LocalCalendar[]) LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, null, null);
@ -129,9 +129,9 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
calendar.delete();
} else {
// remote CollectionInfo found for this local collection, update data
CollectionInfo info = remote.get(url);
App.log.fine("Updating local calendar " + url + " with " + info);
calendar.update(info, updateColors);
JournalEntity journalEntity = remote.get(url);
App.log.fine("Updating local calendar " + url + " with " + journalEntity);
calendar.update(journalEntity, updateColors);
// we already have a local calendar for this remote collection, don't take into consideration anymore
remote.remove(url);
}
@ -139,9 +139,9 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
// create new local calendars
for (String url : remote.keySet()) {
CollectionInfo info = remote.get(url);
App.log.info("Adding local calendar list " + info);
LocalCalendar.create(account, provider, info);
JournalEntity journalEntity = remote.get(url);
App.log.info("Adding local calendar list " + journalEntity);
LocalCalendar.create(account, provider, journalEntity);
}
}
}