Fix: Showing download progress (not real-time-synced though)

This commit is contained in:
machiav3lli 2022-05-31 03:03:47 +02:00
parent 0e6affa96d
commit 934f0bd8cc

View File

@ -121,8 +121,9 @@ fun TopBarHeader(
AnimatedVisibility(visible = state is Cancelable) { AnimatedVisibility(visible = state is Cancelable) {
DownloadProgress( DownloadProgress(
modifier = Modifier.padding(horizontal = 12.dp), modifier = Modifier.padding(horizontal = 12.dp),
totalSize = 69420, totalSize = if (state is Downloading) state.total ?: 1L else 1L,
isIndeterminate = state !is Downloading, isIndeterminate = state !is Downloading,
downloaded = if (state is Downloading) state.downloaded else 0L,
) )
} }
} }
@ -194,8 +195,8 @@ fun HeaderExtrasCard(
@Composable @Composable
fun DownloadProgress( fun DownloadProgress(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
downloading: Float = 0f,
totalSize: Long, totalSize: Long,
downloaded: Long?,
isIndeterminate: Boolean isIndeterminate: Boolean
) { ) {
Column( Column(
@ -210,15 +211,14 @@ fun DownloadProgress(
) )
} else { } else {
Text( Text(
text = totalSize.times(downloading).toLong() text = "${downloaded?.formatSize()}/${totalSize.formatSize()}"
.formatSize() + "/" + totalSize.formatSize()
) )
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
LinearProgressIndicator( LinearProgressIndicator(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clip(Shapes.Full), .clip(Shapes.Full),
progress = downloading progress = downloaded?.toFloat()?.div(totalSize) ?: 1f
) )
} }
} }