1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +00:00

Add support for read-only journals.

This change only works for calendars at the moment, because we don't have shared
address books anyway.
This is currently only implemented in the client, and only as a read-only attribute,
you can't make a journal read-only yet. This requires server support that is not yet
there, but it's better to be ready for this sooner rather than later.
This commit is contained in:
Tom Hacohen 2017-04-21 11:19:10 +01:00
parent df3db6b357
commit 1ab32be0f6
7 changed files with 10 additions and 7 deletions

View File

@ -228,7 +228,7 @@ public class App extends Application {
public EntityDataStore<Persistable> getData() { public EntityDataStore<Persistable> getData() {
if (dataStore == null) { if (dataStore == null) {
// override onUpgrade to handle migrating to a new version // override onUpgrade to handle migrating to a new version
DatabaseSource source = new MyDatabaseSource(this, Models.DEFAULT, 3); DatabaseSource source = new MyDatabaseSource(this, Models.DEFAULT, 4);
Configuration configuration = source.getConfiguration(); Configuration configuration = source.getConfiguration();
dataStore = new EntityDataStore<>(configuration); dataStore = new EntityDataStore<>(configuration);
} }

View File

@ -137,6 +137,9 @@ public class JournalManager extends BaseManager {
@Getter @Getter
private int version = -1; private int version = -1;
@Getter
private boolean readOnly = false;
private transient byte[] hmac = null; private transient byte[] hmac = null;
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -43,8 +43,6 @@ public class CollectionInfo implements Serializable {
public String uid; public String uid;
@Expose
public boolean readOnly;
@Expose @Expose
public String displayName, description; public String displayName, description;
@Expose @Expose
@ -64,7 +62,6 @@ public class CollectionInfo implements Serializable {
CollectionInfo info = new CollectionInfo(); CollectionInfo info = new CollectionInfo();
info.displayName = "Default"; info.displayName = "Default";
info.selected = true; info.selected = true;
info.readOnly = false;
info.type = service; info.type = service;
return info; return info;
@ -85,7 +82,6 @@ public class CollectionInfo implements Serializable {
info.serviceID = values.getAsInteger(Collections.SERVICE_ID); info.serviceID = values.getAsInteger(Collections.SERVICE_ID);
info.uid = values.getAsString(Collections.URL); info.uid = values.getAsString(Collections.URL);
info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0;
info.displayName = values.getAsString(Collections.DISPLAY_NAME); info.displayName = values.getAsString(Collections.DISPLAY_NAME);
info.description = values.getAsString(Collections.DESCRIPTION); info.description = values.getAsString(Collections.DESCRIPTION);

View File

@ -47,6 +47,9 @@ public class JournalModel {
boolean deleted; boolean deleted;
@Column(value = "false")
boolean readOnly;
@PostLoad @PostLoad
void afterLoad() { void afterLoad() {
this.info.serviceID = this.serviceModel.id; this.info.serviceID = this.serviceModel.id;

View File

@ -103,7 +103,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
if (withColor) if (withColor)
values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor); values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor);
if (info.readOnly) if (journalEntity.isReadOnly())
values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ); values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
else { else {
values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER); values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);

View File

@ -198,6 +198,7 @@ public abstract class SyncAdapterService extends Service {
JournalEntity journalEntity = JournalEntity.fetchOrCreate(data, collection); JournalEntity journalEntity = JournalEntity.fetchOrCreate(data, collection);
journalEntity.setOwner(journal.getOwner()); journalEntity.setOwner(journal.getOwner());
journalEntity.setEncryptedKey(journal.getKey()); journalEntity.setEncryptedKey(journal.getKey());
journalEntity.setReadOnly(journal.isReadOnly());
journalEntity.setDeleted(false); journalEntity.setDeleted(false);
data.upsert(journalEntity); data.upsert(journalEntity);

View File

@ -414,7 +414,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
} }
View readOnly = v.findViewById(R.id.read_only); View readOnly = v.findViewById(R.id.read_only);
readOnly.setVisibility(info.readOnly ? View.VISIBLE : View.GONE); readOnly.setVisibility(journalEntity.isReadOnly() ? View.VISIBLE : View.GONE);
final View shared = v.findViewById(R.id.shared); final View shared = v.findViewById(R.id.shared);
shared.setVisibility(account.name.equals(journalEntity.getOwner()) ? View.GONE : View.VISIBLE); shared.setVisibility(account.name.equals(journalEntity.getOwner()) ? View.GONE : View.VISIBLE);