Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 71a7ba1

Browse files
committedAug 10, 2023
redid everything, much faster
1 parent e6161db commit 71a7ba1

11 files changed

+1397
-211
lines changed
 

‎damus.xcodeproj/project.pbxproj

+41-9
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@
377377
9609F058296E220800069BF3 /* BannerImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9609F057296E220800069BF3 /* BannerImageView.swift */; };
378378
9C83F89329A937B900136C08 /* TextViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C83F89229A937B900136C08 /* TextViewWrapper.swift */; };
379379
9CA876E229A00CEA0003B9A3 /* AttachMediaUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */; };
380+
BA27222E2A806E39004CDF52 /* VideoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA27222D2A806E39004CDF52 /* VideoCaptureProcessor.swift */; };
381+
BA3BF2892A7F156B00600232 /* PhotoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2842A7F156900600232 /* PhotoCaptureProcessor.swift */; };
382+
BA3BF28A2A7F156B00600232 /* ImageResizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2852A7F156900600232 /* ImageResizer.swift */; };
383+
BA3BF28B2A7F156B00600232 /* CameraService+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2862A7F156A00600232 /* CameraService+Extensions.swift */; };
384+
BA3BF28C2A7F156B00600232 /* CameraService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2872A7F156A00600232 /* CameraService.swift */; };
385+
BA3BF28F2A7F1B2D00600232 /* CameraModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF28E2A7F1B2D00600232 /* CameraModel.swift */; };
380386
BA4AB0AE2A63B9270070A32A /* AddEmojiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */; };
381387
BA4AB0B02A63B94D0070A32A /* EmojiListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */; };
382388
BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; };
@@ -931,6 +937,12 @@
931937
9609F057296E220800069BF3 /* BannerImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerImageView.swift; sourceTree = "<group>"; };
932938
9C83F89229A937B900136C08 /* TextViewWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewWrapper.swift; sourceTree = "<group>"; };
933939
9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachMediaUtility.swift; sourceTree = "<group>"; };
940+
BA27222D2A806E39004CDF52 /* VideoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCaptureProcessor.swift; sourceTree = "<group>"; };
941+
BA3BF2842A7F156900600232 /* PhotoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureProcessor.swift; sourceTree = "<group>"; };
942+
BA3BF2852A7F156900600232 /* ImageResizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResizer.swift; sourceTree = "<group>"; };
943+
BA3BF2862A7F156A00600232 /* CameraService+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CameraService+Extensions.swift"; sourceTree = "<group>"; };
944+
BA3BF2872A7F156A00600232 /* CameraService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraService.swift; sourceTree = "<group>"; };
945+
BA3BF28E2A7F1B2D00600232 /* CameraModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraModel.swift; sourceTree = "<group>"; };
934946
BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddEmojiView.swift; sourceTree = "<group>"; };
935947
BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiListItemView.swift; sourceTree = "<group>"; };
936948
BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = "<group>"; };
@@ -1077,6 +1089,7 @@
10771089
4C0A3F8D280F63FF000448DE /* Models */ = {
10781090
isa = PBXGroup;
10791091
children = (
1092+
BA3BF2832A7F151300600232 /* Camera */,
10801093
4C190F1E2A535FC200027FD5 /* Zaps */,
10811094
4C54AA0829A55416003E4487 /* Notifications */,
10821095
3AA247FC297E3CFF0090C62D /* RepostsModel.swift */,
@@ -1868,15 +1881,17 @@
18681881
path = Extensions;
18691882
sourceTree = "<group>";
18701883
};
1871-
F71694E82A66221E001F4053 /* Onboarding */ = {
1884+
BA3BF2832A7F151300600232 /* Camera */ = {
18721885
isa = PBXGroup;
18731886
children = (
1874-
F71694E92A662232001F4053 /* SuggestedUsersView.swift */,
1875-
F71694F12A67314D001F4053 /* SuggestedUserView.swift */,
1876-
F71694EB2A662292001F4053 /* SuggestedUsersViewModel.swift */,
1877-
F71694ED2A6624F9001F4053 /* suggested_users.json */,
1887+
BA27222D2A806E39004CDF52 /* VideoCaptureProcessor.swift */,
1888+
BA3BF2872A7F156A00600232 /* CameraService.swift */,
1889+
BA3BF2862A7F156A00600232 /* CameraService+Extensions.swift */,
1890+
BA3BF2852A7F156900600232 /* ImageResizer.swift */,
1891+
BA3BF2842A7F156900600232 /* PhotoCaptureProcessor.swift */,
1892+
BA3BF28E2A7F1B2D00600232 /* CameraModel.swift */,
18781893
);
1879-
path = Onboarding;
1894+
path = Camera;
18801895
sourceTree = "<group>";
18811896
};
18821897
BA8A4F0D2A2D95880045C48C /* Camera */ = {
@@ -1888,6 +1903,17 @@
18881903
path = Camera;
18891904
sourceTree = "<group>";
18901905
};
1906+
F71694E82A66221E001F4053 /* Onboarding */ = {
1907+
isa = PBXGroup;
1908+
children = (
1909+
F71694E92A662232001F4053 /* SuggestedUsersView.swift */,
1910+
F71694F12A67314D001F4053 /* SuggestedUserView.swift */,
1911+
F71694EB2A662292001F4053 /* SuggestedUsersViewModel.swift */,
1912+
F71694ED2A6624F9001F4053 /* suggested_users.json */,
1913+
);
1914+
path = Onboarding;
1915+
sourceTree = "<group>";
1916+
};
18911917
F7F0BA23297892AE009531F3 /* Modifiers */ = {
18921918
isa = PBXGroup;
18931919
children = (
@@ -2127,6 +2153,7 @@
21272153
4C190F252A547D2000027FD5 /* LoadScript.swift in Sources */,
21282154
4C59B98C2A76C2550032FFEB /* ProfileUpdatedNotify.swift in Sources */,
21292155
4C363A8C28236B92006E126D /* PubkeyView.swift in Sources */,
2156+
BA3BF28A2A7F156B00600232 /* ImageResizer.swift in Sources */,
21302157
4CDA128A29E9D10C0006FA5A /* SignalView.swift in Sources */,
21312158
4C12535C2A76CA540004F4B8 /* LoginNotify.swift in Sources */,
21322159
4C5C7E68284ED36500A22DF5 /* SearchHomeModel.swift in Sources */,
@@ -2201,6 +2228,7 @@
22012228
4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */,
22022229
4C30AC7629A5770900E2BD5A /* NotificationItemView.swift in Sources */,
22032230
4C86F7C42A76C44C00EC0817 /* ZappingNotify.swift in Sources */,
2231+
BA27222E2A806E39004CDF52 /* VideoCaptureProcessor.swift in Sources */,
22042232
4C363A8428233689006E126D /* Parser.swift in Sources */,
22052233
3AAA95CA298DF87B00F3D526 /* TranslationService.swift in Sources */,
22062234
4CE4F9E328528C5200C00DD9 /* AddRelayView.swift in Sources */,
@@ -2294,13 +2322,15 @@
22942322
4C4E137D2A76D63600BDD832 /* UnmuteThreadNotify.swift in Sources */,
22952323
4CE4F0F829DB7399005914DB /* ThiccDivider.swift in Sources */,
22962324
4CE0E2B629A3ED5500DB4CA2 /* InnerTimelineView.swift in Sources */,
2325+
BA3BF28C2A7F156B00600232 /* CameraService.swift in Sources */,
22972326
4C363A8828236948006E126D /* BlocksView.swift in Sources */,
22982327
4C06670628FCB08600038D2A /* ImageCarousel.swift in Sources */,
22992328
3A23838E2A297DD200E5AA2E /* ZapButtonModel.swift in Sources */,
23002329
F71694F82A6983AF001F4053 /* GrayGradient.swift in Sources */,
23012330
4C1D4FB12A7958E60024F453 /* VersionInfo.swift in Sources */,
23022331
5053ACA72A56DF3B00851AE3 /* DeveloperSettingsView.swift in Sources */,
23032332
F79C7FAD29D5E9620000F946 /* EditPictureControl.swift in Sources */,
2333+
BA3BF2892A7F156B00600232 /* PhotoCaptureProcessor.swift in Sources */,
23042334
4C9F18E229AA9B6C008C55EC /* CustomizeZapView.swift in Sources */,
23052335
4C2859602A12A2BE004746F7 /* SupporterBadge.swift in Sources */,
23062336
4C1A9A2A29DDF54400516EAC /* DamusVideoPlayer.swift in Sources */,
@@ -2373,6 +2403,7 @@
23732403
4C3EA66028FF5E7700C48A62 /* node_id.c in Sources */,
23742404
4C687C212A5F7ED00092C550 /* DamusBackground.swift in Sources */,
23752405
4CA352A02A76AE80003BB08B /* Notify.swift in Sources */,
2406+
BA3BF28B2A7F156B00600232 /* CameraService+Extensions.swift in Sources */,
23762407
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */,
23772408
4C1253582A76C9060004F4B8 /* PresentSheetNotify.swift in Sources */,
23782409
4C363A962827096D006E126D /* PostBlock.swift in Sources */,
@@ -2417,6 +2448,7 @@
24172448
5C513FBA297F72980072348F /* CustomPicker.swift in Sources */,
24182449
4C1253622A76D00B0004F4B8 /* PostNotify.swift in Sources */,
24192450
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */,
2451+
BA3BF28F2A7F1B2D00600232 /* CameraModel.swift in Sources */,
24202452
F7908E92298B0F0700AB113A /* RelayDetailView.swift in Sources */,
24212453
4C9147002A2A891E00DDEA40 /* error.c in Sources */,
24222454
4CE879552996BAB900F758CC /* RelayPaidDetail.swift in Sources */,
@@ -2764,7 +2796,7 @@
27642796
CODE_SIGN_STYLE = Automatic;
27652797
CURRENT_PROJECT_VERSION = 11;
27662798
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
2767-
DEVELOPMENT_TEAM = XK7H4JAB3D;
2799+
DEVELOPMENT_TEAM = XL4476DR2X;
27682800
ENABLE_PREVIEWS = YES;
27692801
GENERATE_INFOPLIST_FILE = YES;
27702802
INFOPLIST_FILE = damus/Info.plist;
@@ -2790,7 +2822,7 @@
27902822
"$(PROJECT_DIR)",
27912823
);
27922824
MARKETING_VERSION = 1.6;
2793-
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus2;
2825+
PRODUCT_BUNDLE_IDENTIFIER = com.suhail.damus2;
27942826
PRODUCT_NAME = "$(TARGET_NAME)";
27952827
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
27962828
SUPPORTS_MACCATALYST = YES;
@@ -2813,7 +2845,7 @@
28132845
CODE_SIGN_STYLE = Automatic;
28142846
CURRENT_PROJECT_VERSION = 11;
28152847
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
2816-
DEVELOPMENT_TEAM = XK7H4JAB3D;
2848+
DEVELOPMENT_TEAM = XL4476DR2X;
28172849
ENABLE_PREVIEWS = YES;
28182850
GENERATE_INFOPLIST_FILE = YES;
28192851
INFOPLIST_FILE = damus/Info.plist;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
"version" : 2
39+
}

‎damus/Models/Camera/CameraModel.swift

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//
2+
// CameraModel.swift
3+
// damus
4+
//
5+
// Created by Suhail Saqan on 8/5/23.
6+
//
7+
8+
import Foundation
9+
import AVFoundation
10+
import Combine
11+
12+
final class CameraModel: ObservableObject {
13+
private let service = CameraService()
14+
15+
@Published var showAlertError = false
16+
17+
@Published var isFlashOn = false
18+
19+
@Published var willCapturePhoto = false
20+
21+
@Published var isCameraButtonDisabled = false
22+
23+
@Published var isPhotoProcessing = false
24+
25+
@Published var isRecording = false
26+
27+
@Published var captureMode: CameraMediaType = .image
28+
29+
@Published public var mediaItems: [MediaItem] = []
30+
31+
@Published var thumbnail: Thumbnail!
32+
33+
var alertError: AlertError!
34+
35+
var session: AVCaptureSession
36+
37+
private var subscriptions = Set<AnyCancellable>()
38+
39+
init() {
40+
self.session = service.session
41+
42+
service.$shouldShowAlertView.sink { [weak self] (val) in
43+
self?.alertError = self?.service.alertError
44+
self?.showAlertError = val
45+
}
46+
.store(in: &self.subscriptions)
47+
48+
service.$flashMode.sink { [weak self] (mode) in
49+
self?.isFlashOn = mode == .on
50+
}
51+
.store(in: &self.subscriptions)
52+
53+
service.$willCapturePhoto.sink { [weak self] (val) in
54+
self?.willCapturePhoto = val
55+
}
56+
.store(in: &self.subscriptions)
57+
58+
service.$isCameraButtonDisabled.sink { [weak self] (val) in
59+
self?.isCameraButtonDisabled = val
60+
}
61+
.store(in: &self.subscriptions)
62+
63+
service.$isPhotoProcessing.sink { [weak self] (val) in
64+
self?.isPhotoProcessing = val
65+
}
66+
.store(in: &self.subscriptions)
67+
68+
service.$isRecording.sink { [weak self] (val) in
69+
self?.isRecording = val
70+
}
71+
.store(in: &self.subscriptions)
72+
73+
service.$captureMode.sink { [weak self] (mode) in
74+
self?.captureMode = mode
75+
}
76+
.store(in: &self.subscriptions)
77+
78+
service.$mediaItems.sink { [weak self] (mode) in
79+
self?.mediaItems = mode
80+
}
81+
.store(in: &self.subscriptions)
82+
83+
service.$thumbnail.sink { [weak self] (thumbnail) in
84+
guard let pic = thumbnail else { return }
85+
self?.thumbnail = pic
86+
}
87+
.store(in: &self.subscriptions)
88+
}
89+
90+
func configure() {
91+
service.checkForPermissions()
92+
service.configure()
93+
}
94+
95+
func stop() {
96+
service.stop()
97+
}
98+
99+
func capturePhoto() {
100+
service.capturePhoto()
101+
}
102+
103+
func startRecording() {
104+
service.startRecording()
105+
}
106+
107+
func stopRecording() {
108+
service.stopRecording()
109+
}
110+
111+
func flipCamera() {
112+
service.changeCamera()
113+
}
114+
115+
func zoom(with factor: CGFloat) {
116+
service.set(zoom: factor)
117+
}
118+
119+
func switchFlash() {
120+
service.flashMode = service.flashMode == .on ? .off : .on
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// CameraService+Extensions.swift
3+
// Campus
4+
//
5+
// Created by Rolando Rodriguez on 1/11/20.
6+
// Copyright © 2020 Rolando Rodriguez. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
import AVFoundation
12+
13+
extension AVCaptureVideoOrientation {
14+
init?(deviceOrientation: UIDeviceOrientation) {
15+
switch deviceOrientation {
16+
case .portrait: self = .portrait
17+
case .portraitUpsideDown: self = .portraitUpsideDown
18+
case .landscapeLeft: self = .landscapeRight
19+
case .landscapeRight: self = .landscapeLeft
20+
default: return nil
21+
}
22+
}
23+
24+
init?(interfaceOrientation: UIInterfaceOrientation) {
25+
switch interfaceOrientation {
26+
case .portrait: self = .portrait
27+
case .portraitUpsideDown: self = .portraitUpsideDown
28+
case .landscapeLeft: self = .landscapeLeft
29+
case .landscapeRight: self = .landscapeRight
30+
default: return nil
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.