@@ -77,9 +77,11 @@ final class SyncStatus {
7777 other.lastSyncedAt == lastSyncedAt &&
7878 other.hasSynced == hasSynced &&
7979 _statusEquality.equals (
80- other.priorityStatusEntries, priorityStatusEntries));
80+ other.priorityStatusEntries, priorityStatusEntries) &&
81+ other.downloadProgress == downloadProgress);
8182 }
8283
84+ // Deprecated because it can't set fields back to null
8385 @Deprecated ('Should not be used in user code' )
8486 SyncStatus copyWith ({
8587 bool ? connected,
@@ -148,19 +150,21 @@ final class SyncStatus {
148150 @override
149151 int get hashCode {
150152 return Object .hash (
151- connected,
152- downloading,
153- uploading,
154- connecting,
155- uploadError,
156- downloadError,
157- lastSyncedAt,
158- _statusEquality.hash (priorityStatusEntries));
153+ connected,
154+ downloading,
155+ uploading,
156+ connecting,
157+ uploadError,
158+ downloadError,
159+ lastSyncedAt,
160+ _statusEquality.hash (priorityStatusEntries),
161+ downloadProgress,
162+ );
159163 }
160164
161165 @override
162166 String toString () {
163- return "SyncStatus<connected: $connected connecting: $connecting downloading: $downloading uploading: $uploading lastSyncedAt: $lastSyncedAt , hasSynced: $hasSynced , error: $anyError >" ;
167+ return "SyncStatus<connected: $connected connecting: $connecting downloading: $downloading (progress: $ downloadProgress ) uploading: $uploading lastSyncedAt: $lastSyncedAt , hasSynced: $hasSynced , error: $anyError >" ;
164168 }
165169
166170 // This should be a ListEquality<SyncPriorityStatus>, but that appears to
@@ -266,11 +270,14 @@ final class InternalSyncDownloadProgress {
266270 /// Sums the total target and completed operations for all buckets up until
267271 /// the given [priority] (inclusive).
268272 (int , int ) targetAndCompletedCounts (BucketPriority priority) {
269- return buckets.values.fold ((0 , 0 ), (prev, entry) {
270- final downloaded = entry.sinceLast;
271- final total = entry.targetCount - entry.atLast;
272- return (prev.$1 + total, prev.$2 + downloaded);
273- });
273+ return buckets.values.where ((e) => e.priority >= priority).fold (
274+ (0 , 0 ),
275+ (prev, entry) {
276+ final downloaded = entry.sinceLast;
277+ final total = entry.targetCount - entry.atLast;
278+ return (prev.$1 + total, prev.$2 + downloaded);
279+ },
280+ );
274281 }
275282
276283 InternalSyncDownloadProgress incrementDownloaded (SyncDataBatch batch) {
@@ -280,7 +287,7 @@ final class InternalSyncDownloadProgress {
280287 newBucketStates[dataForBucket.bucket] = (
281288 priority: previous.priority,
282289 atLast: previous.atLast,
283- sinceLast: previous.sinceLast,
290+ sinceLast: previous.sinceLast + dataForBucket.data.length ,
284291 targetCount: previous.targetCount,
285292 );
286293 }
@@ -304,6 +311,13 @@ final class InternalSyncDownloadProgress {
304311 _mapEquality.equals (buckets, other.buckets);
305312 }
306313
314+ @override
315+ String toString () {
316+ final asView = asSyncDownloadProgress;
317+ final all = asView.untilCompletion;
318+ return 'for total: ${all .completed } / ${all .total }' ;
319+ }
320+
307321 static const _mapEquality = MapEquality <Object ?, Object ?>();
308322}
309323
0 commit comments