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