mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Add clear storage progress
This commit is contained in:
parent
cc014328f1
commit
d846bbf510
@ -1732,9 +1732,14 @@ public final class MediaBox {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastReportValue = 0
|
||||||
|
|
||||||
let reportProgress: (Int) -> Void = { count in
|
let reportProgress: (Int) -> Void = { count in
|
||||||
Queue.mainQueue().async {
|
let currentProgress = min(1.0, Float(count) / Float(totalCount))
|
||||||
subscriber.putNext(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())
|
self.didRemoveResourcesPipe.putNext(Void())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscriber.putNext(1.0)
|
||||||
subscriber.putCompletion()
|
subscriber.putCompletion()
|
||||||
}
|
}
|
||||||
return EmptyDisposable
|
return EmptyDisposable
|
||||||
|
|||||||
@ -2880,7 +2880,12 @@ final class StorageUsageScreenComponent: Component {
|
|||||||
let totalSize = aggregatedData.selectedSize
|
let totalSize = aggregatedData.selectedSize
|
||||||
|
|
||||||
let _ = (component.context.engine.resources.clearStorage(peerId: component.peer?.id, categories: mappedCategories, includeMessages: aggregatedData.clearIncludeMessages, excludeMessages: aggregatedData.clearExcludeMessages)
|
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 {
|
guard let self, let _ = self.component else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2921,11 +2926,6 @@ final class StorageUsageScreenComponent: Component {
|
|||||||
self.isClearing = true
|
self.isClearing = true
|
||||||
self.state?.updated(transition: .immediate)
|
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
|
var totalSize: Int64 = 0
|
||||||
|
|
||||||
let contextStats = aggregatedData.contextStats
|
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
|
self.reloadStats(firstTime: false, completion: { [weak self] in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
@ -2994,7 +3005,12 @@ final class StorageUsageScreenComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _ = (component.context.engine.resources.clearStorage(peerIds: aggregatedData.selectionState.selectedPeers, includeMessages: includeMessages, excludeMessages: excludeMessages)
|
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 {
|
guard let self else {
|
||||||
return
|
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) {
|
private func openKeepMediaCategory(mappedCategory: CacheStorageSettings.PeerStorageCategory, sourceView: StoragePeerTypeItemComponent.View) {
|
||||||
guard let component = self.component else {
|
guard let component = self.component else {
|
||||||
return
|
return
|
||||||
@ -3507,8 +3529,8 @@ private class StorageUsageClearProgressOverlayNode: ASDisplayNode {
|
|||||||
self.addSubnode(self.animationNode)
|
self.addSubnode(self.animationNode)
|
||||||
self.addSubnode(self.progressTextNode)
|
self.addSubnode(self.progressTextNode)
|
||||||
self.addSubnode(self.descriptionTextNode)
|
self.addSubnode(self.descriptionTextNode)
|
||||||
//self.addSubnode(self.progressBackgroundNode)
|
self.addSubnode(self.progressBackgroundNode)
|
||||||
//self.addSubnode(self.progressForegroundNode)
|
self.addSubnode(self.progressForegroundNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
@ -3525,7 +3547,7 @@ private class StorageUsageClearProgressOverlayNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var progress: Float = 0.0
|
private var progress: Float = 0.0
|
||||||
private func setProgress(_ progress: Float) {
|
func setProgress(_ progress: Float) {
|
||||||
self.progress = progress
|
self.progress = progress
|
||||||
|
|
||||||
if let size = self.validLayout {
|
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))
|
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)
|
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)
|
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)
|
var progressTextFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - progressTextSize.width) / 2.0), y: descriptionTextFrame.minY - spacing - progressTextSize.height), size: progressTextSize)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user