Skip to content

Commit

Permalink
add download resume support in ui with a colored property name
Browse files Browse the repository at this point in the history
  • Loading branch information
amir1376 committed Jul 15, 2024
1 parent 8895b16 commit a8034cf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,9 @@ sealed class PartInfoCells : TableCell<IndexedValue<UiPart>> {


@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()
Expand All @@ -400,7 +399,6 @@ fun RenderPropertyItem(
modifier = Modifier.weight(0.3f),
maxLines = 1,
fontSize = myTextSizes.base

)
}
WithContentAlpha(1f) {
Expand All @@ -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
}
)
}
}
Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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,
Expand All @@ -41,28 +50,36 @@ class SingleDownloadComponent(
val showPartInfo = mutableStateOf(false)


val extraDownloadInfo: StateFlow<List<Pair<String, String>>> = itemStateFlow
val extraDownloadInfo: StateFlow<List<SingleDownloadPagePropertyItem>> = 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
}
))
}
}
}
Expand Down

0 comments on commit a8034cf

Please sign in to comment.