Only show deviceFolder on UI if coverFile is found

This commit is contained in:
Neeraj Gupta 2022-09-01 01:20:11 +05:30
parent 718fcdf6cb
commit decbfe0145
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 31 additions and 13 deletions

View file

@ -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) {

View file

@ -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(() {

View file

@ -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));