Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] refactor

Neeraj Guptaeb2f6aec689d
diff --git a/mobile/lib/db/collections_db.dart b/mobile/lib/db/collections_db.dart
index e9597c62ca..c73b9a8e35 100644
--- a/mobile/lib/db/collections_db.dart
+++ b/mobile/lib/db/collections_db.dart
@@ -257,7 +257,7 @@ class CollectionsDB {
row[columnName] = collection.name;
row[columnEncryptedName] = collection.encryptedName;
row[columnNameDecryptionNonce] = collection.nameDecryptionNonce;
- row[columnType] = Collection.typeToString(collection.type);
+ row[columnType] = typeToString(collection.type);
row[columnEncryptedPath] = collection.attributes.encryptedPath;
row[columnPathDecryptionNonce] = collection.attributes.pathDecryptionNonce;
row[columnVersion] = collection.attributes.version;
@@ -290,7 +290,7 @@ class CollectionsDB {
row[columnName],
row[columnEncryptedName],
row[columnNameDecryptionNonce],
- Collection.typeFromString(row[columnType]),
+ typeFromString(row[columnType]),
CollectionAttributes(
encryptedPath: row[columnEncryptedPath],
pathDecryptionNonce: row[columnPathDecryptionNonce],
diff --git a/mobile/lib/models/api/collection/create_request.dart b/mobile/lib/models/api/collection/create_request.dart
index 24bf0a9b0f..0fc5866383 100644
--- a/mobile/lib/models/api/collection/create_request.dart
+++ b/mobile/lib/models/api/collection/create_request.dart
@@ -45,7 +45,7 @@ class CreateRequest {
map['keyDecryptionNonce'] = keyDecryptionNonce;
map['encryptedName'] = encryptedName;
map['nameDecryptionNonce'] = nameDecryptionNonce;
- map['type'] = Collection.typeToString(type);
+ map['type'] = typeToString(type);
if (attributes != null) {
map['attributes'] = attributes!.toMap();
}
diff --git a/mobile/lib/models/collection/collection.dart b/mobile/lib/models/collection/collection.dart
index 2330da3aa9..c62c9432d5 100644
--- a/mobile/lib/models/collection/collection.dart
+++ b/mobile/lib/models/collection/collection.dart
@@ -180,38 +180,6 @@ class Collection {
sharees.addAll(newSharees);
}
- static CollectionType typeFromString(String type) {
- switch (type) {
- case "folder":
- return CollectionType.folder;
- case "favorites":
- return CollectionType.favorites;
- case "uncategorized":
- return CollectionType.uncategorized;
- case "album":
- return CollectionType.album;
- case "unknown":
- return CollectionType.unknown;
- }
- debugPrint("unexpected collection type $type");
- return CollectionType.unknown;
- }
-
- static String typeToString(CollectionType type) {
- switch (type) {
- case CollectionType.folder:
- return "folder";
- case CollectionType.favorites:
- return "favorites";
- case CollectionType.album:
- return "album";
- case CollectionType.uncategorized:
- return "uncategorized";
- case CollectionType.unknown:
- return "unknown";
- }
- }
-
Collection copyWith({
int? id,
User? owner,
@@ -294,6 +262,38 @@ enum CollectionType {
unknown,
}
+CollectionType typeFromString(String type) {
+ switch (type) {
+ case "folder":
+ return CollectionType.folder;
+ case "favorites":
+ return CollectionType.favorites;
+ case "uncategorized":
+ return CollectionType.uncategorized;
+ case "album":
+ return CollectionType.album;
+ case "unknown":
+ return CollectionType.unknown;
+ }
+ debugPrint("unexpected collection type $type");
+ return CollectionType.unknown;
+}
+
+String typeToString(CollectionType type) {
+ switch (type) {
+ case CollectionType.folder:
+ return "folder";
+ case CollectionType.favorites:
+ return "favorites";
+ case CollectionType.album:
+ return "album";
+ case CollectionType.uncategorized:
+ return "uncategorized";
+ case CollectionType.unknown:
+ return "unknown";
+ }
+}
+
extension CollectionTypeExtn on CollectionType {
bool get canDelete =>
this != CollectionType.favorites && this != CollectionType.uncategorized;