mirror of
https://github.com/amir1376/ab-download-manager.git
synced 2025-02-20 11:43:24 +08:00
add download resume support in ui
This commit is contained in:
parent
44d2936767
commit
8895b16410
@ -55,7 +55,7 @@ fun ShowDownloadDialogs(component: DownloadDialogManager) {
|
||||
val onRequestClose = {
|
||||
component.closeDownloadDialog(singleDownloadComponent.downloadId)
|
||||
}
|
||||
val defaultHeight = 270f
|
||||
val defaultHeight = 290f
|
||||
val defaultWidth = 450f
|
||||
|
||||
val showPartInfo by singleDownloadComponent.showPartInfo
|
||||
|
@ -77,7 +77,7 @@ fun SingleDownloadPage(singleDownloadComponent: SingleDownloadComponent) {
|
||||
val tabContentModifier = Modifier
|
||||
|
||||
Box(
|
||||
Modifier.height(130.dp)
|
||||
Modifier.height(150.dp)
|
||||
.clip(RoundedCornerShape(bottomStart = 6.dp, bottomEnd = 6.dp))
|
||||
.background(myColors.background)
|
||||
.verticalScroll(scrollState)
|
||||
@ -543,6 +543,7 @@ private fun ToggleButton(
|
||||
itemState: ProcessingDownloadItemState,
|
||||
toggle: () -> Unit,
|
||||
) {
|
||||
val isResumeSupported = itemState.supportResume == true
|
||||
val (icon, text) = when (itemState.status) {
|
||||
is DownloadJobStatus.CanBeResumed -> {
|
||||
MyIcons.resume to "Resume"
|
||||
@ -560,6 +561,15 @@ private fun ToggleButton(
|
||||
},
|
||||
icon = icon,
|
||||
text = text,
|
||||
color = if (isResumeSupported){
|
||||
LocalContentColor.current
|
||||
}else{
|
||||
if (itemState.status is DownloadJobStatus.IsActive){
|
||||
myColors.error
|
||||
}else{
|
||||
LocalContentColor.current
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,11 @@ class SingleDownloadComponent(
|
||||
add("Remaining Time" to (it.remainingTime?.let { remainingTime ->
|
||||
convertTimeRemainingToHumanReadable(remainingTime, TimeNames.ShortNames)
|
||||
}.orEmpty()))
|
||||
add("Resume Support" to when(it.supportResume){
|
||||
true->"Yes"
|
||||
false->"No"
|
||||
null->"Unknown"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,8 @@ class DownloadJob(
|
||||
private var booted = false
|
||||
|
||||
|
||||
var supportsConcurrent: Boolean = false
|
||||
var supportsConcurrent: Boolean? = null
|
||||
private set
|
||||
|
||||
private val _isDownloadActive = MutableStateFlow(false)
|
||||
val isDownloadActive = _isDownloadActive.asStateFlow()
|
||||
@ -56,6 +57,10 @@ class DownloadJob(
|
||||
val outFile = downloadManager.calculateOutputFile(downloadItem)
|
||||
destination = SimpleDownloadDestination(outFile, downloadManager.diskStat)
|
||||
loadPartState()
|
||||
supportsConcurrent = when(getParts().size){
|
||||
in 2..Int.MAX_VALUE -> true
|
||||
else -> null
|
||||
}
|
||||
applySpeedLimit()
|
||||
booted = true
|
||||
// thisLogger().info("job for dl_$id booted")
|
||||
@ -261,7 +266,7 @@ class DownloadJob(
|
||||
listOf(Part(0, null, 0))
|
||||
)
|
||||
} else {
|
||||
if (supportsConcurrent){
|
||||
if (supportsConcurrent==true){
|
||||
//split parts
|
||||
setParts(splitToRange(
|
||||
minPartSize = downloadManager.settings.minPartSize,
|
||||
@ -313,7 +318,7 @@ class DownloadJob(
|
||||
val inactivePart =
|
||||
kotlin.runCatching { mutableInactivePartDownloaderList.removeAt(0) }.getOrNull()
|
||||
if (inactivePart != null) return inactivePart
|
||||
if (supportsConcurrent && downloadManager.settings.dynamicPartCreationMode) {
|
||||
if (supportsConcurrent==true && downloadManager.settings.dynamicPartCreationMode) {
|
||||
synchronized(partSplitLock) {
|
||||
val candidates = getPartDownloaderList()
|
||||
.toList()
|
||||
|
@ -20,6 +20,7 @@ data class ProcessingDownloadItemState(
|
||||
val status: DownloadJobStatus,
|
||||
val speed: Long,
|
||||
val parts: List<UiPart>,
|
||||
val supportResume: Boolean?,
|
||||
) : IDownloadItemState {
|
||||
val progress = parts.sumOf {
|
||||
it.howMuchProceed
|
||||
@ -62,6 +63,7 @@ data class ProcessingDownloadItemState(
|
||||
UiPart.fromPart(it)
|
||||
},
|
||||
speed = speed,
|
||||
supportResume = downloadJob.supportsConcurrent,
|
||||
downloadLink = downloadItem.link
|
||||
)
|
||||
}
|
||||
@ -82,7 +84,8 @@ data class ProcessingDownloadItemState(
|
||||
saveLocation = downloadItem.name,
|
||||
parts = emptyList(),
|
||||
speed = 0,
|
||||
downloadLink = downloadItem.link
|
||||
downloadLink = downloadItem.link,
|
||||
supportResume = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user