diff --git a/NeflixCloneCoding/NeflixCloneCoding.xcodeproj/project.pbxproj b/NeflixCloneCoding/NeflixCloneCoding.xcodeproj/project.pbxproj index 2d4389a..87817af 100644 --- a/NeflixCloneCoding/NeflixCloneCoding.xcodeproj/project.pbxproj +++ b/NeflixCloneCoding/NeflixCloneCoding.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 7821D5EC287EEAB200ACDF65 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7821D5EB287EEAB200ACDF65 /* ViewModel.swift */; }; + 7821D691287EFF6500ACDF65 /* MovieData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7821D690287EFF6500ACDF65 /* MovieData.swift */; }; + 7821D693287F005C00ACDF65 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7821D692287F005C00ACDF65 /* Data.swift */; }; + 7821D695287F00FA00ACDF65 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7821D694287F00FA00ACDF65 /* Result.swift */; }; 78268A9A287016BB0099F75C /* NeflixCloneCodingApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78268A99287016BB0099F75C /* NeflixCloneCodingApp.swift */; }; 78268A9C287016BB0099F75C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78268A9B287016BB0099F75C /* ContentView.swift */; }; 78268A9E287016BC0099F75C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78268A9D287016BC0099F75C /* Assets.xcassets */; }; @@ -23,6 +27,10 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 7821D5EB287EEAB200ACDF65 /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = ""; }; + 7821D690287EFF6500ACDF65 /* MovieData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieData.swift; sourceTree = ""; }; + 7821D692287F005C00ACDF65 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 7821D694287F00FA00ACDF65 /* Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; 78268A96287016BB0099F75C /* NeflixCloneCoding.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NeflixCloneCoding.app; sourceTree = BUILT_PRODUCTS_DIR; }; 78268A99287016BB0099F75C /* NeflixCloneCodingApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeflixCloneCodingApp.swift; sourceTree = ""; }; 78268A9B287016BB0099F75C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -51,6 +59,24 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 7821D5EA287EEAA300ACDF65 /* ViewModel */ = { + isa = PBXGroup; + children = ( + 7821D5EB287EEAB200ACDF65 /* ViewModel.swift */, + ); + path = ViewModel; + sourceTree = ""; + }; + 7821D5ED287EF1A500ACDF65 /* Models */ = { + isa = PBXGroup; + children = ( + 7821D690287EFF6500ACDF65 /* MovieData.swift */, + 7821D692287F005C00ACDF65 /* Data.swift */, + 7821D694287F00FA00ACDF65 /* Result.swift */, + ); + path = Models; + sourceTree = ""; + }; 78268A8D287016BB0099F75C = { isa = PBXGroup; children = ( @@ -70,6 +96,8 @@ 78268A98287016BB0099F75C /* NeflixCloneCoding */ = { isa = PBXGroup; children = ( + 7821D5ED287EF1A500ACDF65 /* Models */, + 7821D5EA287EEAA300ACDF65 /* ViewModel */, 78AF38AD287A9EA600BA81D4 /* Info.plist */, 78AF38AB287A9E7400BA81D4 /* fonts */, 7862CCDB2875B0DA00FE3545 /* Main */, @@ -199,13 +227,17 @@ buildActionMask = 2147483647; files = ( 78268A9C287016BB0099F75C /* ContentView.swift in Sources */, + 7821D5EC287EEAB200ACDF65 /* ViewModel.swift in Sources */, 78AF38B5287AB2D600BA81D4 /* RowMovieList.swift in Sources */, 78AF38AA287A9BA700BA81D4 /* MainPoster.swift in Sources */, + 7821D693287F005C00ACDF65 /* Data.swift in Sources */, B919C98C287EB44D00EB9D42 /* Color.swift in Sources */, B919C987287DF5AA00EB9D42 /* ContentDetailView.swift in Sources */, + 7821D695287F00FA00ACDF65 /* Result.swift in Sources */, 78268A9A287016BB0099F75C /* NeflixCloneCodingApp.swift in Sources */, 78AF38A328770BE700BA81D4 /* TopContent.swift in Sources */, 78AF38A72878798600BA81D4 /* CategoryselectionView.swift in Sources */, + 7821D691287EFF6500ACDF65 /* MovieData.swift in Sources */, 78AF389F2877033E00BA81D4 /* NetflixMain.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/NeflixCloneCoding/NeflixCloneCoding/Info.plist b/NeflixCloneCoding/NeflixCloneCoding/Info.plist index fcc0414..6ef129d 100644 --- a/NeflixCloneCoding/NeflixCloneCoding/Info.plist +++ b/NeflixCloneCoding/NeflixCloneCoding/Info.plist @@ -2,6 +2,11 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + UIAppFonts BebasNeue.otf diff --git a/NeflixCloneCoding/NeflixCloneCoding/Main/MainPoster.swift b/NeflixCloneCoding/NeflixCloneCoding/Main/MainPoster.swift index 83e1a52..d3bfd3e 100644 --- a/NeflixCloneCoding/NeflixCloneCoding/Main/MainPoster.swift +++ b/NeflixCloneCoding/NeflixCloneCoding/Main/MainPoster.swift @@ -8,29 +8,33 @@ import SwiftUI struct MainPoster: View { + @EnvironmentObject var viewModel: ViewModel var posterName : String var movieName : String + var toystory2 = "http://file.koreafilm.or.kr/thm/02/00/01/61/tn_DPF002688.JPG" var body: some View { ZStack{ - NavigationLink { - ContentDetailView() - .navigationBarTitleDisplayMode(.inline) //this must be empty - } label: { - Image(posterName) - .resizable() - .scaledToFill() + AsyncImage(url: URL(string: viewModel.mainPosterImageUrl)) { image in + image.resizable() + } placeholder: { + Color.gray + } .frame(width: UIScreen.main.bounds.width , height: UIScreen.main.bounds.height * 0.5, alignment: .center) - } + } .mask(LinearGradient(gradient: Gradient(colors: [.clear, .black, .black, .black,.clear]), startPoint: .top, endPoint: .bottom)) - + .onAppear(){ + viewModel.getmoviePoster() + } } + + } struct MainPoster_Previews: PreviewProvider { diff --git a/NeflixCloneCoding/NeflixCloneCoding/Main/NetflixMain.swift b/NeflixCloneCoding/NeflixCloneCoding/Main/NetflixMain.swift index 1091fc5..4484490 100644 --- a/NeflixCloneCoding/NeflixCloneCoding/Main/NetflixMain.swift +++ b/NeflixCloneCoding/NeflixCloneCoding/Main/NetflixMain.swift @@ -8,7 +8,11 @@ import SwiftUI struct NetflixMain: View { + @EnvironmentObject var viewModel: ViewModel @State var iscategoryClicked = false + + @State private var showingSheet = false + var categoryList = ["미국 블록버스터 영화","심리 게임 영화","실화 바탕 영화","인디 영화","오늘 대한민국의 Top 10 영화","호러 영화"] init(){ UITabBar.appearance().barTintColor = .black @@ -16,7 +20,6 @@ struct NetflixMain: View { } var body: some View { ZStack{ - NavigationView{ TabView{ ZStack{ Color.black @@ -24,8 +27,12 @@ struct NetflixMain: View { ZStack{ //main Poster 이미지 들어가는 부분 VStack{ - MainPoster(posterName: "MainTitle",movieName: "Toy Story3") - .padding(.bottom,80) + Button{ + self.showingSheet.toggle() + }label: { + MainPoster(posterName: "MainTitle",movieName: "Toy Story2") + .padding(.bottom,80) + } ForEach(categoryList,id:\.self){category in RowMovieList(categoryName: category) } @@ -36,10 +43,15 @@ struct NetflixMain: View { //상단 탭바 TopContent(iscategoryClicked: $iscategoryClicked) //영화 제목 - Text("Toy Story3") - .font(.custom("BebasNeue", size: 80)) - .foregroundColor(.white) - .padding(.top,UIScreen.main.bounds.height * 0.2) + + + + Text("Toy Story2") + .font(.custom("BebasNeue", size: 80)) + .foregroundColor(.white) + .padding(.top,UIScreen.main.bounds.height * 0.2) + + // 영화 카테고리 HStack{ Text("Friendship *") @@ -95,6 +107,10 @@ struct NetflixMain: View { } } + .sheet(isPresented: $showingSheet) { + //sheet에 표시될 뷰를 할당 + ContentDetailView() + } } .ignoresSafeArea() @@ -119,7 +135,7 @@ struct NetflixMain: View { } } .accentColor(.white) - } + if iscategoryClicked{ CategoryselectionView(iscategoryClicked: $iscategoryClicked) } diff --git a/NeflixCloneCoding/NeflixCloneCoding/Models/Data.swift b/NeflixCloneCoding/NeflixCloneCoding/Models/Data.swift new file mode 100644 index 0000000..c43abef --- /dev/null +++ b/NeflixCloneCoding/NeflixCloneCoding/Models/Data.swift @@ -0,0 +1,15 @@ +// +// Data.swift +// NeflixCloneCoding +// +// Created by dohankim on 2022/07/13. +// + +import Foundation + +struct Data : Codable{ + var CollName : String? + var TotalCount : Int? + var Count : Int? + var Result : [Result]? +} diff --git a/NeflixCloneCoding/NeflixCloneCoding/Models/MovieData.swift b/NeflixCloneCoding/NeflixCloneCoding/Models/MovieData.swift new file mode 100644 index 0000000..ee4d87f --- /dev/null +++ b/NeflixCloneCoding/NeflixCloneCoding/Models/MovieData.swift @@ -0,0 +1,15 @@ +// +// MovieData.swift +// NeflixCloneCoding +// +// Created by dohankim on 2022/07/13. +// + +import Foundation + +struct MovieData : Codable{ + var Query : String? + var KMAQuery : String? + var TotalCount : Int? + var Data : [Data]? = [] +} diff --git a/NeflixCloneCoding/NeflixCloneCoding/Models/Result.swift b/NeflixCloneCoding/NeflixCloneCoding/Models/Result.swift new file mode 100644 index 0000000..f1bd529 --- /dev/null +++ b/NeflixCloneCoding/NeflixCloneCoding/Models/Result.swift @@ -0,0 +1,55 @@ +// +// Result.swift +// NeflixCloneCoding +// +// Created by dohankim on 2022/07/13. +// + +import Foundation + +struct Result :Codable{ + var DOCID : String? = nil + var movieId : String? = nil + var movieSeq : String? = nil + var title : String? = nil + var titleEng : String? = nil + var titleOrg : String? = nil + var titleEtc : String? = nil + var prodYear : String? = nil + + var nation : String? = nil + var company : String? = nil + + var runtime : String? = nil + var rating : String? = nil + var genre : String? = nil + var kmdbUrl : String? = nil + var type : String? = nil + var use : String? = nil + var episodes : String? = nil + var ratedYn : String? = nil + var repRatDate : String? = nil + var repRlsDate : String? = nil + + var keywords : String? = nil + var posters : String? = nil + var stlls : String? = nil + + var openThtr : String? = nil + + var screenArea : String? = nil + var screenCnt : String? = nil + var salesAcc : String? = nil + var audiAcc : String? = nil + var statSouce : String? = nil + var statDate : String? = nil + var themeSong : String? = nil + var soundtrack : String? = nil + var fLocation : String? = nil + var Awards1 : String? = nil + var Awards2 : String? = nil + var regDate : String? = nil + var modDate : String? = nil + + var ALIAS : String? = nil +} diff --git a/NeflixCloneCoding/NeflixCloneCoding/NeflixCloneCodingApp.swift b/NeflixCloneCoding/NeflixCloneCoding/NeflixCloneCodingApp.swift index 8828946..f857f8d 100644 --- a/NeflixCloneCoding/NeflixCloneCoding/NeflixCloneCodingApp.swift +++ b/NeflixCloneCoding/NeflixCloneCoding/NeflixCloneCodingApp.swift @@ -12,6 +12,7 @@ struct NeflixCloneCodingApp: App { var body: some Scene { WindowGroup { ContentView() + .environmentObject(ViewModel()) } } } diff --git a/NeflixCloneCoding/NeflixCloneCoding/ViewModel/ViewModel.swift b/NeflixCloneCoding/NeflixCloneCoding/ViewModel/ViewModel.swift new file mode 100644 index 0000000..339a2e2 --- /dev/null +++ b/NeflixCloneCoding/NeflixCloneCoding/ViewModel/ViewModel.swift @@ -0,0 +1,55 @@ +// +// ViewModel.swift +// NeflixCloneCoding +// +// Created by dohankim on 2022/07/13. +// + +import SwiftUI +import Combine +class ViewModel : ObservableObject{ + //스트링키 추가 + //var stringKey = + @Published var mainPosterImageUrl = "" + @Published var imageurlArr : [String] = [] + + func loadData(completionHandler: @escaping (_ data:String)->Void) { + var urlString = "http://api.koreafilm.or.kr/openapi-data2/wisenut/search_api/search_json2.jsp?collection=kmdb_new2&detail=Y&title=토이스토리2&ServiceKey="+stringKey + + let encodedString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + guard let url = URL(string: encodedString ) else { + print(encodedString) + fatalError("Invalid URL") + } + + URLSession.shared.dataTask(with: url) { data, response, error in + guard let data = data, error == nil else { + print("error") + return + } + let result = try? JSONDecoder().decode(MovieData.self, from: data) + if let result = result { + + result.Data?.forEach { + self.imageurlArr = ($0.Result?[0].posters?.components(separatedBy : "|"))! + print($0.Result?[0].posters) + print($0.TotalCount) + } + completionHandler(self.imageurlArr[1]) + print(self.imageurlArr[0]) + } + + + }.resume() + + } + + func getmoviePoster(){ + loadData { [weak self] data in + self?.mainPosterImageUrl = data + } + } +} + + +