diff --git a/app/src/main/java/com/murerwa/murerwadownloader/FirstFragment.kt b/app/src/main/java/com/murerwa/murerwadownloader/FirstFragment.kt index 16f5b7c..d595784 100644 --- a/app/src/main/java/com/murerwa/murerwadownloader/FirstFragment.kt +++ b/app/src/main/java/com/murerwa/murerwadownloader/FirstFragment.kt @@ -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( diff --git a/filedownloader/src/main/java/com/murerwa/filedownloader/FileDownloader.kt b/filedownloader/src/main/java/com/murerwa/filedownloader/FileDownloader.kt index 3604d8e..b6f41fa 100644 --- a/filedownloader/src/main/java/com/murerwa/filedownloader/FileDownloader.kt +++ b/filedownloader/src/main/java/com/murerwa/filedownloader/FileDownloader.kt @@ -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) @@ -90,6 +98,7 @@ class FileDownloader( } } + } catch (ioException: IOException) { withContext(Dispatchers.Main) { downloadInterface.onErrorOccurred(ioException.stackTraceToString())