Skip to content

Commit

Permalink
Merge pull request #15 from sunshinejr/feature/landscape_live_session
Browse files Browse the repository at this point in the history
Added landscape support for live camera session flow
  • Loading branch information
sunshinejr authored Feb 21, 2021
2 parents e249d34 + 74bd9c1 commit 7430516
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
11 changes: 6 additions & 5 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Tree Tracker

## Next
- 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)
- 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).
- Added landscape support for live camera session flow (it needed me to update the presentation mode of image picker, unfortunately).

## 0.4.0
- Fix changing/showing tabbar item name for queue (the idea was to hide names for now).
- Added new view for camera session flow (take a photo -> add details -> take another one...)
- Added rounding precision (5) for coordinates
- Upload list is now sorted by `createdDate` if possible (descending)
- 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
- Added new view for camera session flow (take a photo -> add details -> take another one...).
- Added rounding precision (5) for coordinates.
- Upload list is now sorted by `createdDate` if possible (descending).
- 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.

## 0.3.0
- When uploading, we will now disable screen lock timer and enable it back on after the upload finishes/errors out.
Expand Down
4 changes: 4 additions & 0 deletions Tree Tracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
853ABD8025961EEA00144B0D /* Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853ABD7F25961EEA00144B0D /* Api.swift */; };
853ABD8925961F9700144B0D /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 853ABD8825961F9700144B0D /* Constants.swift */; };
85763A9425E29CE300CB4ED3 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85763A9325E29CE300CB4ED3 /* Logger.swift */; };
85763A9D25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85763A9C25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift */; };
85792A7625B0A35A00BFDA96 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85792A7525B0A35A00BFDA96 /* UIImage.swift */; };
85792A7A25B0A36B00BFDA96 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85792A7925B0A36B00BFDA96 /* URL.swift */; };
85792A7D25B0A3E100BFDA96 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85792A7C25B0A3E100BFDA96 /* Database.swift */; };
Expand Down Expand Up @@ -112,6 +113,7 @@
853ABD7F25961EEA00144B0D /* Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Api.swift; sourceTree = "<group>"; };
853ABD8825961F9700144B0D /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
85763A9325E29CE300CB4ED3 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
85763A9C25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RotatingUIImagePickerController.swift; sourceTree = "<group>"; };
85792A7525B0A35A00BFDA96 /* UIImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; };
85792A7925B0A36B00BFDA96 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
85792A7C25B0A3E100BFDA96 /* Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -444,6 +446,7 @@
85B839D525B74E960008E167 /* KeyboardAccessoryView.swift */,
85B839E325B753F10008E167 /* KeyboardLayoutGuide.swift */,
85B83A2225B9C1BC0008E167 /* NavigationViewController.swift */,
85763A9C25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift */,
85B839F225B866590008E167 /* RoundedTappableButton.swift */,
859F62E325C22D6C005E61F7 /* SelectionsKeyboardView.swift */,
859F62FB25C70F29005E61F7 /* TableListViewController.swift */,
Expand Down Expand Up @@ -610,6 +613,7 @@
85DC214025E0FC9F003F0721 /* ImageCaching.swift in Sources */,
85792A8F25B1D59F00BFDA96 /* SyncProgress.swift in Sources */,
85B83A0225B8735F0008E167 /* AnyImageLoader.swift in Sources */,
85763A9D25E2B0AB00CB4ED3 /* RotatingUIImagePickerController.swift in Sources */,
859F62C325C1C44C005E61F7 /* AirtableImage.swift in Sources */,
857BADAC25B1FAAA005D7D35 /* UploadListFlowViewController.swift in Sources */,
859F62EF25C48FD8005E61F7 /* AlertModel.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Tree Tracker/Navigation/MainFlowViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ final class MainFlowViewController: UITabBarController {
extension MainFlowViewController: LiveUploadNavigating {
func triggerAskForDetailsAndStoreFlow(assets: [PHAsset], completion: @escaping (Bool) -> Void) {
DispatchQueue.main.async {
self.selectedViewController?.present(TreeDetailsFlowViewController(assets: assets, completion: completion), animated: true, completion: nil)
let controller = (self.selectedViewController as? UINavigationController)?.visibleViewController ?? self.selectedViewController?.presentedViewController ?? self.selectedViewController
controller?.present(TreeDetailsFlowViewController(assets: assets, completion: completion), animated: true, completion: nil)
}
}
}
51 changes: 23 additions & 28 deletions Tree Tracker/Screens/Live Upload/LiveUploadViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import Combine
final class LiveUploadViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, CLLocationManagerDelegate {
let viewModel: LiveUploadViewModel

private var currentCameraView: UIImagePickerController?

private lazy var actionButton: RoundedTappableButton = {
let button = RoundedTappableButton()
button.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -48,16 +46,9 @@ final class LiveUploadViewController: UIViewController, UIImagePickerControllerD
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

currentCameraView?.startVideoCapture()
viewModel.onAppear()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

currentCameraView?.stopVideoCapture()
}

private func setup(viewModel: LiveUploadViewModel) {
viewModel.$state
.sink { [weak self] state in
Expand All @@ -76,31 +67,35 @@ final class LiveUploadViewController: UIViewController, UIImagePickerControllerD
}
.store(in: &oservables)
}

private func removeCurrentCameraView() {
currentCameraView?.view.removeFromSuperview()
currentCameraView = nil

private func removeCurrentCameraViewIfNeeded(completion: @escaping () -> Void) {
if presentedViewController is UIImagePickerController {
dismiss(animated: true, completion: completion)
} else {
completion()
}
}

private func presentPhotoSession(cancel: @escaping () -> Void, completion: @escaping (Result<UIImage, Error>) -> Void) {
removeCurrentCameraView()
photoSessionCancel = cancel
photoSessionCompletion = completion
actionButton.isHidden = true

let picker = UIImagePickerController()
picker.mediaTypes = ["public.image"]
picker.sourceType = .camera
picker.delegate = self
add(picker, to: view, insets: .some(top: 0.0, bottom: 16.0))

self.currentCameraView = picker
removeCurrentCameraViewIfNeeded { [weak self] in
self?.photoSessionCancel = cancel
self?.photoSessionCompletion = completion
self?.actionButton.isHidden = true

let picker = RotatingUIImagePickerController()
picker.modalPresentationStyle = .overCurrentContext
picker.mediaTypes = ["public.image"]
picker.sourceType = .camera
picker.delegate = self
self?.present(picker, animated: true, completion: nil)
}
}

private func present(actionButton model: ButtonModel) {
removeCurrentCameraView()
actionButton.set(model: model)
actionButton.isHidden = false
removeCurrentCameraViewIfNeeded { [weak self] in
self?.actionButton.set(model: model)
self?.actionButton.isHidden = false
}
}

private func present(alert: AlertModel) {
Expand Down
2 changes: 1 addition & 1 deletion Tree Tracker/Screens/Trees/TreesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ final class TreesViewModel: TableListViewModel {
info: info,
detail: tree.supervisor,
tapAction: Action(id: "tree_action_\(tree.id)") {
print("tap action")
self?.logger.log(.treeList, "tap action")
})
})]
}
Expand Down
11 changes: 11 additions & 0 deletions Tree Tracker/UI/RotatingUIImagePickerController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import UIKit

final class RotatingUIImagePickerController: UIImagePickerController {
override var shouldAutorotate: Bool {
return true
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all
}
}

0 comments on commit 7430516

Please sign in to comment.