Skip to content

Commit

Permalink
redid everything, much faster
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailsaqan committed Aug 10, 2023
1 parent e6161db commit 71a7ba1
Show file tree
Hide file tree
Showing 11 changed files with 1,397 additions and 211 deletions.
50 changes: 41 additions & 9 deletions damus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@
9609F058296E220800069BF3 /* BannerImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9609F057296E220800069BF3 /* BannerImageView.swift */; };
9C83F89329A937B900136C08 /* TextViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C83F89229A937B900136C08 /* TextViewWrapper.swift */; };
9CA876E229A00CEA0003B9A3 /* AttachMediaUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */; };
BA27222E2A806E39004CDF52 /* VideoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA27222D2A806E39004CDF52 /* VideoCaptureProcessor.swift */; };
BA3BF2892A7F156B00600232 /* PhotoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2842A7F156900600232 /* PhotoCaptureProcessor.swift */; };
BA3BF28A2A7F156B00600232 /* ImageResizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2852A7F156900600232 /* ImageResizer.swift */; };
BA3BF28B2A7F156B00600232 /* CameraService+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2862A7F156A00600232 /* CameraService+Extensions.swift */; };
BA3BF28C2A7F156B00600232 /* CameraService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF2872A7F156A00600232 /* CameraService.swift */; };
BA3BF28F2A7F1B2D00600232 /* CameraModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3BF28E2A7F1B2D00600232 /* CameraModel.swift */; };
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 */; };
Expand Down Expand Up @@ -931,6 +937,12 @@
9609F057296E220800069BF3 /* BannerImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerImageView.swift; sourceTree = "<group>"; };
9C83F89229A937B900136C08 /* TextViewWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewWrapper.swift; sourceTree = "<group>"; };
9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachMediaUtility.swift; sourceTree = "<group>"; };
BA27222D2A806E39004CDF52 /* VideoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCaptureProcessor.swift; sourceTree = "<group>"; };
BA3BF2842A7F156900600232 /* PhotoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureProcessor.swift; sourceTree = "<group>"; };
BA3BF2852A7F156900600232 /* ImageResizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResizer.swift; sourceTree = "<group>"; };
BA3BF2862A7F156A00600232 /* CameraService+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CameraService+Extensions.swift"; sourceTree = "<group>"; };
BA3BF2872A7F156A00600232 /* CameraService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraService.swift; sourceTree = "<group>"; };
BA3BF28E2A7F1B2D00600232 /* CameraModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraModel.swift; sourceTree = "<group>"; };
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>"; };
Expand Down Expand Up @@ -1077,6 +1089,7 @@
4C0A3F8D280F63FF000448DE /* Models */ = {
isa = PBXGroup;
children = (
BA3BF2832A7F151300600232 /* Camera */,
4C190F1E2A535FC200027FD5 /* Zaps */,
4C54AA0829A55416003E4487 /* Notifications */,
3AA247FC297E3CFF0090C62D /* RepostsModel.swift */,
Expand Down Expand Up @@ -1868,15 +1881,17 @@
path = Extensions;
sourceTree = "<group>";
};
F71694E82A66221E001F4053 /* Onboarding */ = {
BA3BF2832A7F151300600232 /* Camera */ = {
isa = PBXGroup;
children = (
F71694E92A662232001F4053 /* SuggestedUsersView.swift */,
F71694F12A67314D001F4053 /* SuggestedUserView.swift */,
F71694EB2A662292001F4053 /* SuggestedUsersViewModel.swift */,
F71694ED2A6624F9001F4053 /* suggested_users.json */,
BA27222D2A806E39004CDF52 /* VideoCaptureProcessor.swift */,
BA3BF2872A7F156A00600232 /* CameraService.swift */,
BA3BF2862A7F156A00600232 /* CameraService+Extensions.swift */,
BA3BF2852A7F156900600232 /* ImageResizer.swift */,
BA3BF2842A7F156900600232 /* PhotoCaptureProcessor.swift */,
BA3BF28E2A7F1B2D00600232 /* CameraModel.swift */,
);
path = Onboarding;
path = Camera;
sourceTree = "<group>";
};
BA8A4F0D2A2D95880045C48C /* Camera */ = {
Expand All @@ -1888,6 +1903,17 @@
path = Camera;
sourceTree = "<group>";
};
F71694E82A66221E001F4053 /* Onboarding */ = {
isa = PBXGroup;
children = (
F71694E92A662232001F4053 /* SuggestedUsersView.swift */,
F71694F12A67314D001F4053 /* SuggestedUserView.swift */,
F71694EB2A662292001F4053 /* SuggestedUsersViewModel.swift */,
F71694ED2A6624F9001F4053 /* suggested_users.json */,
);
path = Onboarding;
sourceTree = "<group>";
};
F7F0BA23297892AE009531F3 /* Modifiers */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2127,6 +2153,7 @@
4C190F252A547D2000027FD5 /* LoadScript.swift in Sources */,
4C59B98C2A76C2550032FFEB /* ProfileUpdatedNotify.swift in Sources */,
4C363A8C28236B92006E126D /* PubkeyView.swift in Sources */,
BA3BF28A2A7F156B00600232 /* ImageResizer.swift in Sources */,
4CDA128A29E9D10C0006FA5A /* SignalView.swift in Sources */,
4C12535C2A76CA540004F4B8 /* LoginNotify.swift in Sources */,
4C5C7E68284ED36500A22DF5 /* SearchHomeModel.swift in Sources */,
Expand Down Expand Up @@ -2201,6 +2228,7 @@
4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */,
4C30AC7629A5770900E2BD5A /* NotificationItemView.swift in Sources */,
4C86F7C42A76C44C00EC0817 /* ZappingNotify.swift in Sources */,
BA27222E2A806E39004CDF52 /* VideoCaptureProcessor.swift in Sources */,
4C363A8428233689006E126D /* Parser.swift in Sources */,
3AAA95CA298DF87B00F3D526 /* TranslationService.swift in Sources */,
4CE4F9E328528C5200C00DD9 /* AddRelayView.swift in Sources */,
Expand Down Expand Up @@ -2294,13 +2322,15 @@
4C4E137D2A76D63600BDD832 /* UnmuteThreadNotify.swift in Sources */,
4CE4F0F829DB7399005914DB /* ThiccDivider.swift in Sources */,
4CE0E2B629A3ED5500DB4CA2 /* InnerTimelineView.swift in Sources */,
BA3BF28C2A7F156B00600232 /* CameraService.swift in Sources */,
4C363A8828236948006E126D /* BlocksView.swift in Sources */,
4C06670628FCB08600038D2A /* ImageCarousel.swift in Sources */,
3A23838E2A297DD200E5AA2E /* ZapButtonModel.swift in Sources */,
F71694F82A6983AF001F4053 /* GrayGradient.swift in Sources */,
4C1D4FB12A7958E60024F453 /* VersionInfo.swift in Sources */,
5053ACA72A56DF3B00851AE3 /* DeveloperSettingsView.swift in Sources */,
F79C7FAD29D5E9620000F946 /* EditPictureControl.swift in Sources */,
BA3BF2892A7F156B00600232 /* PhotoCaptureProcessor.swift in Sources */,
4C9F18E229AA9B6C008C55EC /* CustomizeZapView.swift in Sources */,
4C2859602A12A2BE004746F7 /* SupporterBadge.swift in Sources */,
4C1A9A2A29DDF54400516EAC /* DamusVideoPlayer.swift in Sources */,
Expand Down Expand Up @@ -2373,6 +2403,7 @@
4C3EA66028FF5E7700C48A62 /* node_id.c in Sources */,
4C687C212A5F7ED00092C550 /* DamusBackground.swift in Sources */,
4CA352A02A76AE80003BB08B /* Notify.swift in Sources */,
BA3BF28B2A7F156B00600232 /* CameraService+Extensions.swift in Sources */,
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */,
4C1253582A76C9060004F4B8 /* PresentSheetNotify.swift in Sources */,
4C363A962827096D006E126D /* PostBlock.swift in Sources */,
Expand Down Expand Up @@ -2417,6 +2448,7 @@
5C513FBA297F72980072348F /* CustomPicker.swift in Sources */,
4C1253622A76D00B0004F4B8 /* PostNotify.swift in Sources */,
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */,
BA3BF28F2A7F1B2D00600232 /* CameraModel.swift in Sources */,
F7908E92298B0F0700AB113A /* RelayDetailView.swift in Sources */,
4C9147002A2A891E00DDEA40 /* error.c in Sources */,
4CE879552996BAB900F758CC /* RelayPaidDetail.swift in Sources */,
Expand Down Expand Up @@ -2764,7 +2796,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
DEVELOPMENT_TEAM = XL4476DR2X;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = damus/Info.plist;
Expand All @@ -2790,7 +2822,7 @@
"$(PROJECT_DIR)",
);
MARKETING_VERSION = 1.6;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus2;
PRODUCT_BUNDLE_IDENTIFIER = com.suhail.damus2;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = YES;
Expand All @@ -2813,7 +2845,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
DEVELOPMENT_TEAM = XL4476DR2X;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = damus/Info.plist;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"pins" : [
{
"identity" : "gsplayer",
"kind" : "remoteSourceControl",
"location" : "https://github.com/wxxsw/GSPlayer",
"state" : {
"revision" : "aa6dad7943d52f5207f7fcc2ad3e4274583443b8",
"version" : "0.2.26"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher",
"state" : {
"revision" : "415b1d97fb38bda1e5a6b2dde63354720832110b",
"version" : "7.6.1"
}
},
{
"identity" : "secp256k1.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jb55/secp256k1.swift",
"state" : {
"revision" : "40b4b38b3b1c83f7088c76189a742870e0ca06a9"
}
},
{
"identity" : "swift-markdown-ui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/damus-io/swift-markdown-ui",
"state" : {
"revision" : "76bb7971da7fbf429de1c84f1244adf657242fee"
}
}
],
"version" : 2
}
122 changes: 122 additions & 0 deletions damus/Models/Camera/CameraModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// CameraModel.swift
// damus
//
// Created by Suhail Saqan on 8/5/23.
//

import Foundation
import AVFoundation
import Combine

final class CameraModel: ObservableObject {
private let service = CameraService()

@Published var showAlertError = false

@Published var isFlashOn = false

@Published var willCapturePhoto = false

@Published var isCameraButtonDisabled = false

@Published var isPhotoProcessing = false

@Published var isRecording = false

@Published var captureMode: CameraMediaType = .image

@Published public var mediaItems: [MediaItem] = []

@Published var thumbnail: Thumbnail!

var alertError: AlertError!

var session: AVCaptureSession

private var subscriptions = Set<AnyCancellable>()

init() {
self.session = service.session

service.$shouldShowAlertView.sink { [weak self] (val) in
self?.alertError = self?.service.alertError
self?.showAlertError = val
}
.store(in: &self.subscriptions)

service.$flashMode.sink { [weak self] (mode) in
self?.isFlashOn = mode == .on
}
.store(in: &self.subscriptions)

service.$willCapturePhoto.sink { [weak self] (val) in
self?.willCapturePhoto = val
}
.store(in: &self.subscriptions)

service.$isCameraButtonDisabled.sink { [weak self] (val) in
self?.isCameraButtonDisabled = val
}
.store(in: &self.subscriptions)

service.$isPhotoProcessing.sink { [weak self] (val) in
self?.isPhotoProcessing = val
}
.store(in: &self.subscriptions)

service.$isRecording.sink { [weak self] (val) in
self?.isRecording = val
}
.store(in: &self.subscriptions)

service.$captureMode.sink { [weak self] (mode) in
self?.captureMode = mode
}
.store(in: &self.subscriptions)

service.$mediaItems.sink { [weak self] (mode) in
self?.mediaItems = mode
}
.store(in: &self.subscriptions)

service.$thumbnail.sink { [weak self] (thumbnail) in
guard let pic = thumbnail else { return }
self?.thumbnail = pic
}
.store(in: &self.subscriptions)
}

func configure() {
service.checkForPermissions()
service.configure()
}

func stop() {
service.stop()
}

func capturePhoto() {
service.capturePhoto()
}

func startRecording() {
service.startRecording()
}

func stopRecording() {
service.stopRecording()
}

func flipCamera() {
service.changeCamera()
}

func zoom(with factor: CGFloat) {
service.set(zoom: factor)
}

func switchFlash() {
service.flashMode = service.flashMode == .on ? .off : .on
}
}
33 changes: 33 additions & 0 deletions damus/Models/Camera/CameraService+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// CameraService+Extensions.swift
// Campus
//
// Created by Rolando Rodriguez on 1/11/20.
// Copyright © 2020 Rolando Rodriguez. All rights reserved.
//

import Foundation
import UIKit
import AVFoundation

extension AVCaptureVideoOrientation {
init?(deviceOrientation: UIDeviceOrientation) {
switch deviceOrientation {
case .portrait: self = .portrait
case .portraitUpsideDown: self = .portraitUpsideDown
case .landscapeLeft: self = .landscapeRight
case .landscapeRight: self = .landscapeLeft
default: return nil
}
}

init?(interfaceOrientation: UIInterfaceOrientation) {
switch interfaceOrientation {
case .portrait: self = .portrait
case .portraitUpsideDown: self = .portraitUpsideDown
case .landscapeLeft: self = .landscapeLeft
case .landscapeRight: self = .landscapeRight
default: return nil
}
}
}
Loading

0 comments on commit 71a7ba1

Please sign in to comment.