ente/lib/models/folder.dart

68 lines
1.4 KiB
Dart
Raw Normal View History

2020-05-17 20:39:21 +00:00
import 'dart:convert';
2020-06-19 23:03:26 +00:00
import 'package:photos/models/file.dart';
2020-05-17 20:39:21 +00:00
2020-05-17 12:39:38 +00:00
class Folder {
2020-05-17 20:39:21 +00:00
final int id;
2020-05-17 12:39:38 +00:00
final String name;
final String owner;
final String deviceFolder;
2020-05-22 18:22:55 +00:00
final Set<String> sharedWith;
final int updationTime;
2020-06-19 23:03:26 +00:00
File thumbnailPhoto;
2020-05-17 12:39:38 +00:00
2020-05-17 19:35:57 +00:00
Folder(
2020-05-17 20:39:21 +00:00
this.id,
2020-05-17 19:35:57 +00:00
this.name,
this.owner,
this.deviceFolder,
this.sharedWith,
this.updationTime,
2020-05-17 19:35:57 +00:00
);
static Folder fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return Folder(
2020-05-17 20:39:21 +00:00
map['id'],
2020-06-01 20:47:13 +00:00
map['owner'] + "'s " + map['deviceFolder'],
2020-05-17 19:35:57 +00:00
map['owner'],
map['deviceFolder'],
2020-05-22 18:22:55 +00:00
Set<String>.from(map['sharedWith']),
map['updationTime'],
2020-05-17 19:35:57 +00:00
);
}
@override
String toString() {
return 'Folder(id: $id, name: $name, owner: $owner, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updationTime: $updationTime)';
2020-05-17 20:39:21 +00:00
}
Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'owner': owner,
'deviceFolder': deviceFolder,
2020-05-22 18:22:55 +00:00
'sharedWith': sharedWith.toList(),
'updationTime': updationTime,
2020-05-17 20:39:21 +00:00
};
}
String toJson() => json.encode(toMap());
static Folder fromJson(String source) => fromMap(json.decode(source));
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
2020-06-01 20:59:07 +00:00
return o is Folder && o.id == id;
2020-05-17 20:39:21 +00:00
}
@override
int get hashCode {
2020-06-01 20:59:07 +00:00
return id.hashCode;
2020-05-17 19:35:57 +00:00
}
2020-05-17 12:39:38 +00:00
}