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