Skip to content

Commit

Permalink
fix: Fix an issue that caused false download feedback if file is unre…
Browse files Browse the repository at this point in the history
…achable or undownloadable
  • Loading branch information
kkmurerwa committed Mar 30, 2022
1 parent 48bada8 commit 03618ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class FirstFragment : Fragment(R.layout.fragment_first), DownloadInterface {

private val binding get() = _binding!!

// private val url = "https://p303.zlibcdn.com/dtoken/a2b5e71d182ed58f2fddae0e5b6018af"
private val url = "http://www.ecomesty.co.ke/kytabu/the-time-machine-by-h.-g.-wells.epub"
// private val url = "https://www.makeuseof.com/check-suspicious-file-malware"

private val fileDownloader by lazy {
FileDownloader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ class FileDownloader(

val fileLength = connection.contentLength

if (fileLength < 0) {
withContext(Dispatchers.Main) {
downloadInterface.onErrorOccurred("We encountered an error downloading the file. The file might be unreachable.")
}

return@launch
}

val outputFile = File(filePath, fileName)
val fos = FileOutputStream(outputFile)

Expand Down Expand Up @@ -90,6 +98,7 @@ class FileDownloader(
}
}


} catch (ioException: IOException) {
withContext(Dispatchers.Main) {
downloadInterface.onErrorOccurred(ioException.stackTraceToString())
Expand Down

0 comments on commit 03618ea

Please sign in to comment.