2020-08-14 18:07:27 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:photo_gallery/photo_gallery.dart';
|
|
|
|
|
|
|
|
class Generator {
|
2020-08-22 16:59:52 +08:00
|
|
|
static dynamic generateAlbumsJson({MediumType mediumType}) {
|
2020-08-14 18:07:27 +08:00
|
|
|
mediumType = mediumType ?? MediumType.image;
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
"id": "__ALL__",
|
|
|
|
"mediumType": mediumTypeToJson(mediumType),
|
|
|
|
"name": "All",
|
|
|
|
"count": 5,
|
|
|
|
},
|
|
|
|
{
|
2020-08-18 16:41:24 +08:00
|
|
|
"id": "AlbumId",
|
2020-08-14 18:07:27 +08:00
|
|
|
"mediumType": mediumTypeToJson(mediumType),
|
2020-08-22 16:59:52 +08:00
|
|
|
"name": "AlbumName",
|
2020-08-14 18:07:27 +08:00
|
|
|
"count": 5,
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-22 16:59:52 +08:00
|
|
|
static List<Album> generateAlbums({MediumType mediumType}) {
|
|
|
|
return Generator.generateAlbumsJson(mediumType: mediumType)
|
2020-08-14 18:07:27 +08:00
|
|
|
.map<Album>((x) => Album.fromJson(x))
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
static dynamic generateMediaPageJson({
|
2020-08-18 16:41:24 +08:00
|
|
|
String albumId,
|
2020-08-14 18:07:27 +08:00
|
|
|
MediumType mediumType,
|
|
|
|
int total,
|
|
|
|
int skip,
|
|
|
|
int take,
|
|
|
|
}) {
|
|
|
|
skip = skip ?? 0;
|
|
|
|
take = take ?? (total - skip);
|
|
|
|
|
|
|
|
var items = [];
|
|
|
|
int index = skip;
|
|
|
|
while (index < skip + take) {
|
|
|
|
items.add(generateMediaJson(
|
|
|
|
mediumId: index.toString(), mediumType: mediumType));
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
"start": skip,
|
|
|
|
"total": total,
|
|
|
|
"items": items,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static dynamic generateMediaJson({
|
|
|
|
String mediumId,
|
|
|
|
MediumType mediumType,
|
|
|
|
}) {
|
|
|
|
return {
|
|
|
|
"id": mediumId,
|
|
|
|
"mediumType": mediumTypeToJson(mediumType),
|
|
|
|
"width": 512,
|
|
|
|
"height": 512,
|
|
|
|
"creationDate": DateTime(2020, 8, 1).millisecondsSinceEpoch,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static MediaPage generateMediaPage({
|
2020-08-22 16:59:52 +08:00
|
|
|
Album album,
|
2020-08-14 18:07:27 +08:00
|
|
|
MediumType mediumType,
|
|
|
|
int skip,
|
|
|
|
int take,
|
|
|
|
}) {
|
|
|
|
dynamic json = generateMediaPageJson(
|
2020-08-22 16:59:52 +08:00
|
|
|
albumId: album.id,
|
2020-08-14 18:07:27 +08:00
|
|
|
mediumType: mediumType,
|
2020-08-22 16:59:52 +08:00
|
|
|
total: album.count,
|
2020-08-14 18:07:27 +08:00
|
|
|
skip: skip,
|
|
|
|
take: take,
|
|
|
|
);
|
2020-08-22 16:59:52 +08:00
|
|
|
return MediaPage.fromJson(album, json);
|
2020-08-14 18:07:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Medium generateMedia({
|
|
|
|
String mediumId,
|
|
|
|
MediumType mediumType,
|
|
|
|
}) {
|
|
|
|
return Medium.fromJson(
|
|
|
|
generateMediaJson(mediumId: mediumId, mediumType: mediumType),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static List<int> generateMockThumbnail({
|
|
|
|
String mediumId,
|
|
|
|
MediumType mediumType,
|
|
|
|
}) {
|
|
|
|
return [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
|
}
|
|
|
|
|
2020-08-22 16:59:52 +08:00
|
|
|
static List<int> generateMockAlbumThumbnail({
|
2020-08-18 16:41:24 +08:00
|
|
|
String albumId,
|
2020-08-14 18:07:27 +08:00
|
|
|
}) {
|
|
|
|
return [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
|
}
|
|
|
|
|
|
|
|
static String generateFilePath({
|
|
|
|
String mediumId,
|
|
|
|
MediumType mediumType,
|
|
|
|
}) {
|
|
|
|
return "/path/to/file";
|
|
|
|
}
|
|
|
|
|
|
|
|
static File generateFile({
|
|
|
|
String mediumId,
|
|
|
|
MediumType mediumType,
|
|
|
|
}) {
|
|
|
|
return File(generateFilePath(mediumId: mediumId, mediumType: mediumType));
|
|
|
|
}
|
|
|
|
}
|