Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ZRAdio
CSE 4095 Major iOS Project
- Loading branch information
Showing
13 changed files
with
946 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
ZRadiov2.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Bucket | ||
uuid = "DB395757-5326-4EB5-94C9-6F64DFE33B80" | ||
type = "1" | ||
version = "2.0"> | ||
</Bucket> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
// | ||
// AddStationsViewController.swift | ||
// ZRadiov2 | ||
// | ||
// Created by Kenny Payes on 3/31/20. | ||
// Copyright © 2020 Kenny Payes. All rights reserved. | ||
// | ||
import UIKit | ||
|
||
class AddStationsViewController: UIViewController { | ||
|
||
@IBOutlet weak var newStationName: UITextField! | ||
@IBOutlet weak var newStationLink: UITextField! | ||
@IBOutlet weak var removeStationName: UITextField! | ||
@IBOutlet weak var changeStation: UITextField! | ||
|
||
let s = StationStorage() | ||
var stations = [String:String]() | ||
var stationsList = [[String]]() | ||
|
||
@IBOutlet weak var addTextField: UITextField! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
stations = s.stationList | ||
|
||
let dictKeys = [String](stations.keys) | ||
let dictvalues = [String](stations.values) | ||
|
||
for i in 0...(dictKeys.count - 1){ | ||
stationsList.append([dictKeys[i], dictvalues[i]]) | ||
} | ||
|
||
//print("\n addStations: \(stationsList) \n") | ||
// Do any additional setup after loading the view. | ||
} | ||
|
||
@IBAction func addStationsButton(_ sender: Any) { | ||
|
||
if newStationName.text?.trimmingCharacters(in: .whitespaces) != "" || newStationLink.text?.trimmingCharacters(in: .whitespaces) != "" { | ||
var testContent:String? | ||
testContent = "[ \n" | ||
|
||
for i in 0...(stationsList.count - 1){ | ||
let stationElement:String? = " { \n \"name\" : \"\(stationsList[i][0])\", \n \"url\" : \"\(stationsList[i][1])\" \n " | ||
testContent = testContent! + stationElement! + "}, \n" | ||
|
||
} | ||
|
||
testContent = testContent! + "{ \n \"name\" : \"\(String(newStationName.text!))\", \n \"url\" : \"\(String(newStationLink.text!))\" \n } \n " | ||
|
||
testContent = testContent! + "]" | ||
|
||
|
||
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("stations.json") | ||
|
||
do{ | ||
|
||
try testContent!.write(to: url, atomically: true, encoding: String.Encoding.utf8) | ||
print("File Created!") | ||
|
||
} catch { print("error writing to file...") } | ||
|
||
print(url) | ||
|
||
let fileName = "stations.json" | ||
|
||
var filePath = "" | ||
|
||
let dirs = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true) | ||
|
||
if dirs.count > 0{ | ||
let dir = dirs[0] | ||
filePath = dir.appending("/" + fileName) | ||
print("local path: = \(filePath)" ) | ||
}else{ | ||
print("Could not find filePath") | ||
} | ||
|
||
let fileman = FileManager.default.fileExists(atPath: filePath) | ||
print(fileman) | ||
|
||
newStationLink.text = "" | ||
newStationName.text = "" | ||
} | ||
s.reloadData() | ||
stations = s.stationList | ||
stationsList.removeAll() | ||
let dictKeys = [String](stations.keys) | ||
let dictvalues = [String](stations.values) | ||
|
||
for i in 0...(dictKeys.count - 1){ | ||
stationsList.append([dictKeys[i], dictvalues[i]]) | ||
} | ||
} | ||
|
||
@IBAction func removePressed(_ sender: Any) { | ||
for i in 0...(stationsList.count - 1){ | ||
if stationsList[i][0] == removeStationName.text { | ||
|
||
print("Before removing \(stationsList)") | ||
|
||
stationsList.remove(at: i) | ||
|
||
print("After removing \(stationsList)") | ||
|
||
var testContent:String? | ||
testContent = "[ \n" | ||
|
||
var count = 0 | ||
for i in 0...(stationsList.count - 1){ | ||
if count != 0{ testContent = testContent! + ", \n" } else {testContent = testContent! + "\n" } | ||
count += 1 | ||
let stationElement:String? = " { \n \"name\" : \"\(stationsList[i][0])\", \n \"url\" : \"\(stationsList[i][1])\" \n " | ||
testContent = testContent! + stationElement! + "} \n" | ||
} | ||
|
||
testContent = testContent! + "]" | ||
|
||
print(testContent!) | ||
|
||
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("stations.json") | ||
|
||
do{ | ||
try testContent!.write(to: url, atomically: true, encoding: String.Encoding.utf8) | ||
print("File rewritten!") | ||
} catch { print("error writing to file...") } | ||
|
||
/* | ||
print(url) | ||
let fileName = "stations.json" | ||
var filePath = "" | ||
let dirs = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true) | ||
if dirs.count > 0{ | ||
let dir = dirs[0] | ||
filePath = dir.appending("/" + fileName) | ||
print("local path: = \(filePath)" ) | ||
}else{ | ||
print("Could not find filePath") | ||
} | ||
let fileman = FileManager.default.fileExists(atPath: filePath) | ||
print(fileman) | ||
*/ | ||
|
||
removeStationName.text = "" | ||
break | ||
} | ||
} | ||
s.reloadData() | ||
stations = s.stationList | ||
stationsList.removeAll() | ||
let dictKeys = [String](stations.keys) | ||
let dictvalues = [String](stations.values) | ||
|
||
for i in 0...(dictKeys.count - 1){ | ||
stationsList.append([dictKeys[i], dictvalues[i]]) | ||
} | ||
} | ||
|
||
@IBAction func changePressed(_ sender: Any) { | ||
for i in 0...(stationsList.count - 1){ | ||
if stationsList[i][0] == changeStation.text { | ||
|
||
let testContent = "[{\"name\" : \"\(stationsList[i][0])\", \n \"url\" : \"\(stationsList[i][1])\"} ]" | ||
|
||
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("defaultStation.json") | ||
|
||
do{ | ||
try testContent.write(to: url, atomically: true, encoding: String.Encoding.utf8) | ||
print("File rewritten!") | ||
} catch { print("error writing to file...") } | ||
|
||
break | ||
|
||
} | ||
} | ||
changeStation.text = "" | ||
} | ||
|
||
@IBAction func linkPressed(_ sender: Any) { | ||
if let url = URL(string: "http://www.radiosure.com/stations/") { | ||
UIApplication.shared.open(url) | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.