Skip to content

Commit

Permalink
#25: Refactor details view. Show details view
Browse files Browse the repository at this point in the history
  • Loading branch information
kzyryanov committed Apr 13, 2017
1 parent 7efbd74 commit 2974f0c
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 238 deletions.
4 changes: 4 additions & 0 deletions MapsAOPA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
B5DC47E01E5DEFAD00037888 /* DetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DC47DF1E5DEFAD00037888 /* DetailsViewModel.swift */; };
B5DC775E1CC7E2B700226660 /* MapViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DC775D1CC7E2B700226660 /* MapViewModel.swift */; };
B5DC77611CC7EF3200226660 /* MultipleStatesBarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DC77601CC7EF3200226660 /* MultipleStatesBarButtonItem.swift */; };
B5E5C1101E9F963100F0EE00 /* PointDetailsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E5C10F1E9F963100F0EE00 /* PointDetailsView.xib */; };
B5E6E51F1CC9145D00B175FD /* PointAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E6E51E1CC9145D00B175FD /* PointAnnotation.swift */; };
B5FB20A81CC1DA3A007DA15E /* aopa-points-export.xml in Resources */ = {isa = PBXBuildFile; fileRef = B5FB20A71CC1DA3A007DA15E /* aopa-points-export.xml */; };
B5FBF58F1E5309E500137491 /* ArrayXMLParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FBF58E1E5309E500137491 /* ArrayXMLParser.swift */; };
Expand Down Expand Up @@ -139,6 +140,7 @@
B5DC47DF1E5DEFAD00037888 /* DetailsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailsViewModel.swift; sourceTree = "<group>"; };
B5DC775D1CC7E2B700226660 /* MapViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapViewModel.swift; sourceTree = "<group>"; };
B5DC77601CC7EF3200226660 /* MultipleStatesBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipleStatesBarButtonItem.swift; sourceTree = "<group>"; };
B5E5C10F1E9F963100F0EE00 /* PointDetailsView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PointDetailsView.xib; sourceTree = "<group>"; };
B5E6E51E1CC9145D00B175FD /* PointAnnotation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PointAnnotation.swift; sourceTree = "<group>"; };
B5FB20A71CC1DA3A007DA15E /* aopa-points-export.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "aopa-points-export.xml"; sourceTree = "<group>"; };
B5FBF58E1E5309E500137491 /* ArrayXMLParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArrayXMLParser.swift; path = MapsAOPA/Classes/ArrayXMLParser.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -198,6 +200,7 @@
children = (
B53826BD1D009EEE00828A95 /* RunwaysView.swift */,
B53826BB1D009BB100828A95 /* PointDetailsView.swift */,
B5E5C10F1E9F963100F0EE00 /* PointDetailsView.xib */,
B5CA69AB1E77044500654684 /* PointDetailsViewController.swift */,
B555BD911E71C15600A48304 /* DetailsCell.swift */,
B55011771E76DCA800ABB184 /* DetailsItemView.swift */,
Expand Down Expand Up @@ -475,6 +478,7 @@
B5D1C6BA1CC00DB7001E3294 /* Assets.xcassets in Resources */,
B550117A1E76DCB600ABB184 /* DetailsItemView.xib in Resources */,
B5447D3F1CC12ECA0041B579 /* Localizable.strings in Resources */,
B5E5C1101E9F963100F0EE00 /* PointDetailsView.xib in Resources */,
1B8B20581E6F5AEA0050F381 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
20 changes: 0 additions & 20 deletions MapsAOPA/Classes/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ class MainViewController: UIViewController {

fileprivate lazy var viewModel : MapViewModel = MapViewModel()
fileprivate lazy var loadingViewModel : LoadingViewModel = LoadingViewModel()

var statusBarStyle: UIStatusBarStyle = .default {
didSet {
UIView.animate(withDuration: 0.25) {
self.setNeedsStatusBarAppearanceUpdate()
}
}
}

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .fade
}

override public var prefersStatusBarHidden: Bool {
return false
}

override var preferredStatusBarStyle: UIStatusBarStyle {
return self.statusBarStyle
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
88 changes: 46 additions & 42 deletions MapsAOPA/Classes/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MapViewController: UIViewController, MKMapViewDelegate, UIPopoverPresentat
var loadingViewModel : LoadingViewModel!
var viewModel: MapViewModel!

fileprivate var pointDetailsViewController : PointDetailsViewController?
fileprivate var pointDetails = [String:PointDetailsView]()

fileprivate static let zoomPercent: CLLocationDegrees = 0.5

Expand All @@ -37,15 +37,6 @@ class MapViewController: UIViewController, MKMapViewDelegate, UIPopoverPresentat

fileprivate var keyboardObserver : KeyboardObserver?
fileprivate var searchTimer : Timer?

override public var preferredStatusBarStyle: UIStatusBarStyle {
get {
if self.mapView?.mapType != MKMapType.standard {
return .lightContent
}
return .default
}
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -92,22 +83,22 @@ class MapViewController: UIViewController, MKMapViewDelegate, UIPopoverPresentat
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destinationViewController = segue.destination as? DetailsTableViewController {
switch segue.identifier ?? "" {
case Segue.Contacts.rawValue:
destinationViewController.viewModel = DetailsViewModel(contacts: self.pointDetailsViewController?.viewModel?.contacts ?? [])
case Segue.Frequencies.rawValue:
destinationViewController.viewModel = DetailsViewModel(frequencies: self.pointDetailsViewController?.viewModel?.frequencies ?? [])
default: break
}
destinationViewController.popoverPresentationController?.delegate = self
destinationViewController.title = self.pointDetailsViewController?.viewModel?.title
let height : CGFloat = 300.0
destinationViewController.preferredContentSize = CGSize(width: self.view.width, height: height)
}
if segue.identifier == Segue.PointDetails.rawValue {
self.pointDetailsViewController = segue.destination as? PointDetailsViewController
}
// if let destinationViewController = segue.destination as? DetailsTableViewController {
// switch segue.identifier ?? "" {
// case Segue.Contacts.rawValue:
// destinationViewController.viewModel = DetailsViewModel(contacts: self.pointDetailsViewController?.viewModel?.contacts ?? [])
// case Segue.Frequencies.rawValue:
// destinationViewController.viewModel = DetailsViewModel(frequencies: self.pointDetailsViewController?.viewModel?.frequencies ?? [])
// default: break
// }
// destinationViewController.popoverPresentationController?.delegate = self
// destinationViewController.title = self.pointDetailsViewController?.viewModel?.title
// let height : CGFloat = 300.0
// destinationViewController.preferredContentSize = CGSize(width: self.view.width, height: height)
// }
// if segue.identifier == Segue.PointDetails.rawValue {
// self.pointDetailsViewController = segue.destination as? PointDetailsViewController
// }
}

// MARK: - Private
Expand Down Expand Up @@ -137,26 +128,39 @@ class MapViewController: UIViewController, MKMapViewDelegate, UIPopoverPresentat

fileprivate func select(annotationView view: MKAnnotationView) {
if let pointViewModel = (view.annotation as? PointAnnotation)?.pointViewModel {
// self.viewModel.selectedPoint.value = pointViewModel
/*
if let pointDetails = self.viewModel.pointDetailsViewModel(from: pointViewModel) {
//self.detailsViewContainer.userIn
self.mapView.add(RunwaysOverlay(pointDetailsViewModel: pointDetails))
let pointDetailsViewController = self.storyboard?.instantiateViewController(withIdentifier: "PointDetailsViewController") as? PointDetailsViewController
self.pointDetailsViewControllers[view] = pointDetailsViewController
pointDetailsViewController?.tableView.isScrollEnabled = false
if let detailsViewController = pointDetailsViewController, let detailsView = detailsViewController.view {
detailsViewController.viewModel = pointDetails
self.addChildViewController(detailsViewController)
self.detailsViewContainer.addSubview(detailsView)
detailsViewController.didMove(toParentViewController: self)
}
}*/
let index = pointViewModel.index
if self.pointDetails[index] != nil {
return
}
if let detailsViewModel = self.viewModel.pointDetailsViewModel(from: pointViewModel),
let detailsView = PointDetailsView.view(model: detailsViewModel) {
detailsView.translatesAutoresizingMaskIntoConstraints = false
self.pointDetails[index] = detailsView
self.view.addSubview(detailsView)
self.view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .leading, relatedBy: .equal, toItem: detailsView, attribute: .leading, multiplier: 1.0, constant: 0.0))
self.view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .trailing, relatedBy: .equal, toItem: detailsView, attribute: .trailing, multiplier: 1.0, constant: 0.0))
self.view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .bottom, relatedBy: .equal, toItem: detailsView, attribute: .bottom, multiplier: 1.0, constant: 0.0))
self.view.setNeedsLayout()
detailsView.y = self.view.height
UIView.animate(withDuration: 0.25, animations: {
self.view.setNeedsLayout()
})
}
}
}

fileprivate func deselect(annotationView view: MKAnnotationView) {
self.viewModel.selectedPoint.value = nil
if let pointViewModel = (view.annotation as? PointAnnotation)?.pointViewModel {
let index = pointViewModel.index
if let view = self.pointDetails[index] {
UIView.animate(withDuration: 0.25, animations: {
view.alpha = 0.0
}, completion: { _ in
view.removeFromSuperview()
})
self.pointDetails[index] = nil
}
}
/*
if let pointDetailsViewController = self.pointDetailsViewControllers[view] {
pointDetailsViewController.view.alpha = 1.0
Expand Down
8 changes: 4 additions & 4 deletions MapsAOPA/Classes/PointDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit
import UCCTransliteration
import ReactiveSwift

@IBDesignable
class PointDetailsView: UIView
{
@IBOutlet weak var titleLabel : UILabel?
Expand All @@ -26,9 +25,10 @@ class PointDetailsView: UIView

private let transliteration = UCCTransliteration()

override func awakeFromNib() {
super.awakeFromNib()

static func view(model: PointDetailsViewModel) -> PointDetailsView? {
let view = Bundle.main.loadNibNamed("PointDetailsView", owner: nil, options: nil)?.first as? PointDetailsView
view?.pointDetailsViewModel = model
return view
}

var pointDetailsViewModel : PointDetailsViewModel? {
Expand Down
Loading

0 comments on commit 2974f0c

Please sign in to comment.