improve resizing part info logic

This commit is contained in:
AmirHossein Abdolmotallebi 2024-09-12 07:26:38 +03:30
parent 9e6ffcab09
commit 33ee46e7c9
2 changed files with 59 additions and 38 deletions

View File

@ -43,10 +43,11 @@ fun getDownloadTitle(itemState: IDownloadItemState): String {
} }
} }
val LocalSingleBoxSizing = compositionLocalOf<SingleDownloadPageSizing> { error("LocalSingleBoxSizing not provided") } val LocalSingleDownloadPageSizing = compositionLocalOf<SingleDownloadPageSizing> { error("LocalSingleBoxSizing not provided") }
@Stable @Stable
class SingleDownloadPageSizing { class SingleDownloadPageSizing {
var resizingPartInfo by mutableStateOf(false)
var partInfoHeight by mutableStateOf(150.dp) var partInfoHeight by mutableStateOf(150.dp)
} }
@ -102,7 +103,7 @@ fun ShowDownloadDialogs(component: DownloadDialogManager) {
UpdateTaskBar(window, itemState) UpdateTaskBar(window, itemState)
} }
CompositionLocalProvider( CompositionLocalProvider(
LocalSingleBoxSizing provides singleDownloadPageSizing LocalSingleDownloadPageSizing provides singleDownloadPageSizing
) { ) {
SingleDownloadPage(singleDownloadComponent) SingleDownloadPage(singleDownloadComponent)
} }

View File

@ -18,6 +18,7 @@ import androidx.compose.animation.core.*
import androidx.compose.foundation.* import androidx.compose.foundation.*
import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsDraggedAsState
import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
@ -117,6 +118,12 @@ fun SingleDownloadPage(singleDownloadComponent: SingleDownloadComponent) {
RenderActions(itemState, singleDownloadComponent, showPartInfo, setShowPartInfo) RenderActions(itemState, singleDownloadComponent, showPartInfo, setShowPartInfo)
Spacer(Modifier.size(8.dp)) Spacer(Modifier.size(8.dp))
} }
val resizingState = LocalSingleDownloadPageSizing.current
LaunchedEffect(resizingState.resizingPartInfo){
if (resizingState.partInfoHeight<=0.dp){
setShowPartInfo(false)
}
}
if (showPartInfo && itemState is ProcessingDownloadItemState) { if (showPartInfo && itemState is ProcessingDownloadItemState) {
RenderPartInfo(itemState) RenderPartInfo(itemState)
} }
@ -161,7 +168,7 @@ fun RenderProgressBar(itemState: IDownloadItemState) {
is DownloadJobStatus.PreparingFile -> myColors.infoGradient is DownloadJobStatus.PreparingFile -> myColors.infoGradient
DownloadJobStatus.Resuming, DownloadJobStatus.Resuming,
DownloadJobStatus.Downloading, DownloadJobStatus.Downloading,
-> myColors.primaryGradient -> myColors.primaryGradient
} }
Box( Box(
@ -183,7 +190,7 @@ fun RenderProgressBar(itemState: IDownloadItemState) {
).value ).value
) )
) { ) {
if(progress==1f){ if (progress == 1f) {
MyIcon( MyIcon(
MyIcons.check, MyIcons.check,
null, null,
@ -207,26 +214,28 @@ fun RenderProgressBar(itemState: IDownloadItemState) {
1f, 1f,
infiniteRepeatable(tween(l), RepeatMode.Restart) infiniteRepeatable(tween(l), RepeatMode.Restart)
) )
val width by anim.animateFloat(6f, 16f, infiniteRepeatable( val width by anim.animateFloat(
keyframes { 6f, 16f, infiniteRepeatable(
durationMillis = l keyframes {
0f atFraction 0f durationMillis = l
0.75f atFraction 0.25f 0f atFraction 0f
0f atFraction 1f 0.75f atFraction 0.25f
}, 0f atFraction 1f
repeatMode = RepeatMode.Restart },
) repeatMode = RepeatMode.Restart
)
) )
Box( Box(
Modifier Modifier
.fillMaxHeight() .fillMaxHeight()
.fillMaxWidth(endPos) .fillMaxWidth(endPos)
) { ) {
Box(Modifier Box(
.background(background) Modifier
.fillMaxHeight() .background(background)
.align(Alignment.CenterEnd) .fillMaxHeight()
.fillMaxWidth(width) .align(Alignment.CenterEnd)
.fillMaxWidth(width)
) )
} }
} }
@ -257,7 +266,7 @@ fun ColumnScope.RenderPartInfo(itemState: ProcessingDownloadItemState) {
.let { parts -> .let { parts ->
if (onlyActiveParts) { if (onlyActiveParts) {
parts.filter { parts.filter {
when(it.status){ when (it.status) {
is PartDownloadStatus.Canceled -> true is PartDownloadStatus.Canceled -> true
PartDownloadStatus.Completed -> false PartDownloadStatus.Completed -> false
PartDownloadStatus.IDLE -> false PartDownloadStatus.IDLE -> false
@ -332,7 +341,8 @@ fun ColumnScope.RenderPartInfo(itemState: ProcessingDownloadItemState) {
SimpleCellText( SimpleCellText(
"${ "${
it.value.length?.let { length -> it.value.length?.let { length ->
convertSizeToHumanReadable(length convertSizeToHumanReadable(
length
) )
} ?: "Unknown" } ?: "Unknown"
}", }",
@ -355,15 +365,24 @@ fun ColumnScope.RenderPartInfo(itemState: ProcessingDownloadItemState) {
} }
} }
} }
val singleDownloadPageSizing = LocalSingleBoxSizing.current val singleDownloadPageSizing = LocalSingleDownloadPageSizing.current
Handle(Modifier.fillMaxWidth().height(8.dp), orientation = Orientation.Vertical) { val mutableInteractionSource = remember { MutableInteractionSource() }
val isDraggingHandle by mutableInteractionSource.collectIsDraggedAsState()
LaunchedEffect(isDraggingHandle){
singleDownloadPageSizing.resizingPartInfo = isDraggingHandle
}
Handle(
Modifier.fillMaxWidth().height(8.dp),
orientation = Orientation.Vertical,
interactionSource = mutableInteractionSource
) {
singleDownloadPageSizing.partInfoHeight += it singleDownloadPageSizing.partInfoHeight += it
} }
} }
} }
fun prettifyStatus(status: PartDownloadStatus): String { fun prettifyStatus(status: PartDownloadStatus): String {
return when(status){ return when (status) {
is PartDownloadStatus.Canceled -> "Disconnected" is PartDownloadStatus.Canceled -> "Disconnected"
PartDownloadStatus.IDLE -> "IDLE" PartDownloadStatus.IDLE -> "IDLE"
PartDownloadStatus.Completed -> "Completed" PartDownloadStatus.Completed -> "Completed"
@ -413,8 +432,8 @@ sealed class PartInfoCells : TableCell<IndexedValue<UiPart>> {
@Composable @Composable
fun RenderPropertyItem(propertyItem: SingleDownloadPagePropertyItem) { fun RenderPropertyItem(propertyItem: SingleDownloadPagePropertyItem) {
val title= propertyItem.name val title = propertyItem.name
val value= propertyItem.value val value = propertyItem.value
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@ -435,7 +454,7 @@ fun RenderPropertyItem(propertyItem: SingleDownloadPagePropertyItem) {
.weight(0.7f), .weight(0.7f),
maxLines = 1, maxLines = 1,
fontSize = myTextSizes.base, fontSize = myTextSizes.base,
color = when(propertyItem.valueState){ color = when (propertyItem.valueState) {
SingleDownloadPagePropertyItem.ValueType.Normal -> LocalContentColor.current SingleDownloadPagePropertyItem.ValueType.Normal -> LocalContentColor.current
SingleDownloadPagePropertyItem.ValueType.Error -> myColors.error SingleDownloadPagePropertyItem.ValueType.Error -> myColors.error
SingleDownloadPagePropertyItem.ValueType.Success -> myColors.success SingleDownloadPagePropertyItem.ValueType.Success -> myColors.success
@ -490,7 +509,8 @@ fun RenderActions(
is ProcessingDownloadItemState -> { is ProcessingDownloadItemState -> {
PartInfoButton(showingPartInfo, onRequestShowPartInfo) PartInfoButton(showingPartInfo, onRequestShowPartInfo)
Spacer(Modifier.weight(1f)) Spacer(Modifier.weight(1f))
ToggleButton(it, ToggleButton(
it,
singleDownloadComponent::toggle, singleDownloadComponent::toggle,
singleDownloadComponent::resume, singleDownloadComponent::resume,
singleDownloadComponent::pause, singleDownloadComponent::pause,
@ -598,29 +618,29 @@ private fun ToggleButton(
Box { Box {
SingleDownloadPageButton( SingleDownloadPageButton(
{ {
if (isResumeSupported){ if (isResumeSupported) {
toggle() toggle()
}else{ } else {
if (itemState.status is DownloadJobStatus.IsActive){ if (itemState.status is DownloadJobStatus.IsActive) {
showPromptOnNonePresumablePause=true showPromptOnNonePresumablePause = true
}else{ } else {
toggle() toggle()
} }
} }
}, },
icon = icon, icon = icon,
text = text, text = text,
color = if (isResumeSupported){ color = if (isResumeSupported) {
LocalContentColor.current LocalContentColor.current
}else{ } else {
if (itemState.status is DownloadJobStatus.IsActive){ if (itemState.status is DownloadJobStatus.IsActive) {
myColors.error myColors.error
}else{ } else {
LocalContentColor.current LocalContentColor.current
} }
}, },
) )
if (showPromptOnNonePresumablePause){ if (showPromptOnNonePresumablePause) {
val shape = RoundedCornerShape(6.dp) val shape = RoundedCornerShape(6.dp)
val closePopup = { val closePopup = {
showPromptOnNonePresumablePause = false showPromptOnNonePresumablePause = false
@ -649,7 +669,7 @@ private fun ToggleButton(
.widthIn(max = 140.dp) .widthIn(max = 140.dp)
) { ) {
Text(buildAnnotatedString { Text(buildAnnotatedString {
withStyle(SpanStyle(color = myColors.warning)){ withStyle(SpanStyle(color = myColors.warning)) {
append("WARNING:\n") append("WARNING:\n")
} }
append("This download doesn't support resuming! You may have to RESTART it later in the Download List") append("This download doesn't support resuming! You may have to RESTART it later in the Download List")