1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +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.App;
import com.etesync.syncadapter.model.CollectionInfo; import com.etesync.syncadapter.model.CollectionInfo;
import com.etesync.syncadapter.model.JournalEntity;
import net.fortuna.ical4j.model.component.VTimeZone; 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); super(account, provider, LocalEvent.Factory.INSTANCE, id);
} }
public static Uri create(@NonNull Account account, @NonNull ContentProviderClient provider, @NonNull CollectionInfo info) throws CalendarStorageException { public static Uri create(@NonNull Account account, @NonNull ContentProviderClient provider, @NonNull JournalEntity journalEntity) throws CalendarStorageException {
ContentValues values = valuesFromCollectionInfo(info, true); ContentValues values = valuesFromCollectionInfo(journalEntity, true);
// ACCOUNT_NAME and ACCOUNT_TYPE are required (see docs)! If it's missing, other apps will crash. // ACCOUNT_NAME and ACCOUNT_TYPE are required (see docs)! If it's missing, other apps will crash.
values.put(Calendars.ACCOUNT_NAME, account.name); values.put(Calendars.ACCOUNT_NAME, account.name);
@ -79,8 +80,8 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
return create(account, provider, values); return create(account, provider, values);
} }
public void update(CollectionInfo info, boolean updateColor) throws CalendarStorageException { public void update(JournalEntity journalEntity, boolean updateColor) throws CalendarStorageException {
update(valuesFromCollectionInfo(info, updateColor)); update(valuesFromCollectionInfo(journalEntity, updateColor));
} }
public static LocalCalendar findByName(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, String name) throws FileNotFoundException, CalendarStorageException { 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(); ContentValues values = new ContentValues();
values.put(Calendars.NAME, info.uid); values.put(Calendars.NAME, info.uid);
values.put(Calendars.CALENDAR_DISPLAY_NAME, info.displayName); 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(); EntityDataStore<Persistable> data = ((App) getContext().getApplicationContext()).getData();
ServiceEntity service = JournalModel.Service.fetch(data, account.name, CollectionInfo.Type.CALENDAR); ServiceEntity service = JournalModel.Service.fetch(data, account.name, CollectionInfo.Type.CALENDAR);
Map<String, CollectionInfo> remote = new HashMap<>(); Map<String, JournalEntity> remote = new HashMap<>();
List<CollectionInfo> remoteCollections = JournalEntity.getCollections(data, service); List<JournalEntity> remoteJournals = JournalEntity.getJournals(data, service);
for (CollectionInfo info : remoteCollections) { for (JournalEntity journalEntity : remoteJournals) {
remote.put(info.uid, info); remote.put(journalEntity.getUid(), journalEntity);
} }
LocalCalendar[] local = (LocalCalendar[]) LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, null, null); LocalCalendar[] local = (LocalCalendar[]) LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, null, null);
@ -129,9 +129,9 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
calendar.delete(); calendar.delete();
} else { } else {
// remote CollectionInfo found for this local collection, update data // remote CollectionInfo found for this local collection, update data
CollectionInfo info = remote.get(url); JournalEntity journalEntity = remote.get(url);
App.log.fine("Updating local calendar " + url + " with " + info); App.log.fine("Updating local calendar " + url + " with " + journalEntity);
calendar.update(info, updateColors); calendar.update(journalEntity, updateColors);
// we already have a local calendar for this remote collection, don't take into consideration anymore // we already have a local calendar for this remote collection, don't take into consideration anymore
remote.remove(url); remote.remove(url);
} }
@ -139,9 +139,9 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
// create new local calendars // create new local calendars
for (String url : remote.keySet()) { for (String url : remote.keySet()) {
CollectionInfo info = remote.get(url); JournalEntity journalEntity = remote.get(url);
App.log.info("Adding local calendar list " + info); App.log.info("Adding local calendar list " + journalEntity);
LocalCalendar.create(account, provider, info); LocalCalendar.create(account, provider, journalEntity);
} }
} }
} }