1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +00:00

fix downloadworker; now functional

This commit is contained in:
Austin Huang 2021-06-13 22:22:53 -04:00
parent c47272792e
commit bf22b86723
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F

View File

@ -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!")
} }