Skip to content

Commit

Permalink
change the camera view to the new custom camera
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailsaqan committed Jan 2, 2024
1 parent 40134b4 commit 24efb71
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
6 changes: 6 additions & 0 deletions damus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
BA4AB0AE2A63B9270070A32A /* AddEmojiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */; };
BA4AB0B02A63B94D0070A32A /* EmojiListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */; };
BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; };
BAA578D52AED7F4000EA8BE3 /* CameraView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA578D42AED7F4000EA8BE3 /* CameraView.swift */; };
BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */; };
D2277EEA2A089BD5006C3807 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2277EE92A089BD5006C3807 /* Router.swift */; };
D70A3B172B02DCE5008BD568 /* NotificationFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70A3B162B02DCE5008BD568 /* NotificationFormatter.swift */; };
Expand Down Expand Up @@ -1247,6 +1248,7 @@
BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddEmojiView.swift; sourceTree = "<group>"; };
BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiListItemView.swift; sourceTree = "<group>"; };
BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = "<group>"; };
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraView.swift; sourceTree = "<group>"; };
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = "<group>"; };
D2277EE92A089BD5006C3807 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
D70A3B162B02DCE5008BD568 /* NotificationFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationFormatter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2486,6 +2488,7 @@
isa = PBXGroup;
children = (
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */,
);
path = Camera;
sourceTree = "<group>";
Expand All @@ -2495,6 +2498,8 @@
children = (
D72A2D042AD9C1B5002AFF62 /* MockDamusState.swift */,
D72A2D062AD9C1FB002AFF62 /* MockProfiles.swift */,
BAA8C3262AEC570800696158 /* CameraView.swift */,
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
);
path = Mocking;
sourceTree = "<group>";
Expand Down Expand Up @@ -2975,6 +2980,7 @@
4CC7AAF8297F1CEE00430951 /* EventProfile.swift in Sources */,
5CF2DCCC2AA3AF0B00984B8D /* RelayPicView.swift in Sources */,
4C687C242A5FA86D0092C550 /* SearchHeaderView.swift in Sources */,
BAA578D52AED7F4000EA8BE3 /* CameraView.swift in Sources */,
64FBD06F296255C400D9D3B2 /* Theme.swift in Sources */,
4C1A9A2329DDDB8100516EAC /* IconLabel.swift in Sources */,
4CA352AC2A76C07F003BB08B /* NewUnmutesNotify.swift in Sources */,
Expand Down
8 changes: 8 additions & 0 deletions damus/Views/Camera/CameraView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CameraView.swift
// damus
//
// Created by Suhail Saqan on 10/28/23.
//

import Foundation
42 changes: 22 additions & 20 deletions damus/Views/PostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct PostView: View {
@State var newCursorIndex: Int?
@State var textHeight: CGFloat? = nil

@State var mediaToUpload: MediaUpload? = nil
@State var mediaToUpload: [MediaUpload] = []

@StateObject var image_upload: ImageUploadModel = ImageUploadModel()
@StateObject var tagModel: TagModel = TagModel()
Expand Down Expand Up @@ -379,6 +379,15 @@ struct PostView: View {
pks.append(pk)
}
}

func addToMediaToUpload(mediaItem: MediaItem) {
switch mediaItem.type {
case .image:
mediaToUpload.append(.image(mediaItem.url))
case .video:
mediaToUpload.append(.video(mediaItem.url))
}
}

var body: some View {
GeometryReader { (deviceSize: GeometryProxy) in
Expand Down Expand Up @@ -421,36 +430,29 @@ struct PostView: View {
.background(DamusColors.adaptableWhite.edgesIgnoringSafeArea(.all))
.sheet(isPresented: $attach_media) {
ImagePicker(uploader: damus_state.settings.default_media_uploader, sourceType: .photoLibrary, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in
self.mediaToUpload = .image(img)
self.mediaToUpload.append(.image(img))
} onVideoPicked: { url in
self.mediaToUpload = .video(url)
self.mediaToUpload.append(.video(url))
}
.alert(NSLocalizedString("Are you sure you want to upload this media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) {
Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
if let mediaToUpload {
self.handle_upload(media: mediaToUpload)
if !mediaToUpload.isEmpty {
self.handle_upload(media: mediaToUpload[0])
self.attach_media = false
}
}
Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {}
}
}
.sheet(isPresented: $attach_camera) {

ImagePicker(uploader: damus_state.settings.default_media_uploader, sourceType: .camera, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in
self.mediaToUpload = .image(img)
} onVideoPicked: { url in
self.mediaToUpload = .video(url)
}
.alert(NSLocalizedString("Are you sure you want to upload this media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) {
Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
if let mediaToUpload {
self.handle_upload(media: mediaToUpload)
self.attach_camera = false
}
.fullScreenCover(isPresented: $attach_camera) {
CameraView(damus_state: damus_state, action: { items in
for item in items {
addToMediaToUpload(mediaItem: item)
}
Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {}
}
for media in mediaToUpload {
self.handle_upload(media: media)
}
})
}
.onAppear() {
let loaded_draft = load_draft()
Expand Down

0 comments on commit 24efb71

Please sign in to comment.