Only show deviceFolder on UI if coverFile is found
This commit is contained in:
parent
718fcdf6cb
commit
decbfe0145
|
@ -3,6 +3,7 @@ import 'package:logging/logging.dart';
|
|||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/file_load_result.dart';
|
||||
import 'package:photos/services/local/local_sync_util.dart';
|
||||
import 'package:sqflite/sqlite_api.dart';
|
||||
|
@ -283,15 +284,22 @@ extension DeviceFiles on FilesDB {
|
|||
return FileLoadResult(files, files.length == limit);
|
||||
}
|
||||
|
||||
Future<List<DeviceCollection>> getDeviceCollections() async {
|
||||
debugPrint("Fetching DeviceCollections From DB");
|
||||
Future<List<DeviceCollection>> getDeviceCollections({
|
||||
bool includeCoverThumbnail = false,
|
||||
}) async {
|
||||
debugPrint(
|
||||
"Fetching DeviceCollections From DB with thumnail = $includeCoverThumbnail");
|
||||
try {
|
||||
final db = await database;
|
||||
final fileRows = await db.rawQuery(
|
||||
'''SELECT * FROM FILES where local_id in (select cover_id from device_collections) group by local_id;
|
||||
final coverFiles = <File>[];
|
||||
if (includeCoverThumbnail) {
|
||||
final fileRows = await db.rawQuery(
|
||||
'''SELECT * FROM FILES where local_id in (select cover_id from device_collections) group by local_id;
|
||||
''',
|
||||
);
|
||||
final files = convertToFiles(fileRows);
|
||||
);
|
||||
final files = convertToFiles(fileRows);
|
||||
coverFiles.addAll(files);
|
||||
}
|
||||
final deviceCollectionRows = await db.rawQuery(
|
||||
'''SELECT * from device_collections''',
|
||||
);
|
||||
|
@ -305,11 +313,19 @@ extension DeviceFiles on FilesDB {
|
|||
coverId: row["cover_id"],
|
||||
shouldBackup: (row["should_backup"] ?? _sqlBoolFalse) == _sqlBoolTrue,
|
||||
);
|
||||
deviceCollection.thumbnail = files.firstWhere(
|
||||
(element) => element.localID == deviceCollection.coverId,
|
||||
orElse: () => null,
|
||||
);
|
||||
deviceCollections.add(deviceCollection);
|
||||
if (includeCoverThumbnail) {
|
||||
deviceCollection.thumbnail = coverFiles.firstWhere(
|
||||
(element) => element.localID == deviceCollection.coverId,
|
||||
orElse: () => null,
|
||||
);
|
||||
if (deviceCollection.thumbnail == null) {
|
||||
_logger.warning(
|
||||
'Failed to find coverThum for ${deviceCollection.name}');
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
deviceCollections.add(deviceCollection);
|
||||
}
|
||||
}
|
||||
return deviceCollections;
|
||||
} catch (e) {
|
||||
|
|
|
@ -41,7 +41,9 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
FilesDB.instance.getDeviceCollections().then((files) async {
|
||||
FilesDB.instance
|
||||
.getDeviceCollections(includeCoverThumbnail: true)
|
||||
.then((files) async {
|
||||
_pathIDToItemCount =
|
||||
await FilesDB.instance.getDevicePathIDToImportedFileCount();
|
||||
setState(() {
|
||||
|
|
|
@ -93,7 +93,7 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
final userID = Configuration.instance.getUserID();
|
||||
final List<DeviceFolder> folders = [];
|
||||
final List<DeviceCollection> deviceCollections =
|
||||
await filesDB.getDeviceCollections();
|
||||
await filesDB.getDeviceCollections(includeCoverThumbnail: true);
|
||||
final latestLocalFiles = await filesDB.getLatestLocalFiles();
|
||||
for (final file in latestLocalFiles) {
|
||||
folders.add(DeviceFolder(file.deviceFolder, file.deviceFolder, file));
|
||||
|
|
Loading…
Reference in a new issue