Skip to content

Commit

Permalink
Update FlutterDownloaderPlugin.java
Browse files Browse the repository at this point in the history
  • Loading branch information
atrope authored Jun 10, 2021
1 parent 2ef1318 commit 3efdc1d
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package vn.hunghd.flutterdownloader;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
Expand Down Expand Up @@ -33,7 +32,6 @@
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.PluginRegistry;

public class FlutterDownloaderPlugin implements MethodCallHandler, FlutterPlugin {
private static final String CHANNEL = "vn.hunghd/downloader";
Expand All @@ -42,23 +40,13 @@ public class FlutterDownloaderPlugin implements MethodCallHandler, FlutterPlugin
public static final String SHARED_PREFERENCES_KEY = "vn.hunghd.downloader.pref";
public static final String CALLBACK_DISPATCHER_HANDLE_KEY = "callback_dispatcher_handle_key";

private static FlutterDownloaderPlugin instance;
private MethodChannel flutterChannel;
private TaskDbHelper dbHelper;
private TaskDao taskDao;
private Context context;
private long callbackHandle;
private int debugMode;
private final Object initializationLock = new Object();

@SuppressLint("NewApi")
public static void registerWith(PluginRegistry.Registrar registrar) {
if (instance == null) {
instance = new FlutterDownloaderPlugin();
}
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

public void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
synchronized (initializationLock) {
if (flutterChannel != null) {
Expand All @@ -67,7 +55,7 @@ public void onAttachedToEngine(Context applicationContext, BinaryMessenger messe
this.context = applicationContext;
flutterChannel = new MethodChannel(messenger, CHANNEL);
flutterChannel.setMethodCallHandler(this);
dbHelper = TaskDbHelper.getInstance(context);
TaskDbHelper dbHelper = TaskDbHelper.getInstance(context);
taskDao = new TaskDao(dbHelper);
}
}
Expand Down Expand Up @@ -124,7 +112,7 @@ private WorkRequest buildRequest(String url, String savedDir, String filename, S
.setRequiredNetworkType(NetworkType.CONNECTED)
.build())
.addTag(TAG)
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 5, TimeUnit.SECONDS)
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 10, TimeUnit.SECONDS)
.setInputData(new Data.Builder()
.putString(DownloadWorker.ARG_URL, url)
.putString(DownloadWorker.ARG_SAVED_DIR, savedDir)
Expand Down

0 comments on commit 3efdc1d

Please sign in to comment.