Skip to content
Permalink
Browse files

ZRAdio

CSE 4095 Major iOS Project
  • Loading branch information
kop16101 committed Apr 2, 2020
1 parent 4cdedea commit ff963a53f9677b9f865900bf2cace4142a839a82
@@ -9,13 +9,20 @@
/* Begin PBXBuildFile section */
B9318F352432D9C10036174D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F342432D9C10036174D /* AppDelegate.swift */; };
B9318F372432D9C10036174D /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F362432D9C10036174D /* SceneDelegate.swift */; };
B9318F392432D9C10036174D /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F382432D9C10036174D /* FirstViewController.swift */; };
B9318F3B2432D9C10036174D /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F3A2432D9C10036174D /* SecondViewController.swift */; };
B9318F392432D9C10036174D /* RadioViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F382432D9C10036174D /* RadioViewController.swift */; };
B9318F3B2432D9C10036174D /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F3A2432D9C10036174D /* SettingsViewController.swift */; };
B9318F3E2432D9C10036174D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B9318F3C2432D9C10036174D /* Main.storyboard */; };
B9318F402432D9C70036174D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B9318F3F2432D9C70036174D /* Assets.xcassets */; };
B9318F432432D9C70036174D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B9318F412432D9C70036174D /* LaunchScreen.storyboard */; };
B9318F4E2432D9C80036174D /* ZRadiov2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F4D2432D9C80036174D /* ZRadiov2Tests.swift */; };
B9318F592432D9C80036174D /* ZRadiov2UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F582432D9C80036174D /* ZRadiov2UITests.swift */; };
B9318F672432DE1D0036174D /* Stations.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F662432DE1D0036174D /* Stations.swift */; };
B9318F692432DE270036174D /* StationStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F682432DE270036174D /* StationStorage.swift */; };
B9318F712432DFF50036174D /* SavedStationsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9318F702432DFF50036174D /* SavedStationsCell.swift */; };
B9FD5E672433AC530080FFCD /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FD5E662433AC530080FFCD /* MainTabBarController.swift */; };
B9FD5E69243411760080FFCD /* AddStationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FD5E68243411760080FFCD /* AddStationsViewController.swift */; };
B9FD5E6C2434485C0080FFCD /* stations.json in Resources */ = {isa = PBXBuildFile; fileRef = B9FD5E6A2434482D0080FFCD /* stations.json */; };
B9FD5E6D243448600080FFCD /* defaultStation.json in Resources */ = {isa = PBXBuildFile; fileRef = B9FD5E6B2434482F0080FFCD /* defaultStation.json */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
@@ -39,8 +46,8 @@
B9318F312432D9C10036174D /* ZRadiov2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZRadiov2.app; sourceTree = BUILT_PRODUCTS_DIR; };
B9318F342432D9C10036174D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
B9318F362432D9C10036174D /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
B9318F382432D9C10036174D /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = "<group>"; };
B9318F3A2432D9C10036174D /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = "<group>"; };
B9318F382432D9C10036174D /* RadioViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioViewController.swift; sourceTree = "<group>"; };
B9318F3A2432D9C10036174D /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
B9318F3D2432D9C10036174D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
B9318F3F2432D9C70036174D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
B9318F422432D9C70036174D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -51,6 +58,13 @@
B9318F542432D9C80036174D /* ZRadiov2UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZRadiov2UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B9318F582432D9C80036174D /* ZRadiov2UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZRadiov2UITests.swift; sourceTree = "<group>"; };
B9318F5A2432D9C80036174D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B9318F662432DE1D0036174D /* Stations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Stations.swift; path = "../../Z Radio/Z Radio/Stations.swift"; sourceTree = "<group>"; };
B9318F682432DE270036174D /* StationStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StationStorage.swift; path = "../../Z Radio/Z Radio/StationStorage.swift"; sourceTree = "<group>"; };
B9318F702432DFF50036174D /* SavedStationsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavedStationsCell.swift; sourceTree = "<group>"; };
B9FD5E662433AC530080FFCD /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = "<group>"; };
B9FD5E68243411760080FFCD /* AddStationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddStationsViewController.swift; sourceTree = "<group>"; };
B9FD5E6A2434482D0080FFCD /* stations.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = stations.json; sourceTree = "<group>"; };
B9FD5E6B2434482F0080FFCD /* defaultStation.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = defaultStation.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
@@ -103,12 +117,19 @@
children = (
B9318F342432D9C10036174D /* AppDelegate.swift */,
B9318F362432D9C10036174D /* SceneDelegate.swift */,
B9318F382432D9C10036174D /* FirstViewController.swift */,
B9318F3A2432D9C10036174D /* SecondViewController.swift */,
B9FD5E662433AC530080FFCD /* MainTabBarController.swift */,
B9318F382432D9C10036174D /* RadioViewController.swift */,
B9FD5E68243411760080FFCD /* AddStationsViewController.swift */,
B9318F702432DFF50036174D /* SavedStationsCell.swift */,
B9318F3A2432D9C10036174D /* SettingsViewController.swift */,
B9318F3C2432D9C10036174D /* Main.storyboard */,
B9318F3F2432D9C70036174D /* Assets.xcassets */,
B9318F662432DE1D0036174D /* Stations.swift */,
B9318F682432DE270036174D /* StationStorage.swift */,
B9318F412432D9C70036174D /* LaunchScreen.storyboard */,
B9318F442432D9C70036174D /* Info.plist */,
B9FD5E6A2434482D0080FFCD /* stations.json */,
B9FD5E6B2434482F0080FFCD /* defaultStation.json */,
);
path = ZRadiov2;
sourceTree = "<group>";
@@ -235,6 +256,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B9FD5E6D243448600080FFCD /* defaultStation.json in Resources */,
B9FD5E6C2434485C0080FFCD /* stations.json in Resources */,
B9318F432432D9C70036174D /* LaunchScreen.storyboard in Resources */,
B9318F402432D9C70036174D /* Assets.xcassets in Resources */,
B9318F3E2432D9C10036174D /* Main.storyboard in Resources */,
@@ -262,9 +285,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B9318F3B2432D9C10036174D /* SecondViewController.swift in Sources */,
B9318F392432D9C10036174D /* FirstViewController.swift in Sources */,
B9318F3B2432D9C10036174D /* SettingsViewController.swift in Sources */,
B9FD5E672433AC530080FFCD /* MainTabBarController.swift in Sources */,
B9FD5E69243411760080FFCD /* AddStationsViewController.swift in Sources */,
B9318F672432DE1D0036174D /* Stations.swift in Sources */,
B9318F392432D9C10036174D /* RadioViewController.swift in Sources */,
B9318F352432D9C10036174D /* AppDelegate.swift in Sources */,
B9318F692432DE270036174D /* StationStorage.swift in Sources */,
B9318F712432DFF50036174D /* SavedStationsCell.swift in Sources */,
B9318F372432D9C10036174D /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "DB395757-5326-4EB5-94C9-6F64DFE33B80"
type = "1"
version = "2.0">
</Bucket>
@@ -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)
}

}

}

0 comments on commit ff963a5

Please sign in to comment.
You can’t perform that action at this time.