Skip to content

Commit f219610

Browse files
authored
Merge pull request #334 from fluttercommunity/revert-285-master
Revert "Make download progress step size configurable, not just every 10%."
2 parents 3d8af80 + cd5db7d commit f219610

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

android/src/main/java/vn/hunghd/flutterdownloader/DownloadWorker.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public class DownloadWorker extends Worker implements MethodChannel.MethodCallHa
6666
public static final String ARG_OPEN_FILE_FROM_NOTIFICATION = "open_file_from_notification";
6767
public static final String ARG_CALLBACK_HANDLE = "callback_handle";
6868
public static final String ARG_DEBUG = "debug";
69-
public static final String ARG_STEP_UPDATE = "step_update";
7069

7170
private static final String TAG = DownloadWorker.class.getSimpleName();
7271
private static final int BUFFER_SIZE = 4096;
7372
private static final String CHANNEL_ID = "FLUTTER_DOWNLOADER_NOTIFICATION";
73+
private static final int STEP_UPDATE = 10;
7474

7575
private static final AtomicBoolean isolateStarted = new AtomicBoolean(false);
7676
private static final ArrayDeque<List> isolateQueue = new ArrayDeque<>();
@@ -88,7 +88,6 @@ public class DownloadWorker extends Worker implements MethodChannel.MethodCallHa
8888
private int lastProgress = 0;
8989
private int primaryId;
9090
private String msgStarted, msgInProgress, msgCanceled, msgFailed, msgPaused, msgComplete;
91-
private int stepUpdate;
9291

9392
public DownloadWorker(@NonNull final Context context,
9493
@NonNull WorkerParameters params) {
@@ -167,7 +166,6 @@ public Result doWork() {
167166
String headers = getInputData().getString(ARG_HEADERS);
168167
boolean isResume = getInputData().getBoolean(ARG_IS_RESUME, false);
169168
debug = getInputData().getBoolean(ARG_DEBUG, false);
170-
stepUpdate = getInputData().getInt(ARG_STEP_UPDATE, 10);
171169

172170
Resources res = getApplicationContext().getResources();
173171
msgStarted = res.getString(R.string.flutter_downloader_notification_started);
@@ -339,7 +337,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
339337
int progress = (int) ((count * 100) / (contentLength + downloadedBytes));
340338
outputStream.write(buffer, 0, bytesRead);
341339

342-
if ((lastProgress == 0 || progress > (lastProgress + stepUpdate) || progress == 100)
340+
if ((lastProgress == 0 || progress > lastProgress + STEP_UPDATE || progress == 100)
343341
&& progress != lastProgress) {
344342
lastProgress = progress;
345343
updateNotification(context, filename, DownloadStatus.RUNNING, progress, null);

android/src/main/java/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class FlutterDownloaderPlugin implements MethodCallHandler, FlutterPlugin
4343
private TaskDao taskDao;
4444
private Context context;
4545
private long callbackHandle;
46-
private int stepUpdate;
4746
private int debugMode;
4847
private final Object initializationLock = new Object();
4948

@@ -130,7 +129,6 @@ private WorkRequest buildRequest(String url, String savedDir, String filename, S
130129
.putBoolean(DownloadWorker.ARG_OPEN_FILE_FROM_NOTIFICATION, openFileFromNotification)
131130
.putBoolean(DownloadWorker.ARG_IS_RESUME, isResume)
132131
.putLong(DownloadWorker.ARG_CALLBACK_HANDLE, callbackHandle)
133-
.putInt(DownloadWorker.ARG_STEP_UPDATE, stepUpdate)
134132
.putBoolean(DownloadWorker.ARG_DEBUG, debugMode == 1)
135133
.build()
136134
)
@@ -160,7 +158,6 @@ private void initialize(MethodCall call, MethodChannel.Result result) {
160158
private void registerCallback(MethodCall call, MethodChannel.Result result) {
161159
List args = (List) call.arguments;
162160
callbackHandle = Long.parseLong(args.get(0).toString());
163-
stepUpdate = Integer.parseInt(args.get(1).toString());
164161
result.success(null);
165162
}
166163

ios/Classes/FlutterDownloaderPlugin.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define ERROR_NOT_INITIALIZED [FlutterError errorWithCode:@"not_initialized" message:@"initialize() must called first" details:nil]
3030
#define ERROR_INVALID_TASK_ID [FlutterError errorWithCode:@"invalid_task_id" message:@"not found task corresponding to given task id" details:nil]
3131

32+
#define STEP_UPDATE 10
33+
3234
@interface FlutterDownloaderPlugin()<NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate, UIDocumentInteractionControllerDelegate>
3335
{
3436
FlutterEngine *_headlessRunner;
@@ -41,7 +43,6 @@ @interface FlutterDownloaderPlugin()<NSURLSessionTaskDelegate, NSURLSessionDownl
4143
NSString *_allFilesDownloadedMsg;
4244
NSMutableArray *_eventQueue;
4345
int64_t _callbackHandle;
44-
int _stepUpdate;
4546
}
4647

4748
@property(nonatomic, strong) dispatch_queue_t databaseQueue;
@@ -558,7 +559,6 @@ - (void)didInitializeDispatcherMethodCall:(FlutterMethodCall*)call result:(Flutt
558559
- (void)registerCallbackMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
559560
NSArray *arguments = call.arguments;
560561
_callbackHandle = [arguments[0] longLongValue];
561-
_stepUpdate = [arguments[1] intValue];
562562
result([NSNull null]);
563563
}
564564

@@ -860,7 +860,7 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
860860
NSString *taskId = [self identifierForTask:downloadTask];
861861
int progress = round(totalBytesWritten * 100 / (double)totalBytesExpectedToWrite);
862862
NSNumber *lastProgress = _runningTaskById[taskId][KEY_PROGRESS];
863-
if (([lastProgress intValue] == 0 || (progress > ([lastProgress intValue] + _stepUpdate)) || progress == 100) && progress != [lastProgress intValue]) {
863+
if (([lastProgress intValue] == 0 || (progress > [lastProgress intValue] + STEP_UPDATE) || progress == 100) && progress != [lastProgress intValue]) {
864864
[self sendUpdateProgressForTaskId:taskId inStatus:@(STATUS_RUNNING) andProgress:@(progress)];
865865
_runningTaskById[taskId][KEY_PROGRESS] = @(progress);
866866
}

lib/src/downloader.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,13 @@ class FlutterDownloader {
383383
///
384384
/// {@end-tool}
385385
///
386-
static registerCallback(DownloadCallback callback, int stepSize) {
386+
static registerCallback(DownloadCallback callback) {
387387
assert(_initialized, 'FlutterDownloader.initialize() must be called first');
388388

389389
final callbackHandle = PluginUtilities.getCallbackHandle(callback);
390390
assert(callbackHandle != null,
391391
'callback must be a top-level or a static function');
392-
assert(stepSize >= 0 && stepSize <= 100, 'Step size should be between 0-100');
393392
_channel.invokeMethod(
394-
'registerCallback', <dynamic>[callbackHandle.toRawHandle(), stepSize]);
393+
'registerCallback', <dynamic>[callbackHandle.toRawHandle()]);
395394
}
396395
}

0 commit comments

Comments
 (0)