commit f5d74653684cc82ff721c605959339e713bcb420
parent 8a785559c68673f4b122da83806c15661ed703cc
Author: Swift <scoder1747@gmail.com>
Date: Thu, 6 Apr 2023 18:30:29 -0400
Ask permission before uploading media
Changelog-Changed: Ask permission before uploading media
Closes: #886
Diffstat:
3 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/damus/Views/ImagePicker.swift b/damus/Views/ImagePicker.swift
@@ -15,6 +15,7 @@ struct ImagePicker: UIViewControllerRepresentable {
let sourceType: UIImagePickerController.SourceType
let pubkey: String
+ @Binding var image_upload_confirm: Bool
var imagesOnly: Bool = false
let onImagePicked: (URL) -> Void
let onVideoPicked: (URL) -> Void
@@ -24,15 +25,18 @@ struct ImagePicker: UIViewControllerRepresentable {
private let sourceType: UIImagePickerController.SourceType
private let onImagePicked: (URL) -> Void
private let onVideoPicked: (URL) -> Void
+ @Binding var image_upload_confirm: Bool
init(presentationMode: Binding<PresentationMode>,
sourceType: UIImagePickerController.SourceType,
onImagePicked: @escaping (URL) -> Void,
- onVideoPicked: @escaping (URL) -> Void) {
+ onVideoPicked: @escaping (URL) -> Void,
+ image_upload_confirm: Binding<Bool>) {
_presentationMode = presentationMode
self.sourceType = sourceType
self.onImagePicked = onImagePicked
self.onVideoPicked = onVideoPicked
+ self._image_upload_confirm = image_upload_confirm
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
@@ -51,9 +55,9 @@ struct ImagePicker: UIViewControllerRepresentable {
onImagePicked(editedImageURL)
}
}
- presentationMode.dismiss()
+ image_upload_confirm = true
}
-
+
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
presentationMode.dismiss()
}
@@ -98,7 +102,7 @@ struct ImagePicker: UIViewControllerRepresentable {
onVideoPicked: { videoURL in
// Handle the selected video URL
onVideoPicked(videoURL)
- })
+ }, image_upload_confirm: $image_upload_confirm)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController {
diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift
@@ -23,8 +23,11 @@ struct PostView: View {
@State var attach_camera: Bool = false
@State var error: String? = nil
@State var uploadedMedias: [UploadedMedia] = []
+ @State var image_upload_confirm: Bool = false
@State var originalReferences: [ReferencedId] = []
@State var references: [ReferencedId] = []
+
+ @State var mediaToUpload: MediaUpload? = nil
@StateObject var image_upload: ImageUploadModel = ImageUploadModel()
@@ -254,14 +257,22 @@ struct PostView: View {
}
}
.sheet(isPresented: $attach_media) {
- ImagePicker(sourceType: .photoLibrary, pubkey: damus_state.pubkey) { img in
- handle_upload(media: .image(img))
+ ImagePicker(sourceType: .photoLibrary, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in
+ self.mediaToUpload = .image(img)
} onVideoPicked: { url in
- handle_upload(media: .video(url))
+ self.mediaToUpload = .video(url)
+ }
+ .alert("Confirm upload?", isPresented: $image_upload_confirm) {
+ Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
+ self.handle_upload(media: mediaToUpload!)
+ self.attach_media = false
+ }
+ Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {}
}
}
.sheet(isPresented: $attach_camera) {
- ImagePicker(sourceType: .camera, pubkey: damus_state.pubkey) { img in
+ // image_upload_confirm isn't handled here, I don't know we need to display it here too tbh
+ ImagePicker(sourceType: .camera, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in
handle_upload(media: .image(img))
} onVideoPicked: { url in
handle_upload(media: .video(url))
diff --git a/damus/Views/Profile/EditProfilePictureControl.swift b/damus/Views/Profile/EditProfilePictureControl.swift
@@ -18,7 +18,8 @@ struct EditProfilePictureControl: View {
@State private var show_camera = false
@State private var show_library = false
-
+ @State var image_upload_confirm: Bool = false
+
var body: some View {
Menu {
Button(action: {
@@ -44,14 +45,16 @@ struct EditProfilePictureControl: View {
}
}
.sheet(isPresented: $show_camera) {
- ImagePicker(sourceType: .camera, pubkey: pubkey, imagesOnly: true) { img in
+ // The alert may not be required for the profile pic upload case. Not showing the confirm check alert for this scenario
+ ImagePicker(sourceType: .camera, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in
handle_upload(media: .image(img))
} onVideoPicked: { url in
print("Cannot upload videos as profile image")
}
}
.sheet(isPresented: $show_library) {
- ImagePicker(sourceType: .photoLibrary, pubkey: pubkey, imagesOnly: true) { img in
+ // The alert may not be required for the profile pic upload case. Not showing the confirm check alert for this scenario
+ ImagePicker(sourceType: .photoLibrary, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in
handle_upload(media: .image(img))
} onVideoPicked: { url in
print("Cannot upload videos as profile image")