diff --git a/Halmap.xcodeproj/project.pbxproj b/Halmap.xcodeproj/project.pbxproj index 1eb3d2a..2b31e5b 100644 --- a/Halmap.xcodeproj/project.pbxproj +++ b/Halmap.xcodeproj/project.pbxproj @@ -25,7 +25,6 @@ A81FFC9128F1775000B0FC7C /* SongSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9028F1775000B0FC7C /* SongSearchView.swift */; }; A81FFC9328F1775C00B0FC7C /* StadiumListSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9228F1775C00B0FC7C /* StadiumListSheetView.swift */; }; A81FFC9528F1776300B0FC7C /* StadiumMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9428F1776300B0FC7C /* StadiumMapView.swift */; }; - A81FFC9728F1776F00B0FC7C /* SongInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9628F1776F00B0FC7C /* SongInformationView.swift */; }; A81FFC9928F1777B00B0FC7C /* TeamSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9828F1777B00B0FC7C /* TeamSelectionView.swift */; }; A81FFC9D28F180A000B0FC7C /* SongPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9C28F180A000B0FC7C /* SongPlayerView.swift */; }; A81FFC9F28F180B200B0FC7C /* SongContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81FFC9E28F180B200B0FC7C /* SongContentView.swift */; }; @@ -37,6 +36,7 @@ B2699E1028F1CB9700267A4F /* Pretendard-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = B2699E0F28F1CB9700267A4F /* Pretendard-Medium.otf */; }; EEBC26A028F1CAE900BD5B3D /* TabBarItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEBC269E28F1CAE800BD5B3D /* TabBarItemView.swift */; }; EEBC26A128F1CAE900BD5B3D /* TabBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEBC269F28F1CAE800BD5B3D /* TabBarView.swift */; }; + F9174B2A2A2B2F5F00B1CE87 /* SeasonSong.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9174B292A2B2F5F00B1CE87 /* SeasonSong.swift */; }; F91BE5FB29B18AF800F7E488 /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F91BE5FA29B18AF800F7E488 /* MainTabView.swift */; }; F91BE5FD29B18D1E00F7E488 /* MainSongListTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F91BE5FC29B18D1E00F7E488 /* MainSongListTabView.swift */; }; F939EBBA29D58FB2005ED8CA /* StorageContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F939EBB929D58FB2005ED8CA /* StorageContentView.swift */; }; @@ -74,7 +74,6 @@ A81FFC9028F1775000B0FC7C /* SongSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongSearchView.swift; sourceTree = ""; }; A81FFC9228F1775C00B0FC7C /* StadiumListSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StadiumListSheetView.swift; sourceTree = ""; }; A81FFC9428F1776300B0FC7C /* StadiumMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StadiumMapView.swift; sourceTree = ""; }; - A81FFC9628F1776F00B0FC7C /* SongInformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongInformationView.swift; sourceTree = ""; }; A81FFC9828F1777B00B0FC7C /* TeamSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamSelectionView.swift; sourceTree = ""; }; A81FFC9C28F180A000B0FC7C /* SongPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongPlayerView.swift; sourceTree = ""; }; A81FFC9E28F180B200B0FC7C /* SongContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongContentView.swift; sourceTree = ""; }; @@ -87,6 +86,7 @@ B2699E0F28F1CB9700267A4F /* Pretendard-Medium.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Medium.otf"; sourceTree = ""; }; EEBC269E28F1CAE800BD5B3D /* TabBarItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarItemView.swift; sourceTree = ""; }; EEBC269F28F1CAE800BD5B3D /* TabBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarView.swift; sourceTree = ""; }; + F9174B292A2B2F5F00B1CE87 /* SeasonSong.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeasonSong.swift; sourceTree = ""; }; F91BE5FA29B18AF800F7E488 /* MainTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabView.swift; sourceTree = ""; }; F91BE5FC29B18D1E00F7E488 /* MainSongListTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainSongListTabView.swift; sourceTree = ""; }; F939EBB929D58FB2005ED8CA /* StorageContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageContentView.swift; sourceTree = ""; }; @@ -203,7 +203,6 @@ A81FFC9B28F1808700B0FC7C /* SongInformation */ = { isa = PBXGroup; children = ( - A81FFC9628F1776F00B0FC7C /* SongInformationView.swift */, A81FFC9C28F180A000B0FC7C /* SongPlayerView.swift */, A81FFC9E28F180B200B0FC7C /* SongContentView.swift */, F9B3B7B629B842DD00232BB8 /* SongDetailView.swift */, @@ -268,6 +267,7 @@ F98F623029B59CE60025F50E /* TeamName.swift */, F9B3B7B429B7397600232BB8 /* MapName.swift */, A8F8BA9829C8CE5B00FCB229 /* AudioManager.swift */, + F9174B292A2B2F5F00B1CE87 /* SeasonSong.swift */, ); path = Data; sourceTree = ""; @@ -380,6 +380,7 @@ F98F622B29B4CB450025F50E /* ThemeManager.swift in Sources */, A81FFC9128F1775000B0FC7C /* SongSearchView.swift in Sources */, F9B3B7B729B842DD00232BB8 /* SongDetailView.swift in Sources */, + F9174B2A2A2B2F5F00B1CE87 /* SeasonSong.swift in Sources */, EEBC26A028F1CAE900BD5B3D /* TabBarItemView.swift in Sources */, A81FFCA728F1B84A00B0FC7C /* Halmap+Color.swift in Sources */, F98F622929B4C9BD0025F50E /* Themes.swift in Sources */, @@ -392,7 +393,6 @@ F9B95BBB28F271B800728048 /* Model.swift in Sources */, F98F623129B59CE60025F50E /* TeamName.swift in Sources */, F9B3B7B529B7397600232BB8 /* MapName.swift in Sources */, - A81FFC9728F1776F00B0FC7C /* SongInformationView.swift in Sources */, A81FFC9528F1776300B0FC7C /* StadiumMapView.swift in Sources */, F9A178262A1C8B01003E8E4C /* PlayListFilter.swift in Sources */, ); diff --git a/Halmap/Assets.xcassets/Image/2023/Nc23.imageset/Nc23.png b/Halmap/Assets.xcassets/Image/2023/Nc23.imageset/Nc23.png deleted file mode 100644 index 43f3442..0000000 Binary files a/Halmap/Assets.xcassets/Image/2023/Nc23.imageset/Nc23.png and /dev/null differ diff --git a/Halmap/Assets.xcassets/Image/Player/NcPlayer.imageset/NcPlayer.png b/Halmap/Assets.xcassets/Image/Player/NcPlayer.imageset/NcPlayer.png deleted file mode 100644 index f3e0975..0000000 Binary files a/Halmap/Assets.xcassets/Image/Player/NcPlayer.imageset/NcPlayer.png and /dev/null differ diff --git a/Halmap/Assets.xcassets/Image/Search/Contents.json b/Halmap/Assets.xcassets/Image/Search/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Halmap/Assets.xcassets/Image/Search/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Halmap/Assets.xcassets/Image/Player/NcPlayer.imageset/Contents.json b/Halmap/Assets.xcassets/Image/Search/searchEmpty.imageset/Contents.json similarity index 87% rename from Halmap/Assets.xcassets/Image/Player/NcPlayer.imageset/Contents.json rename to Halmap/Assets.xcassets/Image/Search/searchEmpty.imageset/Contents.json index 9c8ba38..d98c68d 100644 --- a/Halmap/Assets.xcassets/Image/Player/NcPlayer.imageset/Contents.json +++ b/Halmap/Assets.xcassets/Image/Search/searchEmpty.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "NCPlayer.png", + "filename" : "searchEmpty.png", "idiom" : "universal", "scale" : "1x" }, diff --git a/Halmap/Assets.xcassets/Image/Search/searchEmpty.imageset/searchEmpty.png b/Halmap/Assets.xcassets/Image/Search/searchEmpty.imageset/searchEmpty.png new file mode 100644 index 0000000..12c81b0 Binary files /dev/null and b/Halmap/Assets.xcassets/Image/Search/searchEmpty.imageset/searchEmpty.png differ diff --git a/Halmap/Assets.xcassets/Image/2023/Nc23.imageset/Contents.json b/Halmap/Assets.xcassets/Image/Search/searchInfo.imageset/Contents.json similarity index 87% rename from Halmap/Assets.xcassets/Image/2023/Nc23.imageset/Contents.json rename to Halmap/Assets.xcassets/Image/Search/searchInfo.imageset/Contents.json index 287fb9e..1d34923 100644 --- a/Halmap/Assets.xcassets/Image/2023/Nc23.imageset/Contents.json +++ b/Halmap/Assets.xcassets/Image/Search/searchInfo.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "NC23.png", + "filename" : "searchInfo.png", "idiom" : "universal", "scale" : "1x" }, diff --git a/Halmap/Assets.xcassets/Image/Search/searchInfo.imageset/searchInfo.png b/Halmap/Assets.xcassets/Image/Search/searchInfo.imageset/searchInfo.png new file mode 100644 index 0000000..0357db0 Binary files /dev/null and b/Halmap/Assets.xcassets/Image/Search/searchInfo.imageset/searchInfo.png differ diff --git "a/Halmap/Assets.xcassets/\355\214\200 \354\225\250\353\262\224 \354\273\244\353\262\204/KtAlbum.imageset/KtAlbum.png" "b/Halmap/Assets.xcassets/\355\214\200 \354\225\250\353\262\224 \354\273\244\353\262\204/KtAlbum.imageset/KtAlbum.png" index ea97460..48754cc 100644 Binary files "a/Halmap/Assets.xcassets/\355\214\200 \354\225\250\353\262\224 \354\273\244\353\262\204/KtAlbum.imageset/KtAlbum.png" and "b/Halmap/Assets.xcassets/\355\214\200 \354\225\250\353\262\224 \354\273\244\353\262\204/KtAlbum.imageset/KtAlbum.png" differ diff --git a/Halmap/Data/DataManager.swift b/Halmap/Data/DataManager.swift index e9c83fa..96467da 100644 --- a/Halmap/Data/DataManager.swift +++ b/Halmap/Data/DataManager.swift @@ -5,14 +5,15 @@ // Created by 전지민 on 2022/10/09. // -import Foundation +import SwiftUI import FirebaseFirestore class DataManager: ObservableObject { private let db = Firestore.firestore() - var selectedTeam: String = (UserDefaults.standard.string(forKey: "selectedTeam") ?? "Hanwha") + @AppStorage("selectedTeam") var selectedTeam = "Hanwha" + var teams: [Team] = [] @Published var teamSongList: [TeamSong] = [] @Published var playerList: [Player] = [] @@ -20,18 +21,29 @@ class DataManager: ObservableObject { @Published var teamSongs: [Song] = [] @Published var favoriteSongs = PersistenceController.shared.fetchFavoriteSong() + @Published var playerSongsAll = [[Song]](repeating: [], count: 10) + @Published var teamSongsAll = [[Song]](repeating: [], count: 10) + + @Published var seasonSongs = [[String]](repeating: [], count: 10) + + var teamLists = TeamName.allCases + init() { loadData() - fetchSong(team: selectedTeam, type: true) { songs in - self.playerSongs = songs.sorted { lhs, rhs in - lhs.title <= rhs.title + teamLists.forEach { teamName in + fetchSong(team: teamName.rawValue, type: true) { songs in + self.playerSongsAll[teamName.fetchTeamIndex()] = songs + self.setSongList(team: self.selectedTeam) } - } - fetchSong(team: selectedTeam, type: false) { songs in - self.teamSongs = songs.sorted { lhs, rhs in - lhs.title <= rhs.title + fetchSong(team: teamName.rawValue, type: false) { songs in + self.teamSongsAll[teamName.fetchTeamIndex()] = songs } } + + fetchSeasonData { data in + self.seasonSongs = data + } + } func loadData(){ @@ -71,12 +83,8 @@ class DataManager: ObservableObject { } func setSongList(team: String) { - fetchSong(team: team, type: true) { songs in - self.playerSongs = songs - } - fetchSong(team: team, type: false) { songs in - self.teamSongs = songs - } + self.playerSongs = playerSongsAll[TeamName(rawValue: selectedTeam)?.fetchTeamIndex() ?? 0] + self.teamSongs = teamSongsAll[TeamName(rawValue: selectedTeam)?.fetchTeamIndex() ?? 0] } //MARK: 파이어스토어에서 해당하는 팀의 응원가 정보를 가져오는 함수 @@ -87,6 +95,7 @@ class DataManager: ObservableObject { db.collection(team) .whereField("type", isEqualTo: type) + .order(by: "title", descending: false) .getDocuments { (querySnapshot, error) in if let error { print("Error getting documents: \(error)") @@ -108,4 +117,53 @@ class DataManager: ObservableObject { } } } + + func fetchSeasonData(completionHandler: @escaping ([[String]])->()) { + db.collection("SeasonSong") + .getDocuments { (querySnapshot, error) in + if let error { + print("Error getting documents: \(error)") + } else { + guard let documents = querySnapshot?.documents else { return } + let decoder = JSONDecoder() + + for document in documents { + do { + let data = document.data() + let jsonData = try JSONSerialization.data(withJSONObject: data) + let seasonSong = try decoder.decode(SeasonSong.self, from: jsonData) + + completionHandler(self.processingSeasonSongData(data: seasonSong)) + } catch let error { + print("error: \(error)") + } + } + } + } + } + + func processingSeasonSongData(data: SeasonSong) -> [[String]] { + var seasonData = [[String]](repeating: [], count: 10) + + seasonData[TeamName.doosan.fetchTeamIndex()] = splitData(data: data.doosan) + seasonData[TeamName.hanwha.fetchTeamIndex()] = splitData(data: data.hanwha) + seasonData[TeamName.samsung.fetchTeamIndex()] = splitData(data: data.samsung) + seasonData[TeamName.lotte.fetchTeamIndex()] = splitData(data: data.lotte) + seasonData[TeamName.lg.fetchTeamIndex()] = splitData(data: data.lg) + seasonData[TeamName.ssg.fetchTeamIndex()] = splitData(data: data.ssg) + seasonData[TeamName.kt.fetchTeamIndex()] = splitData(data: data.kt) + seasonData[TeamName.nc.fetchTeamIndex()] = splitData(data: data.nc) + seasonData[TeamName.kiwoom.fetchTeamIndex()] = splitData(data: data.kiwoom) + seasonData[TeamName.kia.fetchTeamIndex()] = splitData(data: data.kia) + + return seasonData + } + + func splitData(data: String) -> [String] { + return data.split(separator: ",").map{ String($0) } + } + + func checkSeasonSong(data: SongInfo) -> Bool { + self.seasonSongs[TeamName(rawValue: data.team)?.fetchTeamIndex() ?? 0].contains(data.title) + } } diff --git a/Halmap/Data/SeasonSong.swift b/Halmap/Data/SeasonSong.swift new file mode 100644 index 0000000..6286d1f --- /dev/null +++ b/Halmap/Data/SeasonSong.swift @@ -0,0 +1,22 @@ +// +// SeasonSong.swift +// Halmap +// +// Created by 전지민 on 2023/06/03. +// + +import Foundation + +struct SeasonSong: Identifiable, Codable { + var id: String + var doosan: String + var hanwha: String + var samsung: String + var lotte: String + var lg: String + var ssg: String + var kt: String + var nc: String + var kiwoom: String + var kia: String +} diff --git a/Halmap/Data/Song.swift b/Halmap/Data/Song.swift index 1083f45..ac4c7d2 100644 --- a/Halmap/Data/Song.swift +++ b/Halmap/Data/Song.swift @@ -16,3 +16,12 @@ struct Song: Identifiable, Codable { var info: String var url: String } +struct SongInfo: Identifiable, Codable { + var id: String + var team: String + var type: Bool + var title: String + var lyrics: String + var info: String + var url: String +} diff --git a/Halmap/Data/TeamName.swift b/Halmap/Data/TeamName.swift index f6ad872..a84c12b 100644 --- a/Halmap/Data/TeamName.swift +++ b/Halmap/Data/TeamName.swift @@ -43,4 +43,29 @@ enum TeamName: String, CaseIterable { return "기아 타이거즈" } } + + func fetchTeamIndex() -> Int { + switch self { + case .doosan: + return 0 + case .hanwha: + return 1 + case .samsung: + return 2 + case .lotte: + return 3 + case .lg: + return 4 + case .ssg: + return 5 + case .kt: + return 6 + case .nc: + return 7 + case .kiwoom: + return 8 + case .kia: + return 9 + } + } } diff --git a/Halmap/Persistence.swift b/Halmap/Persistence.swift index 191e216..06e31bf 100644 --- a/Halmap/Persistence.swift +++ b/Halmap/Persistence.swift @@ -29,7 +29,7 @@ struct PersistenceController { container.viewContext.automaticallyMergesChangesFromParent = true } - func saveSongs(song: Song, playListTitle: String?) { + func saveSongs(song: SongInfo, playListTitle: String?) { let context = container.viewContext let collectedSong = CollectedSong(context: context) collectedSong.id = song.id @@ -39,7 +39,7 @@ struct PersistenceController { collectedSong.url = song.url collectedSong.type = song.type collectedSong.playListTitle = playListTitle - collectedSong.team = selectedTeam + collectedSong.team = song.team collectedSong.date = Date() if context.hasChanges { diff --git a/Halmap/View/MainSongListTabView.swift b/Halmap/View/MainSongListTabView.swift index 656e089..4b8325b 100644 --- a/Halmap/View/MainSongListTabView.swift +++ b/Halmap/View/MainSongListTabView.swift @@ -9,8 +9,9 @@ import SwiftUI struct MainSongListTabView: View { - @State var selectedTeam: String = (UserDefaults.standard.string(forKey: "selectedTeam") ?? "Hanwha") - @ObservedObject var dataManager = DataManager() + @AppStorage("selectedTeam") var selectedTeam = "Hanwha" + @EnvironmentObject var dataManager: DataManager + @State private var showingTeamChaingView: Bool = false @State var index = 0 @@ -50,10 +51,17 @@ struct MainSongListTabView: View { lyrics: song.lyrics, info: song.info, url: song.url) + let songInfo = SongInfo(id: song.id, + team: selectedTeam, + type: song.type, + title: song.title, + lyrics: song.lyrics, + info: song.info, + url: song.url) - NavigationLink(destination: SongDetailView(song: music)) { + NavigationLink(destination: SongDetailView(song: music, team: selectedTeam)) { HStack(spacing: 16) { - Image("\(selectedTeam)Album") + Image(dataManager.checkSeasonSong(data: songInfo) ? "\(selectedTeam)23" : "\(selectedTeam)Album") .resizable() .frame(width: 40, height: 40) .cornerRadius(8) @@ -66,6 +74,8 @@ struct MainSongListTabView: View { .foregroundColor(.customDarkGray) } } + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) } } } @@ -84,15 +94,24 @@ struct MainSongListTabView: View { List { ForEach(dataManager.playerSongs) { song in let music = Song(id: song.id, - type: song.type, - title: song.title, - lyrics: song.lyrics, - info: song.info, - url: song.url) + type: song.type, + title: song.title, + lyrics: song.lyrics, + info: song.info, + url: song.url) + + let songInfo = SongInfo(id: song.id, + team: selectedTeam, + type: song.type, + title: song.title, + lyrics: song.lyrics, + info: song.info, + url: song.url) + - NavigationLink(destination: SongDetailView(song: music)) { + NavigationLink(destination: SongDetailView(song: music, team: selectedTeam)) { HStack(spacing: 16) { - Image("\(selectedTeam)Player") + Image(dataManager.checkSeasonSong(data: songInfo) ? "\(selectedTeam)23" : "\(selectedTeam)Player") .resizable() .frame(width: 40, height: 40) .cornerRadius(8) @@ -105,6 +124,8 @@ struct MainSongListTabView: View { .foregroundColor(.customDarkGray) } } + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) } } } diff --git a/Halmap/View/MainTabView.swift b/Halmap/View/MainTabView.swift index 4ecb7a8..9662776 100644 --- a/Halmap/View/MainTabView.swift +++ b/Halmap/View/MainTabView.swift @@ -9,7 +9,7 @@ import SwiftUI struct MainTabView: View { - @State var selectedTeam: String = (UserDefaults.standard.string(forKey: "selectedTeam") ?? "Hanwha") + @AppStorage("selectedTeam") var selectedTeam = "Hanwha" init() { Color.setColor(selectedTeam) @@ -28,11 +28,6 @@ struct MainTabView: View { Image("search") Text("곡 검색") } - StadiumListSheetView() - .tabItem { - Image("map") - Text("야구장") - } StorageContentView() .tabItem { Image("storage") diff --git a/Halmap/View/ScalingHeaderView.swift b/Halmap/View/ScalingHeaderView.swift index caa2f90..e7ba822 100644 --- a/Halmap/View/ScalingHeaderView.swift +++ b/Halmap/View/ScalingHeaderView.swift @@ -8,7 +8,7 @@ import SwiftUI struct ScalingHeaderView: View { - + @EnvironmentObject var dataManager: DataManager let maxHeight: CGFloat = 216 var topEdge: CGFloat @@ -64,12 +64,22 @@ struct ScalingHeaderView: View { info: favoriteSong.info ?? "", url: favoriteSong.url ?? "" ) + let songInfo = SongInfo( + id: favoriteSong.id ?? "", + team: favoriteSong.team ?? "", + type: favoriteSong.type , + title: favoriteSong.title ?? "" , + lyrics: favoriteSong.lyrics ?? "", + info: favoriteSong.info ?? "", + url: favoriteSong.url ?? "" + ) + VStack(spacing: 0) { NavigationLink { - SongDetailView(teamName: favoriteSong.team, song: song) + SongDetailView(song: song, team: favoriteSong.team ?? "Doosan") } label: { HStack(spacing: 16) { - Image("\(favoriteSong.team ?? "NC")\(favoriteSong.type ? "Player" : "Album")") + Image(dataManager.checkSeasonSong(data: songInfo) ? "\(favoriteSong.team ?? "")23" : "\( favoriteSong.team ?? "NC")\(favoriteSong.type ? "Player" : "Album")") .resizable() .frame(width: 40, height: 40) .cornerRadius(8) @@ -81,7 +91,9 @@ struct ScalingHeaderView: View { .font(Font.Halmap.CustomCaptionMedium) .foregroundColor(.customDarkGray) } - Spacer() + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) + Button { persistence.deleteSongs(song: favoriteSong) } label: { diff --git a/Halmap/View/SongInformation/SongContentView.swift b/Halmap/View/SongInformation/SongContentView.swift index e5f0603..23f5ca0 100644 --- a/Halmap/View/SongInformation/SongContentView.swift +++ b/Halmap/View/SongInformation/SongContentView.swift @@ -11,6 +11,7 @@ import Firebase struct SongContentView: View { @Binding var song: Song + @Binding var team: String @Binding var isScrolled: Bool @State private var offset = CGFloat.zero diff --git a/Halmap/View/SongInformation/SongDetailView.swift b/Halmap/View/SongInformation/SongDetailView.swift index 768adc9..4b822a8 100644 --- a/Halmap/View/SongInformation/SongDetailView.swift +++ b/Halmap/View/SongInformation/SongDetailView.swift @@ -12,9 +12,10 @@ struct SongDetailView: View { @Environment(\.managedObjectContext) private var viewContext @AppStorage("selectedTeam") var selectedTeam = "Hanwha" - @State var teamName: String? @State var song: Song + @State var team: String + @State var isScrolled = false @State var isFavorite = false @@ -26,31 +27,31 @@ struct SongDetailView: View { var body: some View { ZStack { - Color("\(teamName ?? selectedTeam)Sub") + Color("\(team)Sub") .ignoresSafeArea() - SongContentView(song: $song, isScrolled: $isScrolled) + SongContentView(song: $song, team: $team, isScrolled: $isScrolled) VStack(spacing: 0) { Rectangle() .frame(height: UIScreen.getHeight(108)) - .foregroundColor(Color("\(teamName ?? selectedTeam)Sub")) + .foregroundColor(Color("\(team)Sub")) if isScrolled { Rectangle() .frame(height: 120) - .background(Color.fetchTopGradient(color: Color("\(teamName ?? selectedTeam)Sub"))) + .background(Color.fetchTopGradient(color: Color("\(team)Sub"))) .foregroundColor(Color(UIColor.clear)) } Spacer() Rectangle() .frame(height: 120) - .background(Color.fetchBottomGradient(color: Color("\(teamName ?? selectedTeam)Sub"))) + .background(Color.fetchBottomGradient(color: Color("\(team)Sub"))) .foregroundColor(Color(UIColor.clear)) ZStack(alignment: .center) { Rectangle() .frame(height: UIScreen.getHeight(120)) - .foregroundColor(Color("\(teamName ?? selectedTeam)Sub")) - SongPlayerView(teamName: $teamName, song: $song) + .foregroundColor(Color("\(team)Sub")) + SongPlayerView(song: $song, team: $team) } } .ignoresSafeArea() @@ -63,13 +64,14 @@ struct SongDetailView: View { if isFavorite { persistence.deleteSongs(song: findFavoriteSong()) } else { - persistence.saveSongs(song: song, playListTitle: "favorite") + let songInfo = SongInfo(id: song.id, team: team, type: song.type, title: song.title, lyrics: song.lyrics, info: song.info, url: song.url) + persistence.saveSongs(song: songInfo, playListTitle: "favorite") } isFavorite.toggle() } label: { if isFavorite { Image(systemName: "heart.fill") - .foregroundColor(Color("\(teamName ?? selectedTeam)Point")) + .foregroundColor(Color("\(team)Point")) } else { Image(systemName: "heart") .foregroundColor(.white) diff --git a/Halmap/View/SongInformation/SongInformationView.swift b/Halmap/View/SongInformation/SongInformationView.swift deleted file mode 100644 index a6b89e8..0000000 --- a/Halmap/View/SongInformation/SongInformationView.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// SongInformationView.swift -// Halmap -// -// Created by Yeni Hwang on 2022/10/08. -// - -import SwiftUI - -struct SongInformationView: View { - - @State var song: Song - - var body: some View { - - VStack(alignment: .leading, spacing: 0) { -// SongPlayerView(song: $song) - -// SongContentView(song: $song) -// .background(.white) - - Spacer() - } - .ignoresSafeArea() - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - Text(song.title) - .font(Font.Halmap.CustomTitleBold) - .foregroundColor(.white) - .padding(.leading, -10) - } - } - - } -} - diff --git a/Halmap/View/SongInformation/SongPlayerView.swift b/Halmap/View/SongInformation/SongPlayerView.swift index dc929c4..629129e 100644 --- a/Halmap/View/SongInformation/SongPlayerView.swift +++ b/Halmap/View/SongInformation/SongPlayerView.swift @@ -12,9 +12,9 @@ import Combine struct SongPlayerView: View { // Song Properties - @State var selectedTeam: String = (UserDefaults.standard.string(forKey: "selectedTeam") ?? "test") - @Binding var teamName: String? + @AppStorage("selectedTeam") var selectedTeam = "Hanwha" @Binding var song: Song + @Binding var team: String // Audio Properties @@ -84,12 +84,12 @@ struct SongPlayerView: View { } .frame(maxWidth: .infinity) - .background(Color("\(teamName ?? selectedTeam)Sub")) + .background(Color("\(team)Sub")) .onDisappear(){ audioManager.removePlayer() } .onAppear(){ - audioManager.AMset(song: song, selectedTeam: selectedTeam) + audioManager.AMset(song: song, selectedTeam: team) } .onReceive(timer) { _ in guard let player = AudioManager.instance.player else { return } diff --git a/Halmap/View/SongSearchView.swift b/Halmap/View/SongSearchView.swift index c5178c8..e981bec 100644 --- a/Halmap/View/SongSearchView.swift +++ b/Halmap/View/SongSearchView.swift @@ -9,17 +9,17 @@ import SwiftUI struct SongSearchView: View { - @State var selectedTeam: String = (UserDefaults.standard.string(forKey: "selectedTeam") ?? "Hanwha") + @AppStorage("selectedTeam") var selectedTeam = "Hanwha" @Environment(\.presentationMode) var mode: Binding - @ObservedObject var dataManager = DataManager() + @EnvironmentObject var dataManager: DataManager @GestureState private var dragOffset = CGSize.zero @FocusState private var isFocused: Bool @State private var isKeyboardFocused = false @State private var searchText = "" - @State private var autoComplete = [Song]() + @State private var autoComplete = [SongInfo]() var body: some View { @@ -91,30 +91,52 @@ struct SongSearchView: View { VStack(spacing: 0) { if searchText.isEmpty { VStack(spacing: 0) { - Text("선수 이름, 응원가를 검색해주세요") - .foregroundColor(Color.customDarkGray) - .padding(30) + Image("searchInfo") + .resizable() + .scaledToFit() + .frame(width: UIScreen.getHeight(200)) + .padding(.top, UIScreen.getHeight(60)) + Spacer() } .frame(maxWidth: .infinity) } else { if autoComplete.isEmpty { - VStack(spacing: 0) { - Text("검색 결과가 없어요") - .foregroundColor(Color.customDarkGray) - .padding(30) - Spacer() - RequestSongView(buttonColor: Color.mainGreen) + ZStack { + VStack(spacing: 0) { + Image("searchEmpty") + .resizable() + .scaledToFit() + .frame(width: UIScreen.getHeight(200)) + .padding(.top, UIScreen.getHeight(60)) + Spacer() + } + VStack { + Spacer() + RequestSongView(buttonColor: Color.mainGreen) + } } .frame(maxWidth: .infinity) } else { List { ForEach(autoComplete.indices, id: \.self) { index in - NavigationLink(destination: SongDetailView(song: autoComplete[index])) { + NavigationLink(destination: SongDetailView(song: setSong(data: autoComplete[index]), team: autoComplete[index].team)) { HStack { - Image(systemName: "magnifyingglass") - Text(autoComplete[index].title) + Image(dataManager.checkSeasonSong(data: autoComplete[index]) ? "\(autoComplete[index].team)23" : (autoComplete[index].type ? "\(autoComplete[index].team)Player" : "\(autoComplete[index].team)Album")) + .resizable() + .frame(width: 40, height: 40) + .cornerRadius(8) + VStack(alignment: .leading, spacing: 8) { + Text(autoComplete[index].title ) + .font(Font.Halmap.CustomBodyMedium) + .foregroundColor(.black) + Text("\(TeamName(rawValue: autoComplete[index].team)?.fetchTeamNameKr() ?? "두산 베어스")") + .font(Font.Halmap.CustomCaptionMedium) + .foregroundColor(.customDarkGray) + } + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) } .font(Font.Halmap.CustomBodyMedium) .foregroundColor(Color.black) @@ -154,20 +176,24 @@ struct SongSearchView: View { autoComplete = [] - for data in dataManager.playerSongs { - if data.title.contains(searchText.lowercased()) { - let music = Song(id: data.id, type: data.type, title: data.title, lyrics: data.lyrics, info: data.info, url: data.url) - autoComplete.append(music) + dataManager.teamLists.forEach { teamName in + for data in dataManager.playerSongsAll[teamName.fetchTeamIndex()] { + if data.title.lowercased().contains(searchText.lowercased()) { + let music = SongInfo(id: data.id,team: teamName.rawValue, type: data.type, title: data.title, lyrics: data.lyrics, info: data.info, url: data.url) + autoComplete.append(music) + } } - } - - for data in dataManager.teamSongs { - if data.title.contains(searchText.lowercased()) { - let music = Song(id: data.id, type: data.type, title: data.title, lyrics: data.lyrics, info: data.info, url: data.url) - autoComplete.append(music) + for data in dataManager.teamSongsAll[teamName.fetchTeamIndex()] { + if data.title.lowercased().contains(searchText.lowercased()) { + let music = SongInfo(id: data.id,team: teamName.rawValue, type: data.type, title: data.title, lyrics: data.lyrics, info: data.info, url: data.url) + autoComplete.append(music) + } } } } + private func setSong(data: SongInfo) -> Song { + Song(id: data.id, type: data.type, title: data.title, lyrics: data.lyrics, info: data.info, url: data.url) + } } diff --git a/Halmap/View/TeamSelectionView.swift b/Halmap/View/TeamSelectionView.swift index 2d1b372..78fd536 100644 --- a/Halmap/View/TeamSelectionView.swift +++ b/Halmap/View/TeamSelectionView.swift @@ -27,6 +27,7 @@ struct OnBoardingStartView: View { } struct TeamSelectionView: View { + @EnvironmentObject var dataManager: DataManager @AppStorage("selectedTeam") var finalSelectedTeam: String = "" @Binding var isFirstLaunching: Bool @@ -72,6 +73,7 @@ struct TeamSelectionView: View { UserDefaults.standard.set(selectedTeam, forKey: "selectedTeam") withAnimation { isFirstLaunching.toggle() + dataManager.setSongList(team: finalSelectedTeam) finalSelectedTeam = selectedTeam ?? "error" } print("선택완료")