Skip to content

Instantly share code, notes, and snippets.

@raystatic
Created March 1, 2022 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raystatic/b854db04f1e77a0699aed21de69ffa5a to your computer and use it in GitHub Desktop.
Save raystatic/b854db04f1e77a0699aed21de69ffa5a to your computer and use it in GitHub Desktop.
@Composable
fun ItemFile(
file: File,
startDownload:(File) -> Unit,
openFile:(File) -> Unit
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.background(color = Color.White)
.border(width = 2.dp, color = Color.Blue, shape = RoundedCornerShape(16.dp))
.clickable {
if (!file.isDownloading){
if (file.downloadedUri.isNullOrEmpty()){
startDownload(file)
}else{
openFile(file)
}
}
}
.padding(16.dp)
) {
Row(
modifier = Modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Column(
modifier = Modifier
.fillMaxWidth(0.8f)
) {
Text(
text = file.name,
style = Typography.body1,
color = Color.Black
)
Row {
val description = if (file.isDownloading){
"Downloading..."
}else{
if (file.downloadedUri.isNullOrEmpty()) "Tap to download the file" else "Tap to open file"
}
Text(
text = description,
style = Typography.body2,
color = Color.DarkGray
)
}
}
if (file.isDownloading){
CircularProgressIndicator(
color = Color.Blue,
modifier = Modifier
.size(32.dp)
.align(Alignment.CenterVertically)
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment