This file contains hidden or 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
// fetch google sheet all datas and store in menus | |
func fetchItem() { | |
// remember to switch googlesheetid with your own one! | |
let urlStr = "https://spreadsheets.google.com/feeds/list/googlesheetid/od6/public/values?alt=json" | |
if let url = URL(string: urlStr) { | |
URLSession.shared.dataTask(with: url) { (data, response, error) in | |
if let data = data { | |
let decoder = JSONDecoder() | |
do { | |
let searchResponse = try decoder.decode(Menu.self, from: data) |
This file contains hidden or 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
@IBAction func playPreviousPressed(_ sender: UIButton) { | |
if repeatType == .one { | |
playingIndex = songs.firstIndex(of: songPlayed!) | |
songPlayed = songs![playingIndex] | |
configurePlayer(song: songPlayed!) | |
player.play() | |
} else { | |
playingIndex = songs.firstIndex(of: songPlayed!) | |
print("first: List\(playingIndex!)") | |
playingIndex -= 1 |
This file contains hidden or 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
@IBAction func playNextPressed(_ sender: UIButton) { | |
switch player.timeControlStatus { | |
case .paused: | |
playNPause.setImage(UIImage(systemName: SystemName.playFill), for: .normal) | |
player.pause() | |
let time = CMTime(value: 0, timescale: 1) | |
player.seek(to: time) | |
playingIndex = songs.firstIndex(of: songPlayed!) | |
playingIndex += 1 | |
if playingIndex == songs?.count { |
This file contains hidden or 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
func repeatStateCheck() { | |
switch repeatType { | |
case .none: | |
playingIndex = songs.firstIndex(of: songPlayed!) | |
playingIndex += 1 | |
if playingIndex == songs.count { | |
player.pause() | |
playNPause.setImage(UIImage(systemName: SystemName.playFill), for: .normal) | |
} else { | |
songPlayed = songs[playingIndex] |
This file contains hidden or 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
// 隨機播放,預設無,點選變成有 | |
@IBAction func playShufflePressed(_ sender: UIButton) { | |
switch shuffleType { | |
case .no: | |
shuffleType = .yes | |
playShuffle.setImage(UIImage(systemName: SystemName.shuffleCircleFill), for: .normal) | |
songs?.shuffle() | |
case .yes: | |
shuffleType = .no | |
playShuffle.setImage(UIImage(systemName: SystemName.shuffleCircle), for: .normal) |
This file contains hidden or 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
func fetchMusic() { | |
if let urlStr = "https://itunes.apple.com/search?term=宇多田光&media=music&country=JP".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) { | |
if let url = URL(string: urlStr) { | |
URLSession.shared.dataTask(with: url) { (data, response, error) in | |
if let data = data { | |
let decoder = JSONDecoder() | |
do { | |
let result = try decoder.decode(MusicOnline.self, from: data) | |
self.showOnlineFile = result.results | |
} catch { |
This file contains hidden or 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
// AutoLayout | |
stackView.translatesAutoresizingMaskIntoConstraints = false | |
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true | |
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true | |
stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true | |
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true |
This file contains hidden or 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
let segmentedControl: UISegmentedControl = { | |
let sc = UISegmentedControl(items: ["Local", "Online Preview"]) | |
sc.addTarget(self, action: #selector(segmentChanged), for: .valueChanged) | |
sc.selectedSegmentIndex = 0 | |
return sc | |
}() | |
let tableView = UITableView(frame: .zero, style: .plain) | |
let stackView = UIStackView(arrangedSubviews: [segmentedControl, tableView]) | |
stackView.axis = .vertical |
This file contains hidden or 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
func loadUser() { | |
db.collection(Constant.FireStore.users).getDocuments { (querySnapshot, error) in | |
if let error = error { | |
print("There was an issue retrieving data to Firestore. \(error)") | |
} else { | |
if let snapshotDocuments = querySnapshot?.documents { | |
for doc in snapshotDocuments { | |
let data = doc.data() | |
if let userName = data[Constant.FireStore.userName] as? String { | |
// label顯示速度有差,再確認 |