@@ -77,9 +77,11 @@ final class SyncStatus {
77
77
other.lastSyncedAt == lastSyncedAt &&
78
78
other.hasSynced == hasSynced &&
79
79
_statusEquality.equals (
80
- other.priorityStatusEntries, priorityStatusEntries));
80
+ other.priorityStatusEntries, priorityStatusEntries) &&
81
+ other.downloadProgress == downloadProgress);
81
82
}
82
83
84
+ // Deprecated because it can't set fields back to null
83
85
@Deprecated ('Should not be used in user code' )
84
86
SyncStatus copyWith ({
85
87
bool ? connected,
@@ -148,19 +150,21 @@ final class SyncStatus {
148
150
@override
149
151
int get hashCode {
150
152
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
+ );
159
163
}
160
164
161
165
@override
162
166
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 >" ;
164
168
}
165
169
166
170
// This should be a ListEquality<SyncPriorityStatus>, but that appears to
@@ -266,11 +270,14 @@ final class InternalSyncDownloadProgress {
266
270
/// Sums the total target and completed operations for all buckets up until
267
271
/// the given [priority] (inclusive).
268
272
(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
+ );
274
281
}
275
282
276
283
InternalSyncDownloadProgress incrementDownloaded (SyncDataBatch batch) {
@@ -280,7 +287,7 @@ final class InternalSyncDownloadProgress {
280
287
newBucketStates[dataForBucket.bucket] = (
281
288
priority: previous.priority,
282
289
atLast: previous.atLast,
283
- sinceLast: previous.sinceLast,
290
+ sinceLast: previous.sinceLast + dataForBucket.data.length ,
284
291
targetCount: previous.targetCount,
285
292
);
286
293
}
@@ -304,6 +311,13 @@ final class InternalSyncDownloadProgress {
304
311
_mapEquality.equals (buckets, other.buckets);
305
312
}
306
313
314
+ @override
315
+ String toString () {
316
+ final asView = asSyncDownloadProgress;
317
+ final all = asView.untilCompletion;
318
+ return 'for total: ${all .completed } / ${all .total }' ;
319
+ }
320
+
307
321
static const _mapEquality = MapEquality <Object ?, Object ?>();
308
322
}
309
323
0 commit comments