Преглед изворни кода

Fix the serialziation logic for CollectionType

Vishnu Mohandas пре 4 година
родитељ
комит
b8586e31e0
2 измењених фајлова са 17 додато и 6 уклоњено
  1. 3 3
      lib/db/collections_db.dart
  2. 14 3
      lib/models/collection.dart

+ 3 - 3
lib/db/collections_db.dart

@@ -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]),

+ 14 - 3
lib/models/collection.dart

@@ -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,