Fix the serialziation logic for CollectionType

This commit is contained in:
Vishnu Mohandas 2020-10-13 00:44:23 +05:30
parent 13715c924c
commit b8586e31e0
2 changed files with 17 additions and 6 deletions

View file

@ -52,7 +52,7 @@ class CollectionsDB {
$columnType TEXT NOT NULL,
$columnEncryptedPath TEXT,
$columnPathDecryptionNonce TEXT,
$columnCreationTime TEXT NOT NULL,
$columnCreationTime TEXT NOT NULL
)
''');
}
@ -98,7 +98,7 @@ class CollectionsDB {
row[columnEncryptedKey] = collection.encryptedKey;
row[columnKeyDecryptionNonce] = collection.keyDecryptionNonce;
row[columnName] = collection.name;
row[columnType] = collection.type;
row[columnType] = typeToString(collection.type);
row[columnEncryptedPath] = collection.encryptedPath;
row[columnPathDecryptionNonce] = collection.pathDecryptionNonce;
row[columnCreationTime] = collection.creationTime;
@ -112,7 +112,7 @@ class CollectionsDB {
row[columnEncryptedKey],
row[columnKeyDecryptionNonce],
row[columnName],
row[columnType],
typeFromString(row[columnType]),
row[columnEncryptedPath],
row[columnPathDecryptionNonce],
int.parse(row[columnCreationTime]),

View file

@ -65,7 +65,7 @@ class Collection {
'encryptedKey': encryptedKey,
'keyDecryptionNonce': keyDecryptionNonce,
'name': name,
'type': type.toString(),
'type': typeToString(type),
'creationTime': creationTime,
'encryptedPath': encryptedPath,
'pathDecryptionNonce': pathDecryptionNonce,
@ -82,7 +82,7 @@ class Collection {
map['encryptedKey'],
map['keyDecryptionNonce'],
map['name'],
fromString(map['type']),
typeFromString(map['type']),
map['encryptedPath'],
map['pathDecryptionNonce'],
map['creationTime'],
@ -132,7 +132,7 @@ class Collection {
}
}
CollectionType fromString(String type) {
CollectionType typeFromString(String type) {
switch (type) {
case "folder":
return CollectionType.folder;
@ -142,6 +142,17 @@ CollectionType fromString(String type) {
return CollectionType.album;
}
String typeToString(CollectionType type) {
switch (type) {
case CollectionType.folder:
return "folder";
case CollectionType.favorites:
return "favorites";
default:
return "album";
}
}
enum CollectionType {
folder,
favorites,