Sort albums in the order in which they were updated
This commit is contained in:
parent
af01dbe610
commit
6e02cae865
5 changed files with 67 additions and 13 deletions
|
@ -325,6 +325,22 @@ class FilesDB {
|
|||
}
|
||||
}
|
||||
|
||||
Future<File> getLastModifiedFileInCollection(int collectionID) async {
|
||||
final db = await instance.database;
|
||||
final rows = await db.query(
|
||||
table,
|
||||
where: '$columnCollectionID =?',
|
||||
whereArgs: [collectionID],
|
||||
orderBy: '$columnUpdationTime DESC',
|
||||
limit: 1,
|
||||
);
|
||||
if (rows.isNotEmpty) {
|
||||
return _getFileFromRow(rows[0]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<File> _convertToFiles(List<Map<String, dynamic>> results) {
|
||||
final files = List<File>();
|
||||
for (final result in results) {
|
||||
|
|
|
@ -12,6 +12,11 @@ class CollectionItems {
|
|||
class CollectionWithThumbnail {
|
||||
final Collection collection;
|
||||
final File thumbnail;
|
||||
final File lastUpdatedFile;
|
||||
|
||||
CollectionWithThumbnail(this.collection, this.thumbnail);
|
||||
CollectionWithThumbnail(
|
||||
this.collection,
|
||||
this.thumbnail,
|
||||
this.lastUpdatedFile,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -131,21 +131,36 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
|
|||
return second.creationTime.compareTo(first.creationTime);
|
||||
});
|
||||
if (favorites.length > 0) {
|
||||
final favoritesCollection =
|
||||
await FavoritesService.instance.getFavoritesCollection();
|
||||
final lastUpdatedFile = await FilesDB.instance
|
||||
.getLastModifiedFileInCollection(favoritesCollection.id);
|
||||
collectionsWithThumbnail.add(CollectionWithThumbnail(
|
||||
await FavoritesService.instance.getFavoritesCollection(),
|
||||
favorites[0]));
|
||||
favoritesCollection, favorites[0], lastUpdatedFile));
|
||||
}
|
||||
final collections = CollectionsService.instance.getCollections();
|
||||
|
||||
for (final c in collections) {
|
||||
if (c.ownerID != Configuration.instance.getUserID()) {
|
||||
continue;
|
||||
}
|
||||
var thumbnail = await FilesDB.instance.getLatestFileInCollection(c.id);
|
||||
final thumbnail = await FilesDB.instance.getLatestFileInCollection(c.id);
|
||||
if (thumbnail == null) {
|
||||
continue;
|
||||
}
|
||||
collectionsWithThumbnail.add(CollectionWithThumbnail(c, thumbnail));
|
||||
final lastUpdatedFile =
|
||||
await FilesDB.instance.getLastModifiedFileInCollection(c.id);
|
||||
collectionsWithThumbnail.add(CollectionWithThumbnail(
|
||||
c,
|
||||
thumbnail,
|
||||
lastUpdatedFile,
|
||||
));
|
||||
}
|
||||
collectionsWithThumbnail.sort((first, second) {
|
||||
return second.lastUpdatedFile.updationTime
|
||||
.compareTo(first.lastUpdatedFile.updationTime);
|
||||
});
|
||||
|
||||
return CollectionItems(folders, collectionsWithThumbnail);
|
||||
}
|
||||
|
||||
|
|
|
@ -153,8 +153,18 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|||
if (thumbnail == null) {
|
||||
continue;
|
||||
}
|
||||
collectionsWithThumbnail.add(CollectionWithThumbnail(c, thumbnail));
|
||||
final lastUpdatedFile =
|
||||
await FilesDB.instance.getLastModifiedFileInCollection(c.id);
|
||||
collectionsWithThumbnail.add(CollectionWithThumbnail(
|
||||
c,
|
||||
thumbnail,
|
||||
lastUpdatedFile,
|
||||
));
|
||||
}
|
||||
collectionsWithThumbnail.sort((first, second) {
|
||||
return second.lastUpdatedFile.updationTime
|
||||
.compareTo(first.lastUpdatedFile.updationTime);
|
||||
});
|
||||
return collectionsWithThumbnail;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,15 +46,23 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery> {
|
|||
if (collection.ownerID == Configuration.instance.getUserID()) {
|
||||
continue;
|
||||
}
|
||||
var thumbnail;
|
||||
try {
|
||||
thumbnail =
|
||||
await FilesDB.instance.getLatestFileInCollection(collection.id);
|
||||
} catch (e) {
|
||||
_logger.warning(e.toString());
|
||||
final thumbnail =
|
||||
await FilesDB.instance.getLatestFileInCollection(collection.id);
|
||||
if (thumbnail == null) {
|
||||
continue;
|
||||
}
|
||||
c.add(CollectionWithThumbnail(collection, thumbnail));
|
||||
final lastUpdatedFile = await FilesDB.instance
|
||||
.getLastModifiedFileInCollection(collection.id);
|
||||
c.add(CollectionWithThumbnail(
|
||||
collection,
|
||||
thumbnail,
|
||||
lastUpdatedFile,
|
||||
));
|
||||
}
|
||||
c.sort((first, second) {
|
||||
return second.lastUpdatedFile.updationTime
|
||||
.compareTo(first.lastUpdatedFile.updationTime);
|
||||
});
|
||||
return c;
|
||||
}),
|
||||
builder: (context, snapshot) {
|
||||
|
|
Loading…
Add table
Reference in a new issue