Last active
July 5, 2022 16:11
-
-
Save francescogatto/218bb70d01b392ba7f8e935c4d4da3d6 to your computer and use it in GitHub Desktop.
#kkd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun downloadWithFlow(dummy: DummyData) { | |
CoroutineScope(Dispatchers.IO).launch { | |
ktor.downloadFile(dummy.file, dummy.url).collect { | |
withContext(Dispatchers.Main) { | |
when (it) { | |
is DownloadResult.Success -> { | |
myAdapter.setDownloading(dummy, false) | |
} | |
is DownloadResult.Error -> { | |
myAdapter.setDownloading(dummy, false) | |
Toast.makeText(this@MainActivity, "Error while downloading ${dummy.title}", Toast.LENGTH_LONG).show() | |
} | |
is DownloadResult.Progress -> { | |
myAdapter.setProgress(dummy, it.progress) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment