Manos Chorianopoulos

Added MapsViewController

Showing 19 changed files with 419 additions and 1 deletions
......@@ -24,6 +24,10 @@
1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */; };
1EBE97212865EE460080EFF7 /* MFYInboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */; };
1EBF5F072840E13F00B8B17F /* SwiftEventBus in Frameworks */ = {isa = PBXBuildFile; productRef = 1EBF5F062840E13F00B8B17F /* SwiftEventBus */; };
1ECA079128D9E3BA00D2BDE0 /* CSMButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECA079028D9E3BA00D2BDE0 /* CSMButton.swift */; };
1ECA079428D9E53F00D2BDE0 /* MapsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECA079228D9E53F00D2BDE0 /* MapsViewController.swift */; };
1ECA079528D9E53F00D2BDE0 /* MapsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1ECA079328D9E53F00D2BDE0 /* MapsViewController.xib */; };
1ECA079728D9E66200D2BDE0 /* MerchantAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECA079628D9E66200D2BDE0 /* MerchantAnnotation.swift */; };
7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; };
A02F34052882B6E60086465F /* TelcoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A02F34042882B6E60086465F /* TelcoViewController.swift */; };
A04D31DE288FF670000E43B5 /* HistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A04D31DD288FF670000E43B5 /* HistoryViewController.swift */; };
......@@ -179,6 +183,10 @@
1EB5F4C728536FD60016F36E /* StepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewController.swift; sourceTree = "<group>"; };
1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoyaltyAnalysisViewController.swift; sourceTree = "<group>"; };
1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFYInboxTableViewCell.swift; sourceTree = "<group>"; };
1ECA079028D9E3BA00D2BDE0 /* CSMButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSMButton.swift; sourceTree = "<group>"; };
1ECA079228D9E53F00D2BDE0 /* MapsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapsViewController.swift; sourceTree = "<group>"; };
1ECA079328D9E53F00D2BDE0 /* MapsViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapsViewController.xib; sourceTree = "<group>"; };
1ECA079628D9E66200D2BDE0 /* MerchantAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MerchantAnnotation.swift; sourceTree = "<group>"; };
A02F34042882B6E60086465F /* TelcoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TelcoViewController.swift; sourceTree = "<group>"; };
A04D31DD288FF670000E43B5 /* HistoryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryViewController.swift; sourceTree = "<group>"; };
A079366D2885D07700064122 /* AnalysisChildViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisChildViewController.swift; sourceTree = "<group>"; };
......@@ -430,6 +438,7 @@
E6A77850282933340045BBA8 /* SwiftWarplyFramework */ = {
isa = PBXGroup;
children = (
1ECA079028D9E3BA00D2BDE0 /* CSMButton.swift */,
1E108A9728A3FA9B0008B8E7 /* Info.plist */,
1E108A8B28A3F8FF0008B8E7 /* Resources */,
A02F34042882B6E60086465F /* TelcoViewController.swift */,
......@@ -465,6 +474,9 @@
E6A77851282933340045BBA8 /* SwiftWarplyFramework.h */,
E6A77852282933340045BBA8 /* SwiftWarplyFramework.docc */,
E6A77A37282BC3530045BBA8 /* Media.xcassets */,
1ECA079228D9E53F00D2BDE0 /* MapsViewController.swift */,
1ECA079628D9E66200D2BDE0 /* MerchantAnnotation.swift */,
1ECA079328D9E53F00D2BDE0 /* MapsViewController.xib */,
);
path = SwiftWarplyFramework;
sourceTree = "<group>";
......@@ -814,6 +826,7 @@
E6A778E5282933E60045BBA8 /* Main.storyboard in Resources */,
1E108A9628A3F9280008B8E7 /* pf_square_sans_pro_bold.ttf in Resources */,
1E108A9228A3F9280008B8E7 /* pf_square_sans_pro_regular.ttf in Resources */,
1ECA079528D9E53F00D2BDE0 /* MapsViewController.xib in Resources */,
E6A778EA282933E60045BBA8 /* WLNativeVideoTableViewCell.xib in Resources */,
1E108A9528A3F9280008B8E7 /* pf_square_sans_pro_bold_italic.ttf in Resources */,
E6A7790A282933E60045BBA8 /* warp_white_close_button.png in Resources */,
......@@ -901,8 +914,10 @@
E6A77917282933E60045BBA8 /* UIViewController+WLAdditions.m in Sources */,
1EA2BB792865BFE8003F2AB0 /* InboxTableViewCell.swift in Sources */,
E6A77943282933E70045BBA8 /* AFNetworkReachabilityManager.m in Sources */,
1ECA079428D9E53F00D2BDE0 /* MapsViewController.swift in Sources */,
A07936702885D95600064122 /* AnalysisItemViewCell.swift in Sources */,
E6A77956282933E70045BBA8 /* GiftsViewController.swift in Sources */,
1ECA079728D9E66200D2BDE0 /* MerchantAnnotation.swift in Sources */,
E6A778F1282933E60045BBA8 /* WLNativeAdTableViewCell.m in Sources */,
E6A77853282933340045BBA8 /* SwiftWarplyFramework.docc in Sources */,
E6A77938282933E70045BBA8 /* AFImageDownloader.m in Sources */,
......@@ -924,6 +939,7 @@
1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */,
E6A7794A282933E70045BBA8 /* FMDatabaseAdditions.m in Sources */,
E6A77903282933E60045BBA8 /* WLAPSItem.m in Sources */,
1ECA079128D9E3BA00D2BDE0 /* CSMButton.swift in Sources */,
E6A7790B282933E60045BBA8 /* WLPushManager.m in Sources */,
A079366E2885D07700064122 /* AnalysisChildViewController.swift in Sources */,
E6A77950282933E70045BBA8 /* FMResultSet.m in Sources */,
......
//
// CSMButton.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 20/9/22.
//
import UIKit
// @IBDesignable
@objc public class CSMButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
}
override init(frame: CGRect = .zero) {
super.init(frame: frame)
configure()
}
public override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
configure()
}
}
private extension CSMButton {
func configure() {
setImage(UIImage(named: "directions"), for: .normal)
titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
setTitleColor(.white, for: .normal)
backgroundColor = UIColor(rgb: 0x79BF14)
layer.cornerRadius = 12.0
imageEdgeInsets = UIEdgeInsets(top:0.0, left:0.0, bottom:0.0, right:5.0);
titleEdgeInsets = UIEdgeInsets(top:0.0, left:5.0, bottom:0.0, right:0.0);
}
}
......@@ -252,6 +252,8 @@ import AVFoundation
}
@IBAction func mapButtonAction(_ sender: Any) {
// TODO: open MapVC
let vc = SwiftWarplyFramework.MapsViewController(nibName: "MapsViewController", bundle: Bundle(for: MyEmptyClass.self))
vc.couponSet = coupon?.couponset_data
self.navigationController?.pushViewController(vc, animated: true)
}
}
......
//
// MapsViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 20/9/22.
//
import UIKit
import MapKit
@objc public class MapsViewController: UIViewController, MKMapViewDelegate {
// ui
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet private var mapView: MKMapView!
@IBOutlet weak var closeButton: UIButton!
@IBOutlet private var titleView: UILabel!
@IBOutlet private var nameImageView: UIImageView!
@IBOutlet private var nameView: UILabel!
@IBOutlet private var hoursView: UILabel!
@IBOutlet private var phoneView: UILabel!
@IBOutlet private var addressView: UILabel!
@IBOutlet private var directionsButton: CSMButton!
@IBOutlet private var infoTopConstraint: NSLayoutConstraint!
// public
public var couponSet: swiftApi.CouponSetItemModel?
var merchantsArray:Array<swiftApi.MerchantModel> = []
var selectedMerchant: swiftApi.MerchantModel?
var annotationGroup = [MKPointAnnotation]()
//
var loading: Bool = false
let initialLocation = CLLocation(latitude: 37.9641262, longitude: 23.7468592) // greece
//
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
self.infoTopConstraint.constant = 0
setBackButton()
setNavigationTitle("Καταστήματα")
backgroundImage.image = UIImage(named: "coupons_scrollview_white")
mapView.delegate = self
mapView.centerToLocation(initialLocation, regionRadius: 1000000)
mapView.clipsToBounds = true
mapView.layer.cornerRadius = 30
mapView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
closeButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
titleView.font = UIFont(name: "PFSquareSansPro-Bold", size: 19)
titleView.textColor = UIColor(rgb: 0x757575)
nameView.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
nameView.textColor = UIColor(rgb: 0x415564)
hoursView.font = UIFont(name: "PFSquareSansPro-Regular", size: 18)
hoursView.textColor = UIColor(rgb: 0xAEAEAE)
hoursView.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
hoursView.textColor = UIColor(rgb: 0x415564)
addressView.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
addressView.textColor = UIColor(rgb: 0x415564)
//directionsButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 16)
directionsButton.setTitle("Οδηγίες", for: .normal)
directionsButton.setImage(UIImage(named: "ic_directions"), for: .normal)
// directionsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
// directionsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
// directionsButton.sizeToFit()
//directionsButton.setTitleColor(.white, for: .normal)
//directionsButton.backgroundColor = UIColor(red: 0.47, green: 0.75, blue: 0.08, alpha: 1.00)
//directionsButton.layer.cornerRadius = 12.0
load()
}
// mvp
@objc func load() {
if (loading) {
return;
}
showLoading()
if (couponSet != nil) {
if let merchantUuid: String = couponSet?.merchant_uuid {
swiftApi().getMultilingualMerchantsAsync([], false, 0.0, [], "", 0, [merchantUuid], getMerchantsCallback)
showContent()
}
}
}
func getMerchantsCallback (_ merchantsData: Array<swiftApi.MerchantModel>?) -> Void {
if (merchantsData != nil) {
DispatchQueue.main.async {
self.merchantsArray = merchantsData ?? []
self.loadMapPins()
}
return
}
}
private func showLoading() {
loading = true
}
private func showError() {
}
private func showContent() {
loading = false
}
// private
@IBAction func closeButtonAction(_ sender: Any) {
print("closeButton Pressed!!!")
hidePinDetailsView()
let selectedAnnotations = mapView.selectedAnnotations
for annotation in selectedAnnotations {
mapView.deselectAnnotation(annotation, animated: false)
}
}
@IBAction func directionsButtomAction(_ sender: Any) {
guard let lon = selectedMerchant?._longitude, let lat = selectedMerchant?._latitude else {
return
}
// guard your URL instances
// guard let googleMapsUrl = URL(string: String(format: "https://www.google.com/maps/@%.6f,%.6f,6z", lat, lon)),
// let appleMapsUrl = URL(string: String(format: "http://maps.apple.com/?ll=%.6f,%.6f", lat, lon)) else {
// print("Error creating URLs")
// return
// }
guard let googleMapsUrl = URL(string: "https://www.google.co.in/maps/dir/?saddr=&daddr=\(lat),\(lon)&directionsmode=driving"),
let appleMapsUrl = URL(string: "http://maps.apple.com/?daddr=\(lat),\(lon)") else {
print("Error creating URLs")
return
}
// check if link can be opened with google maps.
guard UIApplication.shared.canOpenURL(googleMapsUrl) else {
UIApplication.shared.open(appleMapsUrl, options: [:], completionHandler: nil)
return
}
UIApplication.shared.open(googleMapsUrl, options: [:], completionHandler: nil)
}
private func loadMapPins() {
for item in merchantsArray {
let pin = MerchantAnnotation(item)
mapView.addAnnotation(pin)
// self.annotationGroup.append(pin)
// self.mapView.addAnnotations(self.annotationGroup)
// self.mapView.showAnnotations(self.annotationGroup, animated: true)
// let annotation = MKPointAnnotation()
// annotation.coordinate.longitude = item._longitude
// annotation.coordinate.latitude = item._latitude
// annotation.title = item._admin_name //This is the line to remove the optional annotation.title? from.
// annotation.subtitle = item._admin_name
// self.annotationGroup.append(annotation)
// self.mapView.addAnnotations(self.annotationGroup)
// self.mapView.showAnnotations(self.annotationGroup, animated: true)
// let annotation = MKPointAnnotation()
// let centerCoordinate = CLLocationCoordinate2D(latitude: item._latitude, longitude: item._longitude)
// annotation.coordinate = centerCoordinate
// annotation.title = "Pass Title here"
// mapView.addAnnotation(annotation)
}
// mapView.showAnnotations(mapView.annotations, animated: true)
}
private func loadPinDetailsView(_ annotation: MerchantAnnotation) {
self.selectedMerchant = annotation.model
self.titleView.text = self.selectedMerchant?._admin_name
self.nameImageView.load(link: self.selectedMerchant?._img_preview ?? "", placeholder: UIImage(), cache: URLCache())
self.nameView.text = self.selectedMerchant?._name
// TODO: Make dynamic
self.hoursView.text = ""
self.phoneView.text = self.selectedMerchant?._telephone
self.addressView.text = self.selectedMerchant?._address
}
private func showPinDetailsView() {
self.infoTopConstraint.constant = -320
UIView.animate(withDuration: 1.0) {
self.view.layoutIfNeeded()
}
}
private func hidePinDetailsView() {
self.selectedMerchant = nil
self.infoTopConstraint.constant = 0
UIView.animate(withDuration: 1.0) {
self.view.layoutIfNeeded()
}
}
// map view delegate
// public func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
//
//// guard !(annotation is MKUserLocation) else {
//// return nil
//// }
//
// var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "warply_custom")
// if (annotationView == nil) {
// print("=== annotationView == nil ===")
//
// annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "warply_custom")
// annotationView?.canShowCallout = false
// } else {
// print("=== annotationView != nil ===")
//
// annotationView?.annotation = annotation
// }
//
// // TODO: add custom pin image?
// //annotationView?.image = UIImage(named: "custom")
//
// print("=== returned annotation ===")
// print(annotation)
//
// return annotationView
// }
public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
let merchant = view.annotation as? MerchantAnnotation
loadPinDetailsView(merchant!)
showPinDetailsView()
}
public func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
hidePinDetailsView()
}
}
private extension MKMapView {
func centerToLocation(_ location: CLLocation, regionRadius: CLLocationDistance = 1000) {
let coordinateRegion = MKCoordinateRegion(
center: location.coordinate,
latitudinalMeters: regionRadius,
longitudinalMeters: regionRadius)
setRegion(coordinateRegion, animated: true)
}
}
This diff is collapsed. Click to expand it.
{
"images" : [
{
"filename" : "ic_pin_location.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_pin_location-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_pin_location-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_pin_compass.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_pin_compass-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_pin_compass-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_pin_tel.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_pin_tel-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_pin_tel-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
//
// MerchantAnnotation.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 20/9/22.
//
import Foundation
import MapKit
@objc public class MerchantAnnotation: NSObject, MKAnnotation {
let model: swiftApi.MerchantModel
public let coordinate: CLLocationCoordinate2D
init(_ model: swiftApi.MerchantModel) {
self.model = model
self.coordinate = CLLocationCoordinate2D(latitude: model._latitude, longitude: model._longitude)
super.init()
}
}