From ff963a53f9677b9f865900bf2cace4142a839a82 Mon Sep 17 00:00:00 2001 From: Kenny O Payes Galeano Date: Thu, 2 Apr 2020 15:22:50 -0400 Subject: [PATCH] ZRAdio CSE 4095 Major iOS Project --- ZRadiov2.xcodeproj/project.pbxproj | 44 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 6 + ZRadiov2/AddStationsViewController.swift | 193 +++++++ ZRadiov2/Base.lproj/LaunchScreen.storyboard | 43 +- ZRadiov2/Base.lproj/Main.storyboard | 480 ++++++++++++++++-- ZRadiov2/FirstViewController.swift | 20 - ZRadiov2/Info.plist | 9 + ZRadiov2/MainTabBarController.swift | 31 ++ ZRadiov2/RadioViewController.swift | 138 +++++ ZRadiov2/SavedStationsCell.swift | 35 ++ ...ler.swift => SettingsViewController.swift} | 3 +- ZRadiov2/defaultStation.json | 6 + ZRadiov2/stations.json | 14 + 13 files changed, 946 insertions(+), 76 deletions(-) create mode 100644 ZRadiov2.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist create mode 100644 ZRadiov2/AddStationsViewController.swift delete mode 100644 ZRadiov2/FirstViewController.swift create mode 100644 ZRadiov2/MainTabBarController.swift create mode 100644 ZRadiov2/RadioViewController.swift create mode 100644 ZRadiov2/SavedStationsCell.swift rename ZRadiov2/{SecondViewController.swift => SettingsViewController.swift} (85%) create mode 100644 ZRadiov2/defaultStation.json create mode 100644 ZRadiov2/stations.json diff --git a/ZRadiov2.xcodeproj/project.pbxproj b/ZRadiov2.xcodeproj/project.pbxproj index 1b2cb3f..9d0520d 100644 --- a/ZRadiov2.xcodeproj/project.pbxproj +++ b/ZRadiov2.xcodeproj/project.pbxproj @@ -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 = ""; }; B9318F362432D9C10036174D /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - B9318F382432D9C10036174D /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = ""; }; - B9318F3A2432D9C10036174D /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; + B9318F382432D9C10036174D /* RadioViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioViewController.swift; sourceTree = ""; }; + B9318F3A2432D9C10036174D /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; B9318F3D2432D9C10036174D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; B9318F3F2432D9C70036174D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; B9318F422432D9C70036174D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -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 = ""; }; B9318F5A2432D9C80036174D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B9318F662432DE1D0036174D /* Stations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Stations.swift; path = "../../Z Radio/Z Radio/Stations.swift"; sourceTree = ""; }; + B9318F682432DE270036174D /* StationStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StationStorage.swift; path = "../../Z Radio/Z Radio/StationStorage.swift"; sourceTree = ""; }; + B9318F702432DFF50036174D /* SavedStationsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavedStationsCell.swift; sourceTree = ""; }; + B9FD5E662433AC530080FFCD /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = ""; }; + B9FD5E68243411760080FFCD /* AddStationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddStationsViewController.swift; sourceTree = ""; }; + B9FD5E6A2434482D0080FFCD /* stations.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = stations.json; sourceTree = ""; }; + B9FD5E6B2434482F0080FFCD /* defaultStation.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = defaultStation.json; sourceTree = ""; }; /* 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 = ""; @@ -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; diff --git a/ZRadiov2.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZRadiov2.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..52d128f --- /dev/null +++ b/ZRadiov2.xcodeproj/xcuserdata/kenny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/ZRadiov2/AddStationsViewController.swift b/ZRadiov2/AddStationsViewController.swift new file mode 100644 index 0000000..c1d13bc --- /dev/null +++ b/ZRadiov2/AddStationsViewController.swift @@ -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) + } + + } + +} diff --git a/ZRadiov2/Base.lproj/LaunchScreen.storyboard b/ZRadiov2/Base.lproj/LaunchScreen.storyboard index 865e932..6b2b21c 100644 --- a/ZRadiov2/Base.lproj/LaunchScreen.storyboard +++ b/ZRadiov2/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - - + + + - + @@ -11,15 +12,45 @@ - + - + + + + + + + + + + + + + + + + + + - + diff --git a/ZRadiov2/Base.lproj/Main.storyboard b/ZRadiov2/Base.lproj/Main.storyboard index 7a85710..53ccd0a 100644 --- a/ZRadiov2/Base.lproj/Main.storyboard +++ b/ZRadiov2/Base.lproj/Main.storyboard @@ -1,85 +1,461 @@ - + + - + - + - + - + - - + - - - - + + + + + + + + + + + + + + + + + + + + + - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + - + - + - + @@ -88,15 +464,39 @@ + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + diff --git a/ZRadiov2/FirstViewController.swift b/ZRadiov2/FirstViewController.swift deleted file mode 100644 index 1213d26..0000000 --- a/ZRadiov2/FirstViewController.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// FirstViewController.swift -// ZRadiov2 -// -// Created by Kenny Payes on 3/30/20. -// Copyright © 2020 Kenny Payes. All rights reserved. -// - -import UIKit - -class FirstViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} - diff --git a/ZRadiov2/Info.plist b/ZRadiov2/Info.plist index e7f6f58..73fff05 100644 --- a/ZRadiov2/Info.plist +++ b/ZRadiov2/Info.plist @@ -2,6 +2,11 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -39,6 +44,10 @@ + UIBackgroundModes + + audio + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/ZRadiov2/MainTabBarController.swift b/ZRadiov2/MainTabBarController.swift new file mode 100644 index 0000000..8bda6ff --- /dev/null +++ b/ZRadiov2/MainTabBarController.swift @@ -0,0 +1,31 @@ +// +// MainTabBarController.swift +// ZRadiov2 +// +// Created by Kenny Payes on 3/31/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import UIKit +import AVFoundation + +class MainTabBarController: UITabBarController { + + let s = StationStorage() + + var defstations = [String]() + var url: URL? + var currentLabel: String? + var currentURL: String? + + override func viewDidLoad() { + super.viewDidLoad() + let defaultstations = s.defaultStation + + url = URL(string: String(defaultstations[1])) + currentLabel = String(defaultstations[0]) + currentURL = String(defaultstations[1]) + + } + +} diff --git a/ZRadiov2/RadioViewController.swift b/ZRadiov2/RadioViewController.swift new file mode 100644 index 0000000..a03e14c --- /dev/null +++ b/ZRadiov2/RadioViewController.swift @@ -0,0 +1,138 @@ +// +// FirstViewController.swift +// ZRadiov2 +// +// Created by Kenny Payes on 3/30/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import UIKit +import Foundation +import AVFoundation + +class RadioViewController: UIViewController,UITableViewDataSource, UITableViewDelegate { + + let tabBar = MainTabBarController() + + let s = StationStorage() + var stations = [String:String]() + var stationList = [[String]]() + + @IBOutlet weak var playImage: UIImageView! + @IBOutlet weak var customLabel: UILabel! + @IBOutlet weak var currentlyPlaying: UILabel! + @IBOutlet weak var tableView: UITableView! + + var radioOn: Bool? + var radio: AVPlayer? + + let refreshControl = UIRefreshControl() + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + stationList = createStationsList() + + refreshControl.addTarget(self, action: #selector(RadioViewController.handleRefresh), for: .valueChanged) + tableView.refreshControl = refreshControl + tableView.delegate = self + tableView.dataSource = self + + radio = AVPlayer(url:self.tabBar.url!) + radioOn = false + playImage.image = UIImage(systemName: "play.fill") + customLabel.text = String(self.tabBar.currentLabel!) + currentlyPlaying.text = String(self.tabBar.currentURL!) + + } + + @objc func handleRefresh(){ + stationList.removeAll() + stationList = createStationsList() + + Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { (timer) in + self.tableView.reloadData() + self.refreshControl.endRefreshing() + } + } + + @IBAction func buttonPressed(_ sender: Any) { + if radioOn!{ + radioOn = false + radio!.pause() + playImage.image = UIImage(systemName: "play.fill") + } + else{ + radioOn = true + radio!.play() + playImage.image = UIImage(systemName: "pause.fill") + } + } + + func createStationsList() -> [[String]] { + s.reloadData() + stations = s.stationList + + let dictKeys = [String](stations.keys) + let dictvalues = [String](stations.values) + + var stationsList = [[String]]() + + for i in 0...(dictKeys.count - 1){ + stationsList.append([dictKeys[i], dictvalues[i]]) + } + return stationsList + + } + + func changeStation(url: String) -> Void{ + radio?.pause() + radioOn = false + radio?.replaceCurrentItem(with: AVPlayerItem(url: URL(string: url)!)) + radio?.play() + radioOn = true + + print("\(url)) \n") + } + + func changeLabel(label: String) -> Void { + customLabel?.text = label + } + func changeUrl(url: String) -> Void { + currentlyPlaying?.text = url + } + + @IBAction func change(_ sender: Any) { + changeStation(url: (currentlyPlaying?.text)!) + + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return stationList.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + let cell = tableView.dequeueReusableCell(withIdentifier: "cellLabel") as! SavedStationsCell + + cell.setLabel(label: stationList[indexPath.row][0]) + + cell.setUrlPassed(url: stationList[indexPath.row][1]) + + + cell.cellButton.tag = indexPath.row + + cell.cellButton.addTarget(self, action:#selector(self.buttonTapped) , for: .touchUpInside) + return cell + } + + @objc func buttonTapped(sender:UIButton){ + let index: Int = sender.tag + print(index) + changeStation(url: stationList[sender.tag][1]) + changeUrl(url: stationList[sender.tag][1]) + changeLabel(label: stationList[sender.tag][0]) + playImage.image = UIImage(systemName: "pause.fill") + } + +} diff --git a/ZRadiov2/SavedStationsCell.swift b/ZRadiov2/SavedStationsCell.swift new file mode 100644 index 0000000..2c7fbc9 --- /dev/null +++ b/ZRadiov2/SavedStationsCell.swift @@ -0,0 +1,35 @@ +// +// SavedStationsViewController.swift +// ZRadiov2 +// +// Created by Kenny Payes on 3/30/20. +// Copyright © 2020 Kenny Payes. All rights reserved. +// + +import UIKit +import AVFoundation + +class SavedStationsCell: UITableViewCell { + + let tabBar = MainTabBarController() + let radioControl = RadioViewController() + + @IBOutlet weak var cellLabel: UILabel! + @IBOutlet weak var cellButton: UIButton! + + var urlPassed: String? + var labelPassed: String? + + func setLabel(label: String){ + cellLabel.text = label + } + + func setUrlPassed (url: String){ + urlPassed = url + } + + func setLabelPassed (label: String){ + labelPassed = label + } + +} diff --git a/ZRadiov2/SecondViewController.swift b/ZRadiov2/SettingsViewController.swift similarity index 85% rename from ZRadiov2/SecondViewController.swift rename to ZRadiov2/SettingsViewController.swift index dc33c09..deefe60 100644 --- a/ZRadiov2/SecondViewController.swift +++ b/ZRadiov2/SettingsViewController.swift @@ -8,13 +8,12 @@ import UIKit -class SecondViewController: UIViewController { +class SettingsViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } - } diff --git a/ZRadiov2/defaultStation.json b/ZRadiov2/defaultStation.json new file mode 100644 index 0000000..1be3be2 --- /dev/null +++ b/ZRadiov2/defaultStation.json @@ -0,0 +1,6 @@ +[ + { + "name": "Smooch | Rock/Top 40", + "url": "http://stream.radiojar.com/mdk8a0bf8tzuv" + } +] diff --git a/ZRadiov2/stations.json b/ZRadiov2/stations.json new file mode 100644 index 0000000..f70f089 --- /dev/null +++ b/ZRadiov2/stations.json @@ -0,0 +1,14 @@ +[ + { + "name": "Coffee House | Easy Listening", + "url": "http://113fm-edge1.cdnstream.com/1728_128?NoPreroll=true" + }, + { + "name": "Smooch | UK Rock/Top 40", + "url": "http://stream.radiojar.com/mdk8a0bf8tzuv" + }, + { + "name": "POWERHITZ | The Hitlist", + "url" : "http://powerhitz.powerhitz.com:7000/;" + } +]