Display accurate sync state

This commit is contained in:
Vishnu Mohandas 2020-09-18 00:18:25 +05:30
parent 735d30583a
commit a5028c9605
2 changed files with 14 additions and 6 deletions

View file

@ -164,11 +164,18 @@ class FilesDB {
return _convertToFiles(results);
}
Future<List<File>> getFilesToBeUploaded() async {
Future<List<File>> getFilesToBeUploadedWithinFolders(
Set<String> folders) async {
final db = await instance.database;
String inParam = "";
for (final folder in folders) {
inParam += "'" + folder + "',";
}
inParam = inParam.substring(0, inParam.length - 1);
final results = await db.query(
table,
where: '$columnUploadedFileID IS NULL',
where:
'$columnUploadedFileID IS NULL AND $columnDeviceFolder IN ($inParam)',
orderBy: '$columnCreationTime DESC',
);
return _convertToFiles(results);

View file

@ -194,10 +194,11 @@ class PhotoSyncManager {
}
Future<void> _uploadDiff() async {
List<File> photosToBeUploaded = await _db.getFilesToBeUploaded();
final foldersToBackUp = Configuration.instance.getFoldersToBackUp();
for (int i = 0; i < photosToBeUploaded.length; i++) {
File file = photosToBeUploaded[i];
List<File> filesToBeUploaded =
await _db.getFilesToBeUploadedWithinFolders(foldersToBackUp);
for (int i = 0; i < filesToBeUploaded.length; i++) {
File file = filesToBeUploaded[i];
try {
if (!foldersToBackUp.contains(file.deviceFolder)) {
continue;
@ -215,7 +216,7 @@ class PhotoSyncManager {
file.encryptedPassword,
file.encryptedPasswordIV);
Bus.instance.fire(PhotoUploadEvent(
completed: i + 1, total: photosToBeUploaded.length));
completed: i + 1, total: filesToBeUploaded.length));
} catch (e) {
Bus.instance.fire(PhotoUploadEvent(hasError: true));
throw e;