Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions flo/CarPlay/CarPlayCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,31 @@ class CarPlayCoordinator {

private func makeLibraryTab() -> CPListTemplate {
let albumsItem = CPListItem(
text: "Albums", detailText: nil,
text: String(localized: "Albums"), detailText: nil,
image: UIImage(systemName: "square.stack")?.withRenderingMode(.alwaysTemplate))
albumsItem.handler = { [weak self] _, completion in
self?.showAlbumsList()
completion()
}

let artistsItem = CPListItem(
text: "Artists", detailText: nil,
text: String(localized: "Artists"), detailText: nil,
image: UIImage(systemName: "music.mic")?.withRenderingMode(.alwaysTemplate))
artistsItem.handler = { [weak self] _, completion in
self?.showArtistsList()
completion()
}

let songsItem = CPListItem(
text: "Songs", detailText: nil,
text: String(localized: "Songs"), detailText: nil,
image: UIImage(systemName: "music.note")?.withRenderingMode(.alwaysTemplate))
songsItem.handler = { [weak self] _, completion in
self?.showSongsList()
completion()
}

let section = CPListSection(items: [albumsItem, artistsItem, songsItem])
let template = CPListTemplate(title: "Library", sections: [section])
let template = CPListTemplate(title: String(localized: "Library"), sections: [section])
template.tabImage = UIImage(systemName: "square.grid.2x2")

return template
Expand All @@ -80,7 +80,7 @@ class CarPlayCoordinator {
// MARK: - Albums

private func showAlbumsList() {
let loadingTemplate = CPListTemplate(title: "Albums", sections: [])
let loadingTemplate = CPListTemplate(title: String(localized: "Albums"), sections: [])
interfaceController.pushTemplate(loadingTemplate, animated: true, completion: nil)

AlbumService.shared.getAlbum { [weak self] result in
Expand Down Expand Up @@ -111,7 +111,7 @@ class CarPlayCoordinator {
loadingTemplate.updateSections([CPListSection(items: items)])

case .failure:
let errorItem = CPListItem(text: "Failed to load albums", detailText: "Tap to retry")
let errorItem = CPListItem(text: String(localized: "Failed to load albums"), detailText: String(localized: "Tap to retry"))
errorItem.handler = { [weak self] _, completion in
self?.interfaceController.popTemplate(animated: false, completion: nil)
self?.showAlbumsList()
Expand Down Expand Up @@ -165,8 +165,8 @@ class CarPlayCoordinator {
template: CPListTemplate, album: Album, isDownloaded: Bool
) {
let playAllItem = CPListItem(
text: "Play All",
detailText: "\(album.songs.count) tracks",
text: String(localized: "Play All"),
detailText: String(localized: "\(album.songs.count) tracks"),
image: UIImage(systemName: "play.fill")?.withRenderingMode(.alwaysTemplate)
)
playAllItem.handler = { [weak self] _, completion in
Expand All @@ -176,7 +176,7 @@ class CarPlayCoordinator {
}

let shuffleItem = CPListItem(
text: "Shuffle",
text: String(localized: "Shuffle"),
detailText: nil,
image: UIImage(systemName: "shuffle")?.withRenderingMode(.alwaysTemplate)
)
Expand All @@ -202,7 +202,7 @@ class CarPlayCoordinator {
}
let trackSection = CPListSection(
items: trackItems,
header: "Tracks",
header: String(localized: "Tracks"),
sectionIndexTitle: nil
)

Expand All @@ -214,7 +214,7 @@ class CarPlayCoordinator {
private var filterAlbumArtistOnly = true

private func showArtistsList() {
let loadingTemplate = CPListTemplate(title: "Artists", sections: [])
let loadingTemplate = CPListTemplate(title: String(localized: "Artists"), sections: [])
interfaceController.pushTemplate(loadingTemplate, animated: true, completion: nil)

AlbumService.shared.getArtists { [weak self] result in
Expand All @@ -228,7 +228,7 @@ class CarPlayCoordinator {
let items = filteredArtists.map { artist -> CPListItem in
let item = CPListItem(
text: artist.name,
detailText: "\(artist.albumCount) albums"
detailText: String(localized: "\(artist.albumCount) albums")
)
item.handler = { [weak self] _, completion in
self?.showArtistAlbums(artist: artist)
Expand All @@ -239,7 +239,7 @@ class CarPlayCoordinator {
loadingTemplate.updateSections([CPListSection(items: items)])

case .failure:
let errorItem = CPListItem(text: "Failed to load artists", detailText: "Tap to retry")
let errorItem = CPListItem(text: String(localized: "Failed to load artists"), detailText: String(localized: "Tap to retry"))
errorItem.handler = { [weak self] _, completion in
self?.interfaceController.popTemplate(animated: false, completion: nil)
self?.showArtistsList()
Expand All @@ -261,7 +261,7 @@ class CarPlayCoordinator {
switch result {
case .success(let albums):
let radioItem = CPListItem(
text: "Play Artist Radio",
text: String(localized: "Play Artist Radio"),
detailText: nil,
image: UIImage(systemName: "dot.radiowaves.up.forward")
)
Expand All @@ -271,7 +271,7 @@ class CarPlayCoordinator {
}

let topSongsItem = CPListItem(
text: "Play Top Songs",
text: String(localized: "Play Top Songs"),
detailText: nil,
image: UIImage(systemName: "star.fill")
)
Expand Down Expand Up @@ -304,7 +304,7 @@ class CarPlayCoordinator {
}
let albumSection = CPListSection(
items: albumItems,
header: "Albums",
header: String(localized: "Albums"),
sectionIndexTitle: nil
)

Expand All @@ -313,7 +313,7 @@ class CarPlayCoordinator {
case .failure:
loadingTemplate.updateSections([
CPListSection(items: [
CPListItem(text: "Failed to load albums", detailText: nil)
CPListItem(text: String(localized: "Failed to load albums"), detailText: nil)
])
])
}
Expand All @@ -331,16 +331,16 @@ class CarPlayCoordinator {
case .success(let songs) where !songs.isEmpty:
let playable = RadioEntity(
id: artist.id,
name: "\(artist.name) Radio",
name: String(localized: "\(artist.name) Radio"),
songs: songs,
artist: artist.name
)
self.playerVM.playItem(item: playable, isFromLocal: false)
self.showNowPlaying()
case .success:
self.showErrorTemplate(title: "No Radio Available", message: "No similar songs found for \(artist.name).")
self.showErrorTemplate(title: String(localized: "No Radio Available"), message: String(localized: "No similar songs found for \(artist.name)."))
case .failure:
self.showErrorTemplate(title: "Radio Unavailable", message: "Could not load radio for \(artist.name).")
self.showErrorTemplate(title: String(localized: "Radio Unavailable"), message: String(localized: "Could not load radio for \(artist.name)."))
}
}
}
Expand All @@ -354,16 +354,16 @@ class CarPlayCoordinator {
case .success(let songs) where !songs.isEmpty:
let playable = RadioEntity(
id: artist.id,
name: "\(artist.name) Top Songs",
name: String(localized: "\(artist.name) Top Songs"),
songs: songs,
artist: artist.name
)
self.playerVM.playItem(item: playable, isFromLocal: false)
self.showNowPlaying()
case .success:
self.showErrorTemplate(title: "No Top Songs", message: "No top songs found for \(artist.name).")
self.showErrorTemplate(title: String(localized: "No Top Songs"), message: String(localized: "No top songs found for \(artist.name)."))
case .failure:
self.showErrorTemplate(title: "Unavailable", message: "Could not load top songs for \(artist.name).")
self.showErrorTemplate(title: String(localized: "Unavailable"), message: String(localized: "Could not load top songs for \(artist.name)."))
}
}
}
Expand All @@ -378,7 +378,7 @@ class CarPlayCoordinator {
// MARK: - Songs

private func showSongsList() {
let loadingTemplate = CPListTemplate(title: "Songs", sections: [])
let loadingTemplate = CPListTemplate(title: String(localized: "Songs"), sections: [])
interfaceController.pushTemplate(loadingTemplate, animated: true, completion: nil)

AlbumService.shared.getAllSongs { [weak self] result in
Expand All @@ -393,7 +393,7 @@ class CarPlayCoordinator {
)
item.handler = { [weak self] _, completion in
guard let self = self else { return }
let allTracks = Playlist(name: "All Tracks", songs: songs)
let allTracks = Playlist(name: String(localized: "All Tracks"), songs: songs)
self.playerVM.playBySong(idx: idx, item: allTracks, isFromLocal: false)
self.showNowPlaying()
completion()
Expand All @@ -403,7 +403,7 @@ class CarPlayCoordinator {
loadingTemplate.updateSections([CPListSection(items: items)])

case .failure:
let errorItem = CPListItem(text: "Failed to load songs", detailText: "Tap to retry")
let errorItem = CPListItem(text: String(localized: "Failed to load songs"), detailText: String(localized: "Tap to retry"))
errorItem.handler = { [weak self] _, completion in
self?.interfaceController.popTemplate(animated: false, completion: nil)
self?.showSongsList()
Expand All @@ -418,10 +418,10 @@ class CarPlayCoordinator {
// MARK: - Playlists Tab

private func makePlaylistsTab() -> CPListTemplate {
let loadingItem = CPListItem(text: "Loading playlists…", detailText: nil)
let loadingItem = CPListItem(text: String(localized: "Loading playlists…"), detailText: nil)
loadingItem.isEnabled = false
let template = CPListTemplate(
title: "Playlists", sections: [CPListSection(items: [loadingItem])])
title: String(localized: "Playlists"), sections: [CPListSection(items: [loadingItem])])
template.tabImage = UIImage(systemName: "music.note.list")

AlbumService.shared.getPlaylists { [weak self] result in
Expand All @@ -445,7 +445,7 @@ class CarPlayCoordinator {
case .failure:
template.updateSections([
CPListSection(items: [
CPListItem(text: "Failed to load playlists", detailText: nil)
CPListItem(text: String(localized: "Failed to load playlists"), detailText: nil)
])
])
}
Expand Down Expand Up @@ -486,8 +486,8 @@ class CarPlayCoordinator {
template: CPListTemplate, playlist: Playlist, isDownloaded: Bool
) {
let playAllItem = CPListItem(
text: "Play All",
detailText: "\(playlist.songs.count) tracks",
text: String(localized: "Play All"),
detailText: String(localized: "\(playlist.songs.count) tracks"),
image: UIImage(systemName: "play.fill")
)
playAllItem.handler = { [weak self] _, completion in
Expand All @@ -497,7 +497,7 @@ class CarPlayCoordinator {
}

let shuffleItem = CPListItem(
text: "Shuffle",
text: String(localized: "Shuffle"),
detailText: nil,
image: UIImage(systemName: "shuffle")
)
Expand All @@ -523,7 +523,7 @@ class CarPlayCoordinator {
}
let trackSection = CPListSection(
items: trackItems,
header: "Tracks",
header: String(localized: "Tracks"),
sectionIndexTitle: nil
)

Expand All @@ -533,10 +533,10 @@ class CarPlayCoordinator {
// MARK: - Radio Tab

private func makeRadioTab() -> CPListTemplate {
let loadingItem = CPListItem(text: "Loading stations…", detailText: nil)
let loadingItem = CPListItem(text: String(localized: "Loading stations…"), detailText: nil)
loadingItem.isEnabled = false
let template = CPListTemplate(
title: "Radio", sections: [CPListSection(items: [loadingItem])])
title: String(localized: "Radio"), sections: [CPListSection(items: [loadingItem])])
template.tabImage = UIImage(systemName: "radio")

RadioService.shared.getAllRadios { [weak self] result in
Expand All @@ -547,7 +547,7 @@ class CarPlayCoordinator {
if radios.isEmpty {
template.updateSections([
CPListSection(items: [
CPListItem(text: "No radio stations", detailText: nil)
CPListItem(text: String(localized: "No radio stations"), detailText: nil)
])
])
return
Expand All @@ -571,7 +571,7 @@ class CarPlayCoordinator {
case .failure:
template.updateSections([
CPListSection(items: [
CPListItem(text: "Failed to load radios", detailText: nil)
CPListItem(text: String(localized: "Failed to load radios"), detailText: nil)
])
])
}
Expand All @@ -584,10 +584,10 @@ class CarPlayCoordinator {
// MARK: - Downloads Tab

private func makeDownloadsTab() -> CPListTemplate {
let loadingItem = CPListItem(text: "Loading downloads…", detailText: nil)
let loadingItem = CPListItem(text: String(localized: "Loading downloads…"), detailText: nil)
loadingItem.isEnabled = false
let template = CPListTemplate(
title: "Downloads", sections: [CPListSection(items: [loadingItem])])
title: String(localized: "Downloads"), sections: [CPListSection(items: [loadingItem])])
template.tabImage = UIImage(systemName: "arrow.down.circle")

AlbumService.shared.getDownloadedAlbum { [weak self] result in
Expand All @@ -602,7 +602,7 @@ class CarPlayCoordinator {
if filtered.isEmpty {
template.updateSections([
CPListSection(items: [
CPListItem(text: "No downloads", detailText: "Download music from the app")
CPListItem(text: String(localized: "No downloads"), detailText: String(localized: "Download music from the app"))
])
])
return
Expand Down Expand Up @@ -633,7 +633,7 @@ class CarPlayCoordinator {
case .failure:
template.updateSections([
CPListSection(items: [
CPListItem(text: "No downloads available", detailText: nil)
CPListItem(text: String(localized: "No downloads available"), detailText: nil)
])
])
}
Expand Down
10 changes: 5 additions & 5 deletions flo/CarPlay/CarPlayNowPlayingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CarPlayNowPlayingManager: NSObject {
nowPlaying.add(self)

nowPlaying.isUpNextButtonEnabled = true
nowPlaying.upNextTitle = "Up Next"
nowPlaying.upNextTitle = String(localized: "Up Next")

updateButtons(on: nowPlaying)

Expand Down Expand Up @@ -72,7 +72,7 @@ extension CarPlayNowPlayingManager: CPNowPlayingTemplateObserver {
guard idx > activeIdx else { return nil }

let item = CPListItem(
text: entity.songName ?? "Unknown",
text: entity.songName ?? String(localized: "Unknown"),
detailText: entity.artistName ?? ""
)
item.handler = { [weak self] _, completion in
Expand All @@ -83,15 +83,15 @@ extension CarPlayNowPlayingManager: CPNowPlayingTemplateObserver {
}

if upcomingItems.isEmpty {
let emptyItem = CPListItem(text: "No upcoming tracks", detailText: nil)
let emptyItem = CPListItem(text: String(localized: "No upcoming tracks"), detailText: nil)
let template = CPListTemplate(
title: "Up Next",
title: String(localized: "Up Next"),
sections: [CPListSection(items: [emptyItem])]
)
interfaceController.pushTemplate(template, animated: true, completion: nil)
} else {
let template = CPListTemplate(
title: "Up Next",
title: String(localized: "Up Next"),
sections: [CPListSection(items: upcomingItems)]
)
interfaceController.pushTemplate(template, animated: true, completion: nil)
Expand Down
Loading