mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-06 17:00:13 +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,39 +2926,45 @@ final class StorageUsageScreenComponent: Component {
|
|||||||
self.isClearing = true
|
self.isClearing = true
|
||||||
self.state?.updated(transition: .immediate)
|
self.state?.updated(transition: .immediate)
|
||||||
|
|
||||||
|
var totalSize: Int64 = 0
|
||||||
|
|
||||||
|
let contextStats = aggregatedData.contextStats
|
||||||
|
|
||||||
|
for category in aggregatedData.selectedCategories {
|
||||||
|
let mappedCategory: StorageUsageStats.CategoryKey
|
||||||
|
switch category {
|
||||||
|
case .photos:
|
||||||
|
mappedCategory = .photos
|
||||||
|
case .videos:
|
||||||
|
mappedCategory = .videos
|
||||||
|
case .files:
|
||||||
|
mappedCategory = .files
|
||||||
|
case .music:
|
||||||
|
mappedCategory = .music
|
||||||
|
case .other:
|
||||||
|
continue
|
||||||
|
case .stickers:
|
||||||
|
mappedCategory = .stickers
|
||||||
|
case .avatars:
|
||||||
|
mappedCategory = .avatars
|
||||||
|
case .misc:
|
||||||
|
mappedCategory = .misc
|
||||||
|
}
|
||||||
|
|
||||||
|
if let value = contextStats.categories[mappedCategory] {
|
||||||
|
totalSize += value.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _ = (component.context.engine.resources.clearStorage(peerId: component.peer?.id, categories: mappedCategories, includeMessages: [], excludeMessages: [])
|
let _ = (component.context.engine.resources.clearStorage(peerId: component.peer?.id, categories: mappedCategories, includeMessages: [], excludeMessages: [])
|
||||||
|> deliverOnMainQueue).start(completed: { [weak self] in
|
|> deliverOnMainQueue).start(next: { [weak self] progress in
|
||||||
guard let self, let _ = self.component, let aggregatedData = self.aggregatedData else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var totalSize: Int64 = 0
|
self.updateClearProgress(progress: progress)
|
||||||
|
}, completed: { [weak self] in
|
||||||
let contextStats = aggregatedData.contextStats
|
guard let self else {
|
||||||
|
return
|
||||||
for category in aggregatedData.selectedCategories {
|
|
||||||
let mappedCategory: StorageUsageStats.CategoryKey
|
|
||||||
switch category {
|
|
||||||
case .photos:
|
|
||||||
mappedCategory = .photos
|
|
||||||
case .videos:
|
|
||||||
mappedCategory = .videos
|
|
||||||
case .files:
|
|
||||||
mappedCategory = .files
|
|
||||||
case .music:
|
|
||||||
mappedCategory = .music
|
|
||||||
case .other:
|
|
||||||
continue
|
|
||||||
case .stickers:
|
|
||||||
mappedCategory = .stickers
|
|
||||||
case .avatars:
|
|
||||||
mappedCategory = .avatars
|
|
||||||
case .misc:
|
|
||||||
mappedCategory = .misc
|
|
||||||
}
|
|
||||||
|
|
||||||
if let value = contextStats.categories[mappedCategory] {
|
|
||||||
totalSize += value.size
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reloadStats(firstTime: false, completion: { [weak self] in
|
self.reloadStats(firstTime: false, completion: { [weak self] in
|
||||||
@ -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 {
|
||||||
@ -3562,8 +3584,10 @@ private class StorageUsageClearProgressOverlayNode: ASDisplayNode {
|
|||||||
self.descriptionTextNode.attributedText = NSAttributedString(string: self.presentationData.strings.ClearCache_KeepOpenedDescription, font: Font.regular(15.0), textColor: self.presentationData.theme.actionSheet.secondaryTextColor)
|
self.descriptionTextNode.attributedText = NSAttributedString(string: self.presentationData.strings.ClearCache_KeepOpenedDescription, font: Font.regular(15.0), textColor: self.presentationData.theme.actionSheet.secondaryTextColor)
|
||||||
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)
|
||||||
|
|
||||||
|
let progressText: String = "\(Int(self.progress * 100.0))%"
|
||||||
|
|
||||||
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)
|
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