diff --git a/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPage.kt b/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPage.kt index 0f95466..6d63dd5 100644 --- a/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPage.kt +++ b/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPage.kt @@ -386,10 +386,9 @@ sealed class PartInfoCells : TableCell> { @Composable -fun RenderPropertyItem( - title: String, - value: String, -) { +fun RenderPropertyItem(propertyItem: SingleDownloadPagePropertyItem) { + val title= propertyItem.name + val value= propertyItem.value Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth() @@ -400,7 +399,6 @@ fun RenderPropertyItem( modifier = Modifier.weight(0.3f), maxLines = 1, fontSize = myTextSizes.base - ) } WithContentAlpha(1f) { @@ -410,7 +408,12 @@ fun RenderPropertyItem( .basicMarquee() .weight(0.7f), maxLines = 1, - fontSize = myTextSizes.base + fontSize = myTextSizes.base, + color = when(propertyItem.valueState){ + SingleDownloadPagePropertyItem.ValueType.Normal -> LocalContentColor.current + SingleDownloadPagePropertyItem.ValueType.Error -> myColors.error + SingleDownloadPagePropertyItem.ValueType.Success -> myColors.success + } ) } } @@ -426,9 +429,9 @@ fun RenderInfo( .padding(horizontal = 16.dp) .padding(top = 8.dp) ) { - for ((title, value) in singleDownloadComponent.extraDownloadInfo.collectAsState().value) { + for (propertyItem in singleDownloadComponent.extraDownloadInfo.collectAsState().value) { Spacer(Modifier.height(2.dp)) - RenderPropertyItem(title, value) + RenderPropertyItem(propertyItem) } } } diff --git a/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPageComponent.kt b/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPageComponent.kt index 6b72e0a..f5f3fbb 100644 --- a/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPageComponent.kt +++ b/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/pages/singleDownloadPage/SingleDownloadPageComponent.kt @@ -1,5 +1,6 @@ package com.abdownloadmanager.desktop.pages.singleDownloadPage +import androidx.compose.runtime.Immutable import com.abdownloadmanager.desktop.pages.settings.configurable.IntConfigurable import com.abdownloadmanager.desktop.pages.settings.configurable.SpeedLimitConfigurable import com.abdownloadmanager.desktop.utils.* @@ -24,6 +25,14 @@ sealed interface SingleDownloadEffects { data object BringToFront : SingleDownloadEffects } +@Immutable +data class SingleDownloadPagePropertyItem( + val name: String, + val value: String, + val valueState: ValueType = ValueType.Normal, +) { + enum class ValueType { Normal, Error, Success } +} class SingleDownloadComponent( ctx: ComponentContext, val onDismiss: () -> Unit, @@ -41,28 +50,36 @@ class SingleDownloadComponent( val showPartInfo = mutableStateOf(false) - val extraDownloadInfo: StateFlow>> = itemStateFlow + val extraDownloadInfo: StateFlow> = itemStateFlow .filterNotNull() .map { buildList { - add("Name" to it.name) - add("Status" to createStatusString(it)) - add("Size" to convertSizeToHumanReadable(it.contentLength)) + add(SingleDownloadPagePropertyItem("Name", it.name)) + add(SingleDownloadPagePropertyItem("Status", createStatusString(it))) + add(SingleDownloadPagePropertyItem("Size", convertSizeToHumanReadable(it.contentLength))) when (it) { is CompletedDownloadItemState -> { } is ProcessingDownloadItemState -> { - add("Downloaded" to convertBytesToHumanReadable(it.progress).orEmpty()) - add("Speed" to convertSpeedToHumanReadable(it.speed)) - add("Remaining Time" to (it.remainingTime?.let { remainingTime -> + add(SingleDownloadPagePropertyItem("Downloaded" , convertBytesToHumanReadable(it.progress).orEmpty())) + add(SingleDownloadPagePropertyItem("Speed" , convertSpeedToHumanReadable(it.speed))) + add(SingleDownloadPagePropertyItem("Remaining Time" , (it.remainingTime?.let { remainingTime -> convertTimeRemainingToHumanReadable(remainingTime, TimeNames.ShortNames) - }.orEmpty())) - add("Resume Support" to when(it.supportResume){ - true->"Yes" - false->"No" - null->"Unknown" - }) + }.orEmpty()))) + add(SingleDownloadPagePropertyItem( + "Resume Support", + when (it.supportResume) { + true -> "Yes" + false -> "No" + null -> "Unknown" + }, + when (it.supportResume) { + true -> SingleDownloadPagePropertyItem.ValueType.Success + false -> SingleDownloadPagePropertyItem.ValueType.Error + null -> SingleDownloadPagePropertyItem.ValueType.Normal + } + )) } } }