Browse Source

fix downloadworker; now functional

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
bf22b86723
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 11
      app/src/main/java/awais/instagrabber/workers/DownloadWorker.kt

11
app/src/main/java/awais/instagrabber/workers/DownloadWorker.kt

@ -55,9 +55,14 @@ class DownloadWorker(context: Context, workerParams: WorkerParameters) : Corouti
.build()) .build())
} }
val downloadRequestString: String val downloadRequestString: String
val requestFile = File(downloadRequestFilePath)
val requestFile = Uri.parse(downloadRequestFilePath)
val context = applicationContext
val contentResolver = context.contentResolver ?: return Result.failure(Data.Builder()
.putString("error", "contentResolver is null")
.build())
try { try {
downloadRequestString = requestFile.bufferedReader().use { it.readText() }
val scanner = Scanner(contentResolver.openInputStream(requestFile))
downloadRequestString = scanner.useDelimiter("\\A").next()
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "doWork: ", e) Log.e(TAG, "doWork: ", e)
return Result.failure(Data.Builder() return Result.failure(Data.Builder()
@ -82,7 +87,7 @@ class DownloadWorker(context: Context, workerParams: WorkerParameters) : Corouti
val urlToFilePathMap = downloadRequest.urlToFilePathMap val urlToFilePathMap = downloadRequest.urlToFilePathMap
download(urlToFilePathMap) download(urlToFilePathMap)
Handler(Looper.getMainLooper()).postDelayed({ showSummary(urlToFilePathMap) }, 500) Handler(Looper.getMainLooper()).postDelayed({ showSummary(urlToFilePathMap) }, 500)
val deleted = requestFile.delete()
val deleted = DocumentFile.fromSingleUri(context, requestFile)!!.delete()
if (!deleted) { if (!deleted) {
Log.w(TAG, "doWork: requestFile not deleted!") Log.w(TAG, "doWork: requestFile not deleted!")
} }

Loading…
Cancel
Save