Add clear storage progress

This commit is contained in:
Ali 2023-03-07 13:45:21 +04:00
parent cc014328f1
commit d846bbf510
2 changed files with 68 additions and 38 deletions

View File

@ -1732,9 +1732,14 @@ public final class MediaBox {
return
}
var lastReportValue = 0
let reportProgress: (Int) -> Void = { count in
Queue.mainQueue().async {
subscriber.putNext(min(1.0, Float(count) / Float(totalCount)))
let currentProgress = min(1.0, Float(count) / Float(totalCount))
let currentInteger = Int(currentProgress * 100.0)
if lastReportValue != currentInteger {
lastReportValue = currentInteger
subscriber.putNext(currentProgress)
}
}
@ -1781,6 +1786,7 @@ public final class MediaBox {
self.didRemoveResourcesPipe.putNext(Void())
}
subscriber.putNext(1.0)
subscriber.putCompletion()
}
return EmptyDisposable

View File

@ -2880,7 +2880,12 @@ final class StorageUsageScreenComponent: Component {
let totalSize = aggregatedData.selectedSize
let _ = (component.context.engine.resources.clearStorage(peerId: component.peer?.id, categories: mappedCategories, includeMessages: aggregatedData.clearIncludeMessages, excludeMessages: aggregatedData.clearExcludeMessages)
|> deliverOnMainQueue).start(completed: { [weak self] in
|> deliverOnMainQueue).start(next: { [weak self] progress in
guard let self else {
return
}
self.updateClearProgress(progress: progress)
}, completed: { [weak self] in
guard let self, let _ = self.component else {
return
}
@ -2921,11 +2926,6 @@ final class StorageUsageScreenComponent: Component {
self.isClearing = true
self.state?.updated(transition: .immediate)
let _ = (component.context.engine.resources.clearStorage(peerId: component.peer?.id, categories: mappedCategories, includeMessages: [], excludeMessages: [])
|> deliverOnMainQueue).start(completed: { [weak self] in
guard let self, let _ = self.component, let aggregatedData = self.aggregatedData else {
return
}
var totalSize: Int64 = 0
let contextStats = aggregatedData.contextStats
@ -2956,6 +2956,17 @@ final class StorageUsageScreenComponent: Component {
}
}
let _ = (component.context.engine.resources.clearStorage(peerId: component.peer?.id, categories: mappedCategories, includeMessages: [], excludeMessages: [])
|> deliverOnMainQueue).start(next: { [weak self] progress in
guard let self else {
return
}
self.updateClearProgress(progress: progress)
}, completed: { [weak self] in
guard let self else {
return
}
self.reloadStats(firstTime: false, completion: { [weak self] in
guard let self else {
return
@ -2994,7 +3005,12 @@ final class StorageUsageScreenComponent: Component {
}
let _ = (component.context.engine.resources.clearStorage(peerIds: aggregatedData.selectionState.selectedPeers, includeMessages: includeMessages, excludeMessages: excludeMessages)
|> deliverOnMainQueue).start(completed: { [weak self] in
|> deliverOnMainQueue).start(next: { [weak self] progress in
guard let self else {
return
}
self.updateClearProgress(progress: progress)
}, completed: { [weak self] in
guard let self else {
return
}
@ -3012,6 +3028,12 @@ final class StorageUsageScreenComponent: Component {
}
}
private func updateClearProgress(progress: Float) {
if let clearingNode = self.clearingNode {
clearingNode.setProgress(progress)
}
}
private func openKeepMediaCategory(mappedCategory: CacheStorageSettings.PeerStorageCategory, sourceView: StoragePeerTypeItemComponent.View) {
guard let component = self.component else {
return
@ -3507,8 +3529,8 @@ private class StorageUsageClearProgressOverlayNode: ASDisplayNode {
self.addSubnode(self.animationNode)
self.addSubnode(self.progressTextNode)
self.addSubnode(self.descriptionTextNode)
//self.addSubnode(self.progressBackgroundNode)
//self.addSubnode(self.progressForegroundNode)
self.addSubnode(self.progressBackgroundNode)
self.addSubnode(self.progressForegroundNode)
}
deinit {
@ -3525,7 +3547,7 @@ private class StorageUsageClearProgressOverlayNode: ASDisplayNode {
}
private var progress: Float = 0.0
private func setProgress(_ progress: Float) {
func setProgress(_ progress: Float) {
self.progress = progress
if let size = self.validLayout {
@ -3563,7 +3585,9 @@ private class StorageUsageClearProgressOverlayNode: ASDisplayNode {
let descriptionTextSize = self.descriptionTextNode.updateLayout(CGSize(width: size.width - inset * 3.0, height: size.height))
var descriptionTextFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - descriptionTextSize.width) / 2.0), y: animationFrame.maxY + 52.0), size: descriptionTextSize)
self.progressTextNode.attributedText = NSAttributedString(string: self.presentationData.strings.ClearCache_NoProgress, font: Font.with(size: 17.0, design: .regular, weight: .semibold, traits: [.monospacedNumbers]), textColor: self.presentationData.theme.actionSheet.primaryTextColor)
let progressText: String = "\(Int(self.progress * 100.0))%"
self.progressTextNode.attributedText = NSAttributedString(string: progressText, font: Font.with(size: 17.0, design: .regular, weight: .semibold, traits: [.monospacedNumbers]), textColor: self.presentationData.theme.actionSheet.primaryTextColor)
let progressTextSize = self.progressTextNode.updateLayout(size)
var progressTextFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - progressTextSize.width) / 2.0), y: descriptionTextFrame.minY - spacing - progressTextSize.height), size: progressTextSize)