Skip to content

Commit 7430516

Browse files
authored
Merge pull request #15 from sunshinejr/feature/landscape_live_session
Added landscape support for live camera session flow
2 parents e249d34 + 74bd9c1 commit 7430516

File tree

6 files changed

+47
-35
lines changed

6 files changed

+47
-35
lines changed

Changelog.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Tree Tracker
22

33
## Next
4-
- Added ability to cache images in sqlite & now we brought back trees in the list (though on hitting Refresh we don't fetch new ones to not flood the network with unnecessary requests for all trees in Airtable)
4+
- Added ability to cache images in sqlite & now we brought back trees in the list (though on hitting Refresh we don't fetch new ones to not flood the network with unnecessary requests for all trees in Airtable).
5+
- Added landscape support for live camera session flow (it needed me to update the presentation mode of image picker, unfortunately).
56

67
## 0.4.0
78
- Fix changing/showing tabbar item name for queue (the idea was to hide names for now).
8-
- Added new view for camera session flow (take a photo -> add details -> take another one...)
9-
- Added rounding precision (5) for coordinates
10-
- Upload list is now sorted by `createdDate` if possible (descending)
11-
- Sync button on All Trees view doesn't fetch trees from Airtable now + we don't show the trees for now since it takes lots of memory and network bandwith for no reason
9+
- Added new view for camera session flow (take a photo -> add details -> take another one...).
10+
- Added rounding precision (5) for coordinates.
11+
- Upload list is now sorted by `createdDate` if possible (descending).
12+
- Sync button on All Trees view doesn't fetch trees from Airtable now + we don't show the trees for now since it takes lots of memory and network bandwith for no reason.
1213

1314
## 0.3.0
1415
- When uploading, we will now disable screen lock timer and enable it back on after the upload finishes/errors out.

Tree Tracker.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
853ABD8025961EEA00144B0D /* Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853ABD7F25961EEA00144B0D /* Api.swift */; };
2121
853ABD8925961F9700144B0D /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853ABD8825961F9700144B0D /* Constants.swift */; };
2222
85763A9425E29CE300CB4ED3 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85763A9325E29CE300CB4ED3 /* Logger.swift */; };
23+
85763A9D25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85763A9C25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift */; };
2324
85792A7625B0A35A00BFDA96 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85792A7525B0A35A00BFDA96 /* UIImage.swift */; };
2425
85792A7A25B0A36B00BFDA96 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85792A7925B0A36B00BFDA96 /* URL.swift */; };
2526
85792A7D25B0A3E100BFDA96 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85792A7C25B0A3E100BFDA96 /* Database.swift */; };
@@ -112,6 +113,7 @@
112113
853ABD7F25961EEA00144B0D /* Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Api.swift; sourceTree = "<group>"; };
113114
853ABD8825961F9700144B0D /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
114115
85763A9325E29CE300CB4ED3 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
116+
85763A9C25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RotatingUIImagePickerController.swift; sourceTree = "<group>"; };
115117
85792A7525B0A35A00BFDA96 /* UIImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; };
116118
85792A7925B0A36B00BFDA96 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
117119
85792A7C25B0A3E100BFDA96 /* Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
@@ -444,6 +446,7 @@
444446
85B839D525B74E960008E167 /* KeyboardAccessoryView.swift */,
445447
85B839E325B753F10008E167 /* KeyboardLayoutGuide.swift */,
446448
85B83A2225B9C1BC0008E167 /* NavigationViewController.swift */,
449+
85763A9C25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift */,
447450
85B839F225B866590008E167 /* RoundedTappableButton.swift */,
448451
859F62E325C22D6C005E61F7 /* SelectionsKeyboardView.swift */,
449452
859F62FB25C70F29005E61F7 /* TableListViewController.swift */,
@@ -610,6 +613,7 @@
610613
85DC214025E0FC9F003F0721 /* ImageCaching.swift in Sources */,
611614
85792A8F25B1D59F00BFDA96 /* SyncProgress.swift in Sources */,
612615
85B83A0225B8735F0008E167 /* AnyImageLoader.swift in Sources */,
616+
85763A9D25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift in Sources */,
613617
859F62C325C1C44C005E61F7 /* AirtableImage.swift in Sources */,
614618
857BADAC25B1FAAA005D7D35 /* UploadListFlowViewController.swift in Sources */,
615619
859F62EF25C48FD8005E61F7 /* AlertModel.swift in Sources */,

Tree Tracker/Navigation/MainFlowViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ final class MainFlowViewController: UITabBarController {
2222
extension MainFlowViewController: LiveUploadNavigating {
2323
func triggerAskForDetailsAndStoreFlow(assets: [PHAsset], completion: @escaping (Bool) -> Void) {
2424
DispatchQueue.main.async {
25-
self.selectedViewController?.present(TreeDetailsFlowViewController(assets: assets, completion: completion), animated: true, completion: nil)
25+
let controller = (self.selectedViewController as? UINavigationController)?.visibleViewController ?? self.selectedViewController?.presentedViewController ?? self.selectedViewController
26+
controller?.present(TreeDetailsFlowViewController(assets: assets, completion: completion), animated: true, completion: nil)
2627
}
2728
}
2829
}

Tree Tracker/Screens/Live Upload/LiveUploadViewController.swift

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import Combine
66
final class LiveUploadViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, CLLocationManagerDelegate {
77
let viewModel: LiveUploadViewModel
88

9-
private var currentCameraView: UIImagePickerController?
10-
119
private lazy var actionButton: RoundedTappableButton = {
1210
let button = RoundedTappableButton()
1311
button.translatesAutoresizingMaskIntoConstraints = false
@@ -48,16 +46,9 @@ final class LiveUploadViewController: UIViewController, UIImagePickerControllerD
4846
override func viewDidAppear(_ animated: Bool) {
4947
super.viewDidAppear(animated)
5048

51-
currentCameraView?.startVideoCapture()
5249
viewModel.onAppear()
5350
}
5451

55-
override func viewWillDisappear(_ animated: Bool) {
56-
super.viewDidDisappear(animated)
57-
58-
currentCameraView?.stopVideoCapture()
59-
}
60-
6152
private func setup(viewModel: LiveUploadViewModel) {
6253
viewModel.$state
6354
.sink { [weak self] state in
@@ -76,31 +67,35 @@ final class LiveUploadViewController: UIViewController, UIImagePickerControllerD
7667
}
7768
.store(in: &oservables)
7869
}
79-
80-
private func removeCurrentCameraView() {
81-
currentCameraView?.view.removeFromSuperview()
82-
currentCameraView = nil
70+
71+
private func removeCurrentCameraViewIfNeeded(completion: @escaping () -> Void) {
72+
if presentedViewController is UIImagePickerController {
73+
dismiss(animated: true, completion: completion)
74+
} else {
75+
completion()
76+
}
8377
}
8478

8579
private func presentPhotoSession(cancel: @escaping () -> Void, completion: @escaping (Result<UIImage, Error>) -> Void) {
86-
removeCurrentCameraView()
87-
photoSessionCancel = cancel
88-
photoSessionCompletion = completion
89-
actionButton.isHidden = true
90-
91-
let picker = UIImagePickerController()
92-
picker.mediaTypes = ["public.image"]
93-
picker.sourceType = .camera
94-
picker.delegate = self
95-
add(picker, to: view, insets: .some(top: 0.0, bottom: 16.0))
96-
97-
self.currentCameraView = picker
80+
removeCurrentCameraViewIfNeeded { [weak self] in
81+
self?.photoSessionCancel = cancel
82+
self?.photoSessionCompletion = completion
83+
self?.actionButton.isHidden = true
84+
85+
let picker = RotatingUIImagePickerController()
86+
picker.modalPresentationStyle = .overCurrentContext
87+
picker.mediaTypes = ["public.image"]
88+
picker.sourceType = .camera
89+
picker.delegate = self
90+
self?.present(picker, animated: true, completion: nil)
91+
}
9892
}
9993

10094
private func present(actionButton model: ButtonModel) {
101-
removeCurrentCameraView()
102-
actionButton.set(model: model)
103-
actionButton.isHidden = false
95+
removeCurrentCameraViewIfNeeded { [weak self] in
96+
self?.actionButton.set(model: model)
97+
self?.actionButton.isHidden = false
98+
}
10499
}
105100

106101
private func present(alert: AlertModel) {

Tree Tracker/Screens/Trees/TreesViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ final class TreesViewModel: TableListViewModel {
143143
info: info,
144144
detail: tree.supervisor,
145145
tapAction: Action(id: "tree_action_\(tree.id)") {
146-
print("tap action")
146+
self?.logger.log(.treeList, "tap action")
147147
})
148148
})]
149149
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import UIKit
2+
3+
final class RotatingUIImagePickerController: UIImagePickerController {
4+
override var shouldAutorotate: Bool {
5+
return true
6+
}
7+
8+
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
9+
return .all
10+
}
11+
}

0 commit comments

Comments
 (0)