mirror of
https://github.com/etesync/android
synced 2025-01-11 00:01:12 +00:00
Respect read-only flag of collections
* handle read-only information properly * don't show (clear-text) password in account settings
This commit is contained in:
parent
773b2ee992
commit
c08a0bdc43
@ -196,7 +196,7 @@ public class DavService extends Service {
|
||||
for (DavResource member : dav.members) {
|
||||
CollectionInfo info = CollectionInfo.fromDavResource(member);
|
||||
info.confirmed = true;
|
||||
App.log.fine("Found collection" + info);
|
||||
App.log.log(Level.FINE, "Found collection", info);
|
||||
|
||||
if ((serviceType.equals(Services.SERVICE_CARDDAV) && info.type == CollectionInfo.Type.ADDRESS_BOOK) ||
|
||||
(serviceType.equals(Services.SERVICE_CALDAV) && info.type == CollectionInfo.Type.CALENDAR))
|
||||
@ -323,7 +323,7 @@ public class DavService extends Service {
|
||||
|
||||
private Map<HttpUrl, CollectionInfo> readCollections() {
|
||||
Map<HttpUrl, CollectionInfo> collections = new LinkedHashMap<>();
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS, Collections.SERVICE_ID + "=?", new String[]{String.valueOf(service)}, null, null, null);
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, null, Collections.SERVICE_ID + "=?", new String[]{String.valueOf(service)}, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
ContentValues values = new ContentValues();
|
||||
DatabaseUtils.cursorRowToContentValues(cursor, values);
|
||||
|
@ -34,7 +34,7 @@ public class CollectionInfo implements Serializable {
|
||||
public enum Type {
|
||||
ADDRESS_BOOK,
|
||||
CALENDAR
|
||||
};
|
||||
}
|
||||
public Type type;
|
||||
|
||||
public String url;
|
||||
@ -73,10 +73,10 @@ public class CollectionInfo implements Serializable {
|
||||
info.type = Type.CALENDAR;
|
||||
}
|
||||
|
||||
boolean readOnly = false;
|
||||
info.readOnly = false;
|
||||
CurrentUserPrivilegeSet privilegeSet = (CurrentUserPrivilegeSet)dav.properties.get(CurrentUserPrivilegeSet.NAME);
|
||||
if (privilegeSet != null)
|
||||
readOnly = !privilegeSet.mayWriteContent;
|
||||
info.readOnly = !privilegeSet.mayWriteContent;
|
||||
|
||||
DisplayName displayName = (DisplayName)dav.properties.get(DisplayName.NAME);
|
||||
if (displayName != null && !displayName.displayName.isEmpty())
|
||||
@ -118,16 +118,17 @@ public class CollectionInfo implements Serializable {
|
||||
info.serviceID = values.getAsLong(Collections.SERVICE_ID);
|
||||
|
||||
info.url = values.getAsString(Collections.URL);
|
||||
info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0;
|
||||
info.displayName = values.getAsString(Collections.DISPLAY_NAME);
|
||||
info.description = values.getAsString(Collections.DESCRIPTION);
|
||||
|
||||
info.color = values.getAsInteger(Collections.COLOR);
|
||||
|
||||
info.timeZone = values.getAsString(Collections.TIME_ZONE);
|
||||
info.supportsVEVENT = booleanField(values, Collections.SUPPORTS_VEVENT);
|
||||
info.supportsVTODO = booleanField(values, Collections.SUPPORTS_VTODO);
|
||||
info.supportsVEVENT = getAsBooleanOrNull(values, Collections.SUPPORTS_VEVENT);
|
||||
info.supportsVTODO = getAsBooleanOrNull(values, Collections.SUPPORTS_VTODO);
|
||||
|
||||
info.selected = booleanField(values, Collections.SYNC);
|
||||
info.selected = values.getAsInteger(Collections.SYNC) != 0;
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -136,6 +137,7 @@ public class CollectionInfo implements Serializable {
|
||||
// Collections.SERVICE_ID is never changed
|
||||
|
||||
values.put(Collections.URL, url);
|
||||
values.put(Collections.READ_ONLY, readOnly ? 1 : 0);
|
||||
values.put(Collections.DISPLAY_NAME, displayName);
|
||||
values.put(Collections.DESCRIPTION, description);
|
||||
values.put(Collections.COLOR, color);
|
||||
@ -151,11 +153,9 @@ public class CollectionInfo implements Serializable {
|
||||
}
|
||||
|
||||
|
||||
private static Boolean booleanField(ContentValues values, String field) {
|
||||
private static Boolean getAsBooleanOrNull(ContentValues values, String field) {
|
||||
Integer i = values.getAsInteger(field);
|
||||
if (i == null)
|
||||
return null;
|
||||
return i != 0;
|
||||
return (i == null) ? null : (i != 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public class ServiceDB {
|
||||
ID = "_id",
|
||||
SERVICE_ID = "serviceID",
|
||||
URL = "url",
|
||||
READ_ONLY = "readOnly",
|
||||
DISPLAY_NAME = "displayName",
|
||||
DESCRIPTION = "description",
|
||||
COLOR = "color",
|
||||
@ -55,12 +56,6 @@ public class ServiceDB {
|
||||
SUPPORTS_VEVENT = "supportsVEVENT",
|
||||
SUPPORTS_VTODO = "supportsVTODO",
|
||||
SYNC = "sync";
|
||||
|
||||
public static String[] _COLUMNS = new String[] {
|
||||
ID, SERVICE_ID, URL, DISPLAY_NAME, DESCRIPTION, COLOR,
|
||||
TIME_ZONE, SUPPORTS_VEVENT, SUPPORTS_VTODO,
|
||||
SYNC
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -104,6 +99,7 @@ public class ServiceDB {
|
||||
Collections.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
Collections.SERVICE_ID + " INTEGER NOT NULL REFERENCES " + Services._TABLE +" ON DELETE CASCADE," +
|
||||
Collections.URL + " TEXT NOT NULL," +
|
||||
Collections.READ_ONLY + " INTEGER NOT NULL," +
|
||||
Collections.DISPLAY_NAME + " TEXT NULL," +
|
||||
Collections.DESCRIPTION + " TEXT NULL," +
|
||||
Collections.COLOR + " INTEGER NULL," +
|
||||
|
@ -109,7 +109,7 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
|
||||
|
||||
private Map<String, CollectionInfo> remoteCalendars(long service) {
|
||||
Map<String, CollectionInfo> collections = new LinkedHashMap<>();
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS,
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, null,
|
||||
Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VEVENT + "!=0 AND " + Collections.SYNC,
|
||||
new String[] { String.valueOf(service) }, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
|
@ -77,7 +77,7 @@ public class ContactsSyncAdapterService extends SyncAdapterService {
|
||||
|
||||
@Nullable
|
||||
private CollectionInfo remoteAddressBook(long service) {
|
||||
@Cleanup Cursor c = db.query(Collections._TABLE, Collections._COLUMNS,
|
||||
@Cleanup Cursor c = db.query(Collections._TABLE, null,
|
||||
Collections.SERVICE_ID + "=? AND " + Collections.SYNC, new String[] { String.valueOf(service) }, null, null, null);
|
||||
if (c.moveToNext()) {
|
||||
ContentValues values = new ContentValues();
|
||||
|
@ -115,7 +115,7 @@ public class TasksSyncAdapterService extends SyncAdapterService {
|
||||
|
||||
private Map<String, CollectionInfo> remoteTaskLists(long service) {
|
||||
Map<String, CollectionInfo> collections = new LinkedHashMap<>();
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS,
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, null,
|
||||
Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VTODO + "!=0 AND " + Collections.SYNC,
|
||||
new String[] { String.valueOf(service) }, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
|
@ -412,8 +412,8 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
||||
|
||||
private List<CollectionInfo> readCollections(@NonNull SQLiteDatabase db, long service) {
|
||||
List<CollectionInfo> collections = new LinkedList<>();
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS, Collections.SERVICE_ID + "=?",
|
||||
new String[]{ String.valueOf(service) }, null, null, Collections.SUPPORTS_VEVENT + " DESC," + Collections.DISPLAY_NAME);
|
||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, null, Collections.SERVICE_ID + "=?",
|
||||
new String[] { String.valueOf(service) }, null, null, Collections.SUPPORTS_VEVENT + " DESC," + Collections.DISPLAY_NAME);
|
||||
while (cursor.moveToNext()) {
|
||||
ContentValues values = new ContentValues();
|
||||
DatabaseUtils.cursorRowToContentValues(cursor, values);
|
||||
|
@ -93,7 +93,6 @@ public class AccountSettingsActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
final EditTextPreference prefPassword = (EditTextPreference)findPreference("password");
|
||||
prefPassword.setText(settings.password());
|
||||
prefPassword.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
|
Loading…
Reference in New Issue
Block a user