Skip to content

Commit 0dfb8df

Browse files
authored
fix ktlint warnings (#781)
1 parent 1d9da1f commit 0dfb8df

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
272272
var downloadedBytes: Long = 0
273273
var responseCode: Int
274274
var times: Int
275-
var actualTimeout = timeout
276275
visited = HashMap()
277276
try {
278277
val task = taskDao?.loadTask(id.toString())
@@ -304,8 +303,8 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
304303
resourceUrl.openConnection() as HttpsURLConnection
305304
}
306305
log("Open connection to $url")
307-
httpConn.connectTimeout = actualTimeout
308-
httpConn.readTimeout = actualTimeout
306+
httpConn.connectTimeout = timeout
307+
httpConn.readTimeout = timeout
309308
httpConn.instanceFollowRedirects = false // Make the logic below easier to detect redirections
310309
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0...")
311310

@@ -419,10 +418,10 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
419418
)
420419
}
421420
}
422-
val task = taskDao?.loadTask(id.toString())
423-
val progress = if (isStopped && task!!.resumable) lastProgress else 100
421+
val loadedTask = taskDao?.loadTask(id.toString())
422+
val progress = if (isStopped && loadedTask!!.resumable) lastProgress else 100
424423
val status =
425-
if (isStopped) if (task!!.resumable) DownloadStatus.PAUSED else DownloadStatus.CANCELED else DownloadStatus.COMPLETE
424+
if (isStopped) if (loadedTask!!.resumable) DownloadStatus.PAUSED else DownloadStatus.CANCELED else DownloadStatus.COMPLETE
426425
val storage: Int = ContextCompat.checkSelfPermission(
427426
applicationContext,
428427
Manifest.permission.WRITE_EXTERNAL_STORAGE
@@ -460,9 +459,9 @@ class DownloadWorker(context: Context, params: WorkerParameters) :
460459
updateNotification(context, actualFilename, status, progress, pendingIntent, true)
461460
log(if (isStopped) "Download canceled" else "File downloaded")
462461
} else {
463-
val task = taskDao!!.loadTask(id.toString())
462+
val loadedTask = taskDao!!.loadTask(id.toString())
464463
val status =
465-
if (isStopped) if (task!!.resumable) DownloadStatus.PAUSED else DownloadStatus.CANCELED else DownloadStatus.FAILED
464+
if (isStopped) if (loadedTask!!.resumable) DownloadStatus.PAUSED else DownloadStatus.CANCELED else DownloadStatus.FAILED
466465
taskDao!!.updateTask(id.toString(), status, lastProgress)
467466
updateNotification(context, actualFilename ?: fileURL, status, -1, null, true)
468467
log(if (isStopped) "Download canceled" else "Server replied HTTP code: $responseCode")

android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
5555
"initialize" -> initialize(call, result)
5656
"registerCallback" -> registerCallback(call, result)
5757
"enqueue" -> enqueue(call, result)
58-
"loadTasks" -> loadTasks(call, result)
58+
"loadTasks" -> loadTasks(result)
5959
"loadTasksWithRawQuery" -> loadTasksWithRawQuery(call, result)
6060
"cancel" -> cancel(call, result)
61-
"cancelAll" -> cancelAll(call, result)
61+
"cancelAll" -> cancelAll(result)
6262
"pause" -> pause(call, result)
6363
"resume" -> resume(call, result)
6464
"retry" -> retry(call, result)
@@ -170,20 +170,38 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
170170
val saveInPublicStorage: Boolean = call.requireArgument("save_in_public_storage")
171171
val allowCellular: Boolean = call.requireArgument("allow_cellular")
172172
val request: WorkRequest = buildRequest(
173-
url, savedDir, filename, headers, showNotification,
174-
openFileFromNotification, false, requiresStorageNotLow, saveInPublicStorage, timeout, allowCellular = allowCellular
173+
url,
174+
savedDir,
175+
filename,
176+
headers,
177+
showNotification,
178+
openFileFromNotification,
179+
false,
180+
requiresStorageNotLow,
181+
saveInPublicStorage,
182+
timeout,
183+
allowCellular = allowCellular
175184
)
176185
WorkManager.getInstance(requireContext()).enqueue(request)
177186
val taskId: String = request.id.toString()
178187
result.success(taskId)
179188
sendUpdateProgress(taskId, DownloadStatus.ENQUEUED, 0)
180189
taskDao!!.insertOrUpdateNewTask(
181-
taskId, url, DownloadStatus.ENQUEUED, 0, filename,
182-
savedDir, headers, showNotification, openFileFromNotification, saveInPublicStorage, allowCellular = allowCellular
190+
taskId,
191+
url,
192+
DownloadStatus.ENQUEUED,
193+
0,
194+
filename,
195+
savedDir,
196+
headers,
197+
showNotification,
198+
openFileFromNotification,
199+
saveInPublicStorage,
200+
allowCellular = allowCellular
183201
)
184202
}
185203

186-
private fun loadTasks(call: MethodCall, result: MethodChannel.Result) {
204+
private fun loadTasks(result: MethodChannel.Result) {
187205
val tasks = taskDao!!.loadAllTasks()
188206
val array: MutableList<Map<*, *>> = ArrayList()
189207
for (task in tasks) {
@@ -226,7 +244,7 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
226244
result.success(null)
227245
}
228246

229-
private fun cancelAll(call: MethodCall, result: MethodChannel.Result) {
247+
private fun cancelAll(result: MethodChannel.Result) {
230248
WorkManager.getInstance(requireContext()).cancelAllWorkByTag(TAG)
231249
result.success(null)
232250
}
@@ -256,9 +274,17 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
256274
val partialFile = File(partialFilePath)
257275
if (partialFile.exists()) {
258276
val request: WorkRequest = buildRequest(
259-
task.url, task.savedDir, task.filename,
260-
task.headers, task.showNotification, task.openFileFromNotification,
261-
true, requiresStorageNotLow, task.saveInPublicStorage, timeout, allowCellular = task.allowCellular
277+
task.url,
278+
task.savedDir,
279+
task.filename,
280+
task.headers,
281+
task.showNotification,
282+
task.openFileFromNotification,
283+
true,
284+
requiresStorageNotLow,
285+
task.saveInPublicStorage,
286+
timeout,
287+
allowCellular = task.allowCellular
262288
)
263289
val newTaskId: String = request.id.toString()
264290
result.success(newTaskId)

0 commit comments

Comments
 (0)