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)
} }
@ -207,7 +214,8 @@ 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(
6f, 16f, infiniteRepeatable(
keyframes { keyframes {
durationMillis = l durationMillis = l
0f atFraction 0f 0f atFraction 0f
@ -222,7 +230,8 @@ fun RenderProgressBar(itemState: IDownloadItemState) {
.fillMaxHeight() .fillMaxHeight()
.fillMaxWidth(endPos) .fillMaxWidth(endPos)
) { ) {
Box(Modifier Box(
Modifier
.background(background) .background(background)
.fillMaxHeight() .fillMaxHeight()
.align(Alignment.CenterEnd) .align(Alignment.CenterEnd)
@ -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,8 +365,17 @@ 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
} }
} }
@ -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,