Created
March 2, 2022 20:46
-
-
Save raystatic/00e1a1657067551661cd32b2c0c42170 to your computer and use it in GitHub Desktop.
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
@Composable | |
fun Home() { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.padding(32.dp), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally | |
) { | |
val data = remember { | |
mutableStateOf( | |
File( | |
id = "10", | |
name = "Pdf File 10 MB", | |
type = "PDF", | |
url = "https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-download-10-mb.pdf", | |
downloadedUri = null | |
) | |
) | |
} | |
ItemFile( | |
file = data.value, | |
startDownload = { | |
startDownloadingFile( | |
file = data.value, | |
success = { | |
data.value = data.value.copy().apply { | |
isDownloading = false | |
downloadedUri = it | |
} | |
}, | |
failed = { | |
data.value = data.value.copy().apply { | |
isDownloading = false | |
downloadedUri = null | |
} | |
}, | |
running = { | |
data.value = data.value.copy().apply { | |
isDownloading = true | |
} | |
} | |
) | |
}, | |
openFile = { | |
val intent = Intent(Intent.ACTION_VIEW) | |
intent.setDataAndType(it.downloadedUri?.toUri(),"application/pdf") | |
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | |
try { | |
startActivity(intent) | |
}catch (e:ActivityNotFoundException){ | |
Toast.makeText( | |
this@MainActivity, | |
"Can't open Pdf", | |
Toast.LENGTH_SHORT | |
).show() | |
} | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment