Skip to content

Commit bf363e9

Browse files
committed
add media upload counter next to progress bar
1 parent 50a4190 commit bf363e9

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "gsplayer",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/wxxsw/GSPlayer",
7+
"state" : {
8+
"revision" : "aa6dad7943d52f5207f7fcc2ad3e4274583443b8",
9+
"version" : "0.2.26"
10+
}
11+
},
12+
{
13+
"identity" : "kingfisher",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/onevcat/Kingfisher",
16+
"state" : {
17+
"revision" : "415b1d97fb38bda1e5a6b2dde63354720832110b",
18+
"version" : "7.6.1"
19+
}
20+
},
21+
{
22+
"identity" : "secp256k1.swift",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/jb55/secp256k1.swift",
25+
"state" : {
26+
"revision" : "40b4b38b3b1c83f7088c76189a742870e0ca06a9"
27+
}
28+
},
29+
{
30+
"identity" : "swift-markdown-ui",
31+
"kind" : "remoteSourceControl",
32+
"location" : "https://github.com/damus-io/swift-markdown-ui",
33+
"state" : {
34+
"revision" : "76bb7971da7fbf429de1c84f1244adf657242fee"
35+
}
36+
},
37+
{
38+
"identity" : "swift-snapshot-testing",
39+
"kind" : "remoteSourceControl",
40+
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
41+
"state" : {
42+
"revision" : "5b356adceabff6ca027f6574aac79e9fee145d26",
43+
"version" : "1.14.1"
44+
}
45+
},
46+
{
47+
"identity" : "swift-syntax",
48+
"kind" : "remoteSourceControl",
49+
"location" : "https://github.com/apple/swift-syntax.git",
50+
"state" : {
51+
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b",
52+
"version" : "509.0.0"
53+
}
54+
}
55+
],
56+
"version" : 2
57+
}

damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
savedToolIdentifier = ""
7878
useCustomWorkingDirectory = "NO"
7979
debugDocumentVersioning = "YES"
80+
askForAppToLaunch = "Yes"
8081
launchAutomaticallySubstyle = "2">
8182
<BuildableProductRunnable
8283
runnableDebuggingMode = "0">

damus/Models/ImageUploadModel.swift

+21-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ enum MediaUpload {
5353

5454
class ImageUploadModel: NSObject, URLSessionTaskDelegate, ObservableObject {
5555
@Published var progress: Double? = nil
56+
@Published var currentImagesUploaded: Int = 0
57+
@Published var totalImagesToUpload: Int = 0
58+
private var completedUploads: Int = 0
5659

5760
func start(media: MediaUpload, uploader: MediaUploader, keypair: Keypair? = nil) async -> ImageUploadResult {
58-
let res = await create_upload_request(mediaToUpload: media, mediaUploader: uploader, progress: self, keypair: keypair)
5961
DispatchQueue.main.async {
60-
self.progress = nil
62+
self.totalImagesToUpload += 1
6163
}
64+
let res = await create_upload_request(mediaToUpload: media, mediaUploader: uploader, progress: self, keypair: keypair)
6265
return res
6366
}
6467

@@ -67,4 +70,20 @@ class ImageUploadModel: NSObject, URLSessionTaskDelegate, ObservableObject {
6770
self.progress = Double(totalBytesSent) / Double(totalBytesExpectedToSend)
6871
}
6972
}
73+
74+
func didFinishUpload() {
75+
DispatchQueue.main.async {
76+
self.completedUploads += 1
77+
self.currentImagesUploaded = self.completedUploads
78+
}
79+
}
80+
81+
func resetProgress() {
82+
DispatchQueue.main.async {
83+
self.progress = nil
84+
self.currentImagesUploaded = 0
85+
self.totalImagesToUpload = 0
86+
self.completedUploads = 0
87+
}
88+
}
7089
}

damus/Views/PostView.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,11 @@ struct PostView: View {
285285
}
286286

287287
if let progress = image_upload.progress {
288-
ProgressView(value: progress, total: 1.0)
289-
.progressViewStyle(.linear)
288+
HStack {
289+
ProgressView(value: progress, total: 1.0)
290+
.progressViewStyle(.linear)
291+
Text("\(image_upload.currentImagesUploaded)/\(image_upload.totalImagesToUpload)")
292+
}
290293
}
291294

292295
Divider()
@@ -316,6 +319,7 @@ struct PostView: View {
316319
let meta = blurhash.map { bh in calculate_image_metadata(url: url, img: img, blurhash: bh) }
317320
let uploadedMedia = UploadedMedia(localURL: media.localURL, uploadedURL: url, representingImage: img, metadata: meta)
318321
uploadedMedias.append(uploadedMedia)
322+
image_upload.didFinishUpload()
319323

320324
case .failed(let error):
321325
if let error {
@@ -325,6 +329,9 @@ struct PostView: View {
325329
}
326330
}
327331

332+
if (image_upload.currentImagesUploaded + 1) == image_upload.totalImagesToUpload {
333+
image_upload.resetProgress()
334+
}
328335
}
329336
}
330337

0 commit comments

Comments
 (0)