Skip to content

Commit

Permalink
Should be working
Browse files Browse the repository at this point in the history
  • Loading branch information
below committed Jul 29, 2022
1 parent 8866d05 commit b0fac15
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 5 deletions.
4 changes: 4 additions & 0 deletions GeofenceTester.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CB655F7E2856A43B00EBCABA /* RegionsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */; };
CBE711EF2868EE36008F51C4 /* RegionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711EE2868EE36008F51C4 /* RegionViewController.swift */; };
CBE711F1286915A8008F51C4 /* EventRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711F0286915A8008F51C4 /* EventRecord.swift */; };
CBE711F3286920FD008F51C4 /* EventsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -32,6 +33,7 @@
CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionsListViewController.swift; sourceTree = "<group>"; };
CBE711EE2868EE36008F51C4 /* RegionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionViewController.swift; sourceTree = "<group>"; };
CBE711F0286915A8008F51C4 /* EventRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventRecord.swift; sourceTree = "<group>"; };
CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsTableViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -69,6 +71,7 @@
CB655F6928534E2600EBCABA /* ViewController.swift */,
CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */,
CBE711EE2868EE36008F51C4 /* RegionViewController.swift */,
CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */,
CBE711F0286915A8008F51C4 /* EventRecord.swift */,
CB268B9F285A19DC00B16C3A /* PersistantStorage.swift */,
CB655F6B28534E2600EBCABA /* Main.storyboard */,
Expand Down Expand Up @@ -156,6 +159,7 @@
CBE711EF2868EE36008F51C4 /* RegionViewController.swift in Sources */,
CB655F6828534E2600EBCABA /* SceneDelegate.swift in Sources */,
CB655F7E2856A43B00EBCABA /* RegionsListViewController.swift in Sources */,
CBE711F3286920FD008F51C4 /* EventsTableViewController.swift in Sources */,
CB268BA0285A19DC00B16C3A /* PersistantStorage.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
41 changes: 40 additions & 1 deletion GeofenceTester/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@
</view>
<navigationItem key="navigationItem" id="1LR-FO-FdF">
<rightBarButtonItems>
<barButtonItem systemItem="organize" id="O8y-4g-daL"/>
<barButtonItem systemItem="organize" id="O8y-4g-daL">
<connections>
<segue destination="qM3-Fa-wHS" kind="show" id="wyd-fL-lg7"/>
</connections>
</barButtonItem>
<barButtonItem systemItem="add" id="BJ6-F4-XfY">
<connections>
<action selector="addRegion" destination="Mm7-Ts-hYc" id="1H1-ve-oEg"/>
Expand All @@ -166,6 +170,41 @@
</objects>
<point key="canvasLocation" x="-997" y="878"/>
</scene>
<!--Events Table View Controller-->
<scene sceneID="OR8-K7-icH">
<objects>
<tableViewController id="qM3-Fa-wHS" customClass="EventsTableViewController" customModule="GeofenceTester" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="VsJ-ND-XCw">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="Lrp-57-Lec">
<rect key="frame" x="0.0" y="44.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Lrp-57-Lec" id="oAi-8m-7Ve">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="qM3-Fa-wHS" id="4b9-xh-lHT"/>
<outlet property="delegate" destination="qM3-Fa-wHS" id="h7R-j4-Hd1"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="1uK-dd-Sf2">
<barButtonItem key="rightBarButtonItem" systemItem="action" id="9YG-qv-vKZ">
<connections>
<action selector="share" destination="qM3-Fa-wHS" id="jhI-KK-oF0"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mgR-Lf-2xM" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-992" y="1597"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="E3L-WX-VYA">
<objects>
Expand Down
85 changes: 85 additions & 0 deletions GeofenceTester/EventsTableViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// EventsTableViewController.swift
// GeofenceTester
//
// Created by Alexander von Below on 27.06.22.
//

import UIKit

class EventsTableViewController: UITableViewController {

var storage: PersistantStorage<EventRecord>!

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Events"
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Event Cell")
}

@IBAction func share() {
let text = storage.storage.reduce("") { partialResult, event in
partialResult + event.debugDescription + "\n"
}
let activityController = UIActivityViewController(activityItems: [text], applicationActivities: nil)
self.present(activityController, animated: true)
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return storage.storage.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Event Cell", for: indexPath)

var config = cell.defaultContentConfiguration()
let event = storage.storage[indexPath.row]
config.text = event.debugDescription
cell.contentConfiguration = config
return cell
}

/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/

/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/

}
2 changes: 1 addition & 1 deletion GeofenceTester/PersistantStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation

class PersistantStorage<T: Codable> {

private var storage = Array<T>()
public private(set) var storage = Array<T>()
private let decoder = JSONDecoder()
private let encoder = JSONEncoder()
private let kFilename = "geolocator.log"
Expand Down
11 changes: 8 additions & 3 deletions GeofenceTester/RegionsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import os.log
class RegionsListViewController: UIViewController, MKMapViewDelegate {

var locationManager: CLLocationManager!
var storage: PersistantStorage<EventRecord>!
private var logger = Logger()

@IBOutlet var mapView: MKMapView!
Expand Down Expand Up @@ -123,7 +124,7 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate {
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if let detailView = segue.destination as? RegionViewController {
if let destination = segue.destination as? RegionViewController {
guard let annotation = sender as? MKAnnotation else {
let logger = Logger()
logger.log(level: .error, "Sender was not MKAnnotation")
Expand All @@ -132,8 +133,12 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate {
guard let identifier = annotation.title else {
return
}
detailView.identifier = identifier
detailView.locationManager = locationManager
destination.identifier = identifier
destination.locationManager = locationManager
}

if let destination = segue.destination as? EventsTableViewController {
destination.storage = storage
}
}

Expand Down
1 change: 1 addition & 0 deletions GeofenceTester/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class ViewController: UIViewController, CLLocationManagerDelegate {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let regionsController = segue.destination as? RegionsListViewController {
regionsController.locationManager = locationManager
regionsController.storage = storage
}
}
}
Expand Down

0 comments on commit b0fac15

Please sign in to comment.