From 3988024a9d3f521bae451af1fd18f2cad8e00c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daegun=20Choi=20=EF=A3=BF?= Date: Sun, 27 Aug 2023 22:37:19 +0900 Subject: [PATCH 1/2] Revert "Refactor/#16 caching" --- MovieApp/MovieApp.xcodeproj/project.pbxproj | 24 ----- .../MovieApp/Domain/Service/APIService.swift | 12 +-- .../MovieApp/Domain/Utils/Cache/Cache.swift | 98 ------------------- .../Utils/Cache/ImageCacheManager.swift | 73 -------------- .../ChartView/View/ChartTableViewCell.swift | 19 ++-- .../View/DetailViewController.swift | 9 +- .../View/DiscoverCollectionViewCell.swift | 27 +++-- .../Presentation/MainTabBarController.swift | 2 + 8 files changed, 42 insertions(+), 222 deletions(-) delete mode 100644 MovieApp/MovieApp/Domain/Utils/Cache/Cache.swift delete mode 100644 MovieApp/MovieApp/Domain/Utils/Cache/ImageCacheManager.swift diff --git a/MovieApp/MovieApp.xcodeproj/project.pbxproj b/MovieApp/MovieApp.xcodeproj/project.pbxproj index 1194550..ee3dd71 100644 --- a/MovieApp/MovieApp.xcodeproj/project.pbxproj +++ b/MovieApp/MovieApp.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 7D0408B72A94815200402458 /* Cache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0408B62A94815200402458 /* Cache.swift */; }; 7D15F0D727D6F0AE0029C40F /* CreditTableViewDescriptionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D15F0D627D6F0AE0029C40F /* CreditTableViewDescriptionCell.swift */; }; 7D15F0DA27D726E50029C40F /* CreditFootherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D15F0D927D726E50029C40F /* CreditFootherView.swift */; }; 7D1979E827BE0C9A00CD3DB9 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D1979E727BE0C9A00CD3DB9 /* Extensions.swift */; }; @@ -25,7 +24,6 @@ 7D40A07F27BCC33D002C21FE /* IconLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D40A07E27BCC33D002C21FE /* IconLabel.swift */; }; 7D40A08127BCC91E002C21FE /* DescriptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D40A08027BCC91E002C21FE /* DescriptionView.swift */; }; 7D40A08327BCD362002C21FE /* DoubleColumDescriptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D40A08227BCD362002C21FE /* DoubleColumDescriptionView.swift */; }; - 7D7A7D3A2A7E744100E7879A /* ImageCacheManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D7A7D392A7E744100E7879A /* ImageCacheManager.swift */; }; 7D8740F527841F5600E92C72 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D8740F427841F5600E92C72 /* Constant.swift */; }; 7D88534027BA1E7500CC915E /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D88533F27BA1E7500CC915E /* DetailViewController.swift */; }; 7D88534327BA371D00CC915E /* DetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D88534227BA371D00CC915E /* DetailViewModel.swift */; }; @@ -46,7 +44,6 @@ /* Begin PBXFileReference section */ 1333EC5F83FAB13E0CD0D899 /* Pods_MovieApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MovieApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4940141FE31A8FDE1F3A884C /* Pods-MovieApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MovieApp.debug.xcconfig"; path = "Target Support Files/Pods-MovieApp/Pods-MovieApp.debug.xcconfig"; sourceTree = ""; }; - 7D0408B62A94815200402458 /* Cache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cache.swift; sourceTree = ""; }; 7D15F0D627D6F0AE0029C40F /* CreditTableViewDescriptionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreditTableViewDescriptionCell.swift; sourceTree = ""; }; 7D15F0D927D726E50029C40F /* CreditFootherView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreditFootherView.swift; sourceTree = ""; }; 7D1979E727BE0C9A00CD3DB9 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; @@ -66,7 +63,6 @@ 7D40A07E27BCC33D002C21FE /* IconLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconLabel.swift; sourceTree = ""; }; 7D40A08027BCC91E002C21FE /* DescriptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DescriptionView.swift; sourceTree = ""; }; 7D40A08227BCD362002C21FE /* DoubleColumDescriptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubleColumDescriptionView.swift; sourceTree = ""; }; - 7D7A7D392A7E744100E7879A /* ImageCacheManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCacheManager.swift; sourceTree = ""; }; 7D8740F427841F5600E92C72 /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; 7D88533F27BA1E7500CC915E /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = ""; }; 7D88534227BA371D00CC915E /* DetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewModel.swift; sourceTree = ""; }; @@ -141,15 +137,6 @@ path = MovieApp; sourceTree = ""; }; - 7D1D5DE62A8FB0500007E953 /* Cache */ = { - isa = PBXGroup; - children = ( - 7D7A7D392A7E744100E7879A /* ImageCacheManager.swift */, - 7D0408B62A94815200402458 /* Cache.swift */, - ); - path = Cache; - sourceTree = ""; - }; 7D2DD61F278537A7000EBDE0 /* DiscoverView */ = { isa = PBXGroup; children = ( @@ -163,7 +150,6 @@ 7D37ADA5278D5D3D004BBFF9 /* Domain */ = { isa = PBXGroup; children = ( - 7D7A7D362A7E731B00E7879A /* Utils */, 7D37ADA7278D5D50004BBFF9 /* Model */, 7D37ADA6278D5D48004BBFF9 /* Service */, ); @@ -199,14 +185,6 @@ path = CustomView; sourceTree = ""; }; - 7D7A7D362A7E731B00E7879A /* Utils */ = { - isa = PBXGroup; - children = ( - 7D1D5DE62A8FB0500007E953 /* Cache */, - ); - path = Utils; - sourceTree = ""; - }; 7D88533E27BA1E5200CC915E /* DetailView */ = { isa = PBXGroup; children = ( @@ -433,9 +411,7 @@ 7D40A07F27BCC33D002C21FE /* IconLabel.swift in Sources */, 7D88534027BA1E7500CC915E /* DetailViewController.swift in Sources */, 7DDE9C302787E0C700938996 /* ChartViewController.swift in Sources */, - 7D0408B72A94815200402458 /* Cache.swift in Sources */, 7D9D9F4A278E928C0098FEA3 /* MovieFront.swift in Sources */, - 7D7A7D3A2A7E744100E7879A /* ImageCacheManager.swift in Sources */, 7D947CA9278C03E00031C7C9 /* CreditViewController.swift in Sources */, 7DE8154327910DDC00726799 /* Keys.swift in Sources */, 7D90EC1B27D5EC160099B485 /* CreditHeaderView.swift in Sources */, diff --git a/MovieApp/MovieApp/Domain/Service/APIService.swift b/MovieApp/MovieApp/Domain/Service/APIService.swift index 5391db2..81b355e 100644 --- a/MovieApp/MovieApp/Domain/Service/APIService.swift +++ b/MovieApp/MovieApp/Domain/Service/APIService.swift @@ -18,7 +18,7 @@ class APIService { return "https://api.themoviedb.org/3/movie/\(id)?api_key=\(APIKey)&language=\(language)" } - static func configureUrlString(imagePath: String) -> String { + static func configureUrlString(imagePath: String) -> String{ return "https://image.tmdb.org/t/p/original/\(imagePath)" } @@ -29,26 +29,20 @@ class APIService { static func fetchRequest(url: String, retries: Int, onComplete: @escaping (Result) -> Void) { - guard let Url = URL(string: url) else { - print("Error: invalid url") - return - } + guard let Url = URL(string: url) else { return } let task = URLSession(configuration: .default).dataTask(with: Url) { (data, response, error) in if let error = error { - print("Error: \(error.localizedDescription)") onComplete(.failure(error)) return } guard let safeData = data else { - guard let httpResponse = response as? HTTPURLResponse else { return } - print("Error: no data") + let httpResponse = response as! HTTPURLResponse onComplete(.failure(NSError(domain: "no data", code: httpResponse.statusCode, userInfo: nil))) return } onComplete(.success(safeData)) - } task.resume() } diff --git a/MovieApp/MovieApp/Domain/Utils/Cache/Cache.swift b/MovieApp/MovieApp/Domain/Utils/Cache/Cache.swift deleted file mode 100644 index f5cec69..0000000 --- a/MovieApp/MovieApp/Domain/Utils/Cache/Cache.swift +++ /dev/null @@ -1,98 +0,0 @@ -// -// Cache.swift -// MovieApp -// -// Created by Daegeon Choi on 2023/08/22. -// - -import Foundation - -/// class for caching -final class Cache { - - /// Cache data Stored in this NSCache property - private let data = NSCache() - - // MARK: interface methods - - /** - insert new cache data - - Parameters: - - value: data to insert - - forKey: key of data - */ - func insertValue(_ value: Value, forKey key: Key) { - let entry = Entry(value) - data.setObject(entry, forKey: WrappedKey(key)) - print("\(String(describing: Value.self)) data Cached for key: \(key)") - } - - /** - get cached data fot key - - Parameter forKey: key of cached data - - Returns: Return data for key. Returns nil when there's no matching data for key - */ - func value(forKey key: Key) -> Value? { - let entry = data.object(forKey: WrappedKey(key)) - print("Get cached data type: \(String(describing: Value.self))\n value: \(entry?.value)") - return entry?.value - } - - /** - remove cached data fot key - - Parameter forKey: key of cached data to remove - */ - func removeValue(forKey key: Key) { - data.removeObject(forKey: WrappedKey(key)) - print("\(String(describing: Value.self)) data removed for key: \(key)") - } -} - -// MARK: Custom Classes for NSCache -private extension Cache { - - /// Class to wrap public facing key for NSCache - final class WrappedKey: NSObject { - - let key: Key - - init(_ key: Key) { - self.key = key - } - - override var hash: Int { - return key.hashValue - } - - override func isEqual(_ object: Any?) -> Bool { - guard let value = object as? WrappedKey else { return false } - return value.key == key - } - } - - /// Class for NSCache value - final class Entry { - let value: Value - - init(_ value: Value) { - self.value = value - } - } -} - -extension Cache { - subscript(key: Key) -> Value? { - get { - return value(forKey: key) - } - - set { - if let value = newValue { - insertValue(value, forKey: key) - } else { - // remove cached data when nil assigned - removeValue(forKey: key) - } - } - } -} diff --git a/MovieApp/MovieApp/Domain/Utils/Cache/ImageCacheManager.swift b/MovieApp/MovieApp/Domain/Utils/Cache/ImageCacheManager.swift deleted file mode 100644 index 6db6d40..0000000 --- a/MovieApp/MovieApp/Domain/Utils/Cache/ImageCacheManager.swift +++ /dev/null @@ -1,73 +0,0 @@ -// -// ImageCacheManager.swift -// MovieApp -// -// Created by Daegeon Choi on 2023/08/05. -// - -import UIKit - -/// Singleton for Image Caching -class ImageCacheManager { - - /// Storage to save cached UIImage - private let cache = Cache() - - /// singleton instance - static let shared = ImageCacheManager() - - /** - Get image from cache data for url String - - Parameter key: String url of UIImage - - Returns: Retrun cached image for url. Retrun nil when cached image is not exist - */ - func loadCachedData(for key: String) -> UIImage? { - let itemURL = NSString(string: key) - return cache.value(forKey: key) - } - - /** - Save UIImage to cache data - - Parameters: - - image: UIImage to save in cache data - - key: String url of UIImage - */ - func saveCacheData(of image: UIImage, for key: String) { - let itemURL = NSString(string: key) - cache.insertValue(image, forKey: key) - } -} - -extension UIImageView { - - /** - Set image to UIImageView with Cached Image data or data from URL - - Parameters: - - urlString: String url of image - - forceOption: Skip getting image from cache data and force to get image from url when true. default false - */ - func setImage(_ urlString: String?, forceOption: Bool = false) { - - DispatchQueue.global().async { - guard let imagePath = urlString else { return } - - // Cached Image is available - if let cachedData = ImageCacheManager.shared.loadCachedData(for: imagePath), forceOption == false { - DispatchQueue.main.async { - self.image = cachedData - } - - // No Image Cached - } else { - guard let imageURL = URL(string: APIService.configureUrlString(imagePath: imagePath)) else { return } - guard let imageData = try? Data(contentsOf: imageURL) else { return } - guard let newImage = UIImage(data: imageData) else { return } - - ImageCacheManager.shared.saveCacheData(of: newImage, for: imagePath) - DispatchQueue.main.async { - self.image = UIImage(data: imageData) - } - } - } - } -} diff --git a/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift b/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift index 16dd017..a1e940a 100644 --- a/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift +++ b/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift @@ -9,12 +9,11 @@ import UIKit import Then import SnapKit import Cosmos -import RxSwift class ChartTableViewCell: UITableViewCell { var contentId: Int? - private var disposeBag = DisposeBag() + let margin = 10.0 //MARK: Properties @@ -133,11 +132,6 @@ class ChartTableViewCell: UITableViewCell { fatalError("init(coder:) has not been implemented") } - override func prepareForReuse() { - super.prepareForReuse() - self.disposeBag = DisposeBag() - } - //MARK: Set Data func setData(rank: Int, movie: MovieFront) { @@ -151,7 +145,16 @@ class ChartTableViewCell: UITableViewCell { releaseDateLabel.text = movie.releaseDate starRating.rating = movie.ratingScore/2 ratingCountLabel.text = "(\(movie.ratingCount))" - posterImage.setImage(movie.posterPath) + + DispatchQueue.global().async { + guard let imagePath = movie.posterPath else { return } + guard let imageURL = URL(string: APIService.configureUrlString(imagePath: imagePath)) else { return } + guard let imageData = try? Data(contentsOf: imageURL) else { return } + + DispatchQueue.main.async { + self.posterImage.image = UIImage(data: imageData) + } + } } } diff --git a/MovieApp/MovieApp/Presentation/DetailView/View/DetailViewController.swift b/MovieApp/MovieApp/Presentation/DetailView/View/DetailViewController.swift index c678860..b8c71eb 100644 --- a/MovieApp/MovieApp/Presentation/DetailView/View/DetailViewController.swift +++ b/MovieApp/MovieApp/Presentation/DetailView/View/DetailViewController.swift @@ -200,7 +200,14 @@ class DetailViewController: UIViewController { //MARK: Binding Helper private func applyMovieDetailData(data: MovieDetail) { - self.backDropImage.setImage(APIService.configureUrlString(imagePath: APIService.configureUrlString(imagePath: data.backdropPath))) + DispatchQueue.global().async { + guard let imageURL = URL(string: APIService.configureUrlString(imagePath: data.backdropPath)) else { return } + guard let imageData = try? Data(contentsOf: imageURL) else { return } + + DispatchQueue.main.async { + self.backDropImage.image = UIImage(data: imageData) + } + } self.titleLabel.text = data.title self.taglineLabel.text = data.tagline diff --git a/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionViewCell.swift b/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionViewCell.swift index fcc9060..c96553b 100644 --- a/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionViewCell.swift +++ b/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionViewCell.swift @@ -7,17 +7,14 @@ import UIKit import SnapKit -import RxSwift class DiscoverCollectionViewCell: UICollectionViewCell { var contentId: Int? - private var disposeBag = DisposeBag() //MARK: Create properties lazy var posterImage = UIImageView().then { $0.contentMode = .scaleAspectFit - $0.image = UIImage(named: "img_placeholder") } lazy var movieTitle = UILabel().then { @@ -26,6 +23,8 @@ class DiscoverCollectionViewCell: UICollectionViewCell { $0.numberOfLines = 3 $0.minimumScaleFactor = 5 } + + override init(frame: CGRect) { super.init(frame: frame) @@ -51,6 +50,7 @@ class DiscoverCollectionViewCell: UICollectionViewCell { posterImage.snp.makeConstraints { make in make.left.right.greaterThanOrEqualToSuperview() make.bottom.lessThanOrEqualToSuperview() + } movieTitle.setContentHuggingPriority(.required, for: .vertical) // prevent stretching vertically @@ -61,19 +61,28 @@ class DiscoverCollectionViewCell: UICollectionViewCell { required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - - override func prepareForReuse() { - super.prepareForReuse() - self.disposeBag = DisposeBag() - } } //MARK: Insert data to cell extension DiscoverCollectionViewCell { func setData(movie: MovieFront) { + + + self.posterImage.image = UIImage(named: "img_placeholder") self.movieTitle.text = movie.title self.contentId = movie.id - self.posterImage.setImage(movie.posterPath) + + DispatchQueue.global().async { + + guard let imagePath = movie.posterPath else { return } + guard let imageURL = URL(string: APIService.configureUrlString(imagePath: imagePath)) else { return } + guard let imageData = try? Data(contentsOf: imageURL) else { return } + + DispatchQueue.main.async { + self.posterImage.image = UIImage(data: imageData) + } + } + } } diff --git a/MovieApp/MovieApp/Presentation/MainTabBarController.swift b/MovieApp/MovieApp/Presentation/MainTabBarController.swift index 7ead52b..4a76049 100644 --- a/MovieApp/MovieApp/Presentation/MainTabBarController.swift +++ b/MovieApp/MovieApp/Presentation/MainTabBarController.swift @@ -51,4 +51,6 @@ class MainTabBarController: UITabBarController, UITabBarControllerDelegate { return true; } + + } From cc41267b1f658a211ac5b9bf00afe977e4fd7fa0 Mon Sep 17 00:00:00 2001 From: "aakif.nadeem" Date: Mon, 25 Sep 2023 18:06:17 +0500 Subject: [PATCH 2/2] Refactored Color to Extension --- MovieApp/MovieApp.xcodeproj/project.pbxproj | 12 +++++--- MovieApp/MovieApp/Constant.swift | 30 ------------------- .../MovieApp/Domain/Model/GenreModel.swift | 30 +++++++++++++++++++ MovieApp/MovieApp/Extensions.swift | 6 ++++ .../ChartView/View/ChartTableViewCell.swift | 2 +- .../View/CreditTableViewDescriptionCell.swift | 2 +- .../View/CreditViewController.swift | 8 ++--- .../View/DiscoverCollectionHeaderView.swift | 4 +-- 8 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 MovieApp/MovieApp/Domain/Model/GenreModel.swift diff --git a/MovieApp/MovieApp.xcodeproj/project.pbxproj b/MovieApp/MovieApp.xcodeproj/project.pbxproj index ee3dd71..451b72d 100644 --- a/MovieApp/MovieApp.xcodeproj/project.pbxproj +++ b/MovieApp/MovieApp.xcodeproj/project.pbxproj @@ -37,7 +37,8 @@ 7DDE9C2D2787D6EE00938996 /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DDE9C2C2787D6EE00938996 /* MainTabBarController.swift */; }; 7DDE9C302787E0C700938996 /* ChartViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DDE9C2F2787E0C700938996 /* ChartViewController.swift */; }; 7DDE9C322788045B00938996 /* ChartTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DDE9C312788045B00938996 /* ChartTableViewCell.swift */; }; - 7DE8154327910DDC00726799 /* Keys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE8154227910DDC00726799 /* Keys.swift */; }; + 945E07952AC1BAF600A54568 /* Keys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945E07942AC1BAF600A54568 /* Keys.swift */; }; + 945E07972AC1BC8900A54568 /* GenreModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945E07962AC1BC8900A54568 /* GenreModel.swift */; }; 9F38C115EB6AF0EEE6B8E0C5 /* Pods_MovieApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1333EC5F83FAB13E0CD0D899 /* Pods_MovieApp.framework */; }; /* End PBXBuildFile section */ @@ -76,7 +77,8 @@ 7DDE9C2C2787D6EE00938996 /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = ""; }; 7DDE9C2F2787E0C700938996 /* ChartViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartViewController.swift; sourceTree = ""; }; 7DDE9C312788045B00938996 /* ChartTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartTableViewCell.swift; sourceTree = ""; }; - 7DE8154227910DDC00726799 /* Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keys.swift; sourceTree = ""; }; + 945E07942AC1BAF600A54568 /* Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keys.swift; sourceTree = ""; }; + 945E07962AC1BC8900A54568 /* GenreModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenreModel.swift; sourceTree = ""; }; FDA2E981A792A2B7397508AB /* Pods-MovieApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MovieApp.release.xcconfig"; path = "Target Support Files/Pods-MovieApp/Pods-MovieApp.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -160,7 +162,7 @@ isa = PBXGroup; children = ( 7D37AD9F278D5C97004BBFF9 /* APIService.swift */, - 7DE8154227910DDC00726799 /* Keys.swift */, + 945E07942AC1BAF600A54568 /* Keys.swift */, ); path = Service; sourceTree = ""; @@ -171,6 +173,7 @@ 7D37ADA1278D5CE7004BBFF9 /* MovieList.swift */, 7D9D9F49278E928C0098FEA3 /* MovieFront.swift */, 7D202FAD27B262A6008F8051 /* MovieDetail.swift */, + 945E07962AC1BC8900A54568 /* GenreModel.swift */, ); path = Model; sourceTree = ""; @@ -413,12 +416,13 @@ 7DDE9C302787E0C700938996 /* ChartViewController.swift in Sources */, 7D9D9F4A278E928C0098FEA3 /* MovieFront.swift in Sources */, 7D947CA9278C03E00031C7C9 /* CreditViewController.swift in Sources */, - 7DE8154327910DDC00726799 /* Keys.swift in Sources */, 7D90EC1B27D5EC160099B485 /* CreditHeaderView.swift in Sources */, 7DC7D34727913C89005C3D9C /* DiscoverViewModel.swift in Sources */, 7D15F0DA27D726E50029C40F /* CreditFootherView.swift in Sources */, 7DC7D34A27913E8F005C3D9C /* ChartViewModel.swift in Sources */, + 945E07972AC1BC8900A54568 /* GenreModel.swift in Sources */, 7D1982F02782D77500F2E745 /* SceneDelegate.swift in Sources */, + 945E07952AC1BAF600A54568 /* Keys.swift in Sources */, 7D8740F527841F5600E92C72 /* Constant.swift in Sources */, 7D90EC1927D5DA310099B485 /* CreditSection.swift in Sources */, ); diff --git a/MovieApp/MovieApp/Constant.swift b/MovieApp/MovieApp/Constant.swift index 3188f1c..7e1f179 100644 --- a/MovieApp/MovieApp/Constant.swift +++ b/MovieApp/MovieApp/Constant.swift @@ -7,13 +7,6 @@ import Foundation - -struct Colors { - static let background = "BgColor" - static let light_background = "LightBgColor" - static let placeholder = "PlaceholderTextColor" -} - struct identifiers { static let discover_collection_cell = "DiscoverCollectionCell" static let discover_collection_header = "DiscoverCollectionHeader" @@ -26,26 +19,3 @@ struct identifiers { static let detail_trailer_collection_Cell = "DetailTrailerCollectionCell" static let detail_cast_collection_Cell = "DetailCastCollectionCell" } - - -let genreCode = [ - 28 : "Action", - 12 : "Adventure", - 16 : "Animation", - 35 : "Comedy", - 80 : "Crime", - 99 : "Documentary", - 18 : "Drama", - 10751 : "Family", - 14 : "Fantasy", - 36 : "History", - 27 : "Horror", - 10402 : "Music", - 9648 : "Mystery", - 10749 : "Romance", - 878 : "Science Fiction", - 10770 : "TV Movie", - 53 : "Thriller", - 10752 : "War", - 37 : "Western" -] diff --git a/MovieApp/MovieApp/Domain/Model/GenreModel.swift b/MovieApp/MovieApp/Domain/Model/GenreModel.swift new file mode 100644 index 0000000..5a4e6ad --- /dev/null +++ b/MovieApp/MovieApp/Domain/Model/GenreModel.swift @@ -0,0 +1,30 @@ +// +// GenreModel.swift +// MovieApp +// +// Created by Aakif Nadeem on 25/09/2023. +// + +import Foundation + +let genreCode = [ + 28 : "Action", + 12 : "Adventure", + 16 : "Animation", + 35 : "Comedy", + 80 : "Crime", + 99 : "Documentary", + 18 : "Drama", + 10751 : "Family", + 14 : "Fantasy", + 36 : "History", + 27 : "Horror", + 10402 : "Music", + 9648 : "Mystery", + 10749 : "Romance", + 878 : "Science Fiction", + 10770 : "TV Movie", + 53 : "Thriller", + 10752 : "War", + 37 : "Western" +] diff --git a/MovieApp/MovieApp/Extensions.swift b/MovieApp/MovieApp/Extensions.swift index a50a0a3..877dc2f 100644 --- a/MovieApp/MovieApp/Extensions.swift +++ b/MovieApp/MovieApp/Extensions.swift @@ -22,3 +22,9 @@ extension UIImage { } } + +extension UIColor { + static let background = "BgColor" + static let light_background = "LightBgColor" + static let placeholder = "PlaceholderTextColor" +} diff --git a/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift b/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift index a1e940a..1750585 100644 --- a/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift +++ b/MovieApp/MovieApp/Presentation/ChartView/View/ChartTableViewCell.swift @@ -98,7 +98,7 @@ class ChartTableViewCell: UITableViewCell { $0.spacing = 5 } - self.backgroundColor = UIColor(named: Colors.background) + self.backgroundColor = UIColor(named: UIColor.background) self.selectionStyle = .none //MARK: Set Constraints diff --git a/MovieApp/MovieApp/Presentation/CreditView/View/CreditTableViewDescriptionCell.swift b/MovieApp/MovieApp/Presentation/CreditView/View/CreditTableViewDescriptionCell.swift index 86e7177..20b524c 100644 --- a/MovieApp/MovieApp/Presentation/CreditView/View/CreditTableViewDescriptionCell.swift +++ b/MovieApp/MovieApp/Presentation/CreditView/View/CreditTableViewDescriptionCell.swift @@ -37,7 +37,7 @@ class CreditTableViewDescriptionCell: UITableViewCell { private func setupView() { self.addSubview(descriptionView) - descriptionView.backgroundColor = UIColor(named: Colors.background) + descriptionView.backgroundColor = UIColor(named: UIColor.background) descriptionView.snp.makeConstraints { $0.edges.equalToSuperview() } } diff --git a/MovieApp/MovieApp/Presentation/CreditView/View/CreditViewController.swift b/MovieApp/MovieApp/Presentation/CreditView/View/CreditViewController.swift index e27c4ad..0951320 100644 --- a/MovieApp/MovieApp/Presentation/CreditView/View/CreditViewController.swift +++ b/MovieApp/MovieApp/Presentation/CreditView/View/CreditViewController.swift @@ -17,11 +17,11 @@ class CreditViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - self.view.backgroundColor = UIColor(named: Colors.background) + self.view.backgroundColor = UIColor(named: UIColor.background) tableView = UITableView(frame: self.view.frame, style: .insetGrouped) - tableView.backgroundColor = UIColor(named: Colors.background) - tableView.separatorColor = UIColor(named: Colors.background) + tableView.backgroundColor = UIColor(named: UIColor.background) + tableView.separatorColor = UIColor(named: UIColor.background) tableView.register(UITableViewCell.self, forCellReuseIdentifier: identifiers.credit_table_cell) tableView.bounces = false @@ -60,7 +60,7 @@ extension CreditViewController: UITableViewDataSource { if indexPath.section == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: identifiers.credit_table_cell, for: indexPath) as UITableViewCell - cell.backgroundColor = UIColor(named: Colors.light_background) + cell.backgroundColor = UIColor(named: UIColor.light_background) cell.textLabel?.textColor = .white let data = ExternalLink.data[indexPath.row] diff --git a/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionHeaderView.swift b/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionHeaderView.swift index 2ca24e5..a0ab853 100644 --- a/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionHeaderView.swift +++ b/MovieApp/MovieApp/Presentation/DiscoverView/View/DiscoverCollectionHeaderView.swift @@ -26,10 +26,10 @@ class DiscoverCollectionHeaderView: UICollectionReusableView { lazy var searchField = PaddingTextField().then { $0.layer.cornerRadius = 20 - $0.backgroundColor = UIColor(named: Colors.light_background) + $0.backgroundColor = UIColor(named: UIColor.light_background) $0.textColor = .white - let placeholderColor = UIColor(named: Colors.placeholder) ?? UIColor.lightGray + let placeholderColor = UIColor(named: UIColor.placeholder) ?? UIColor.lightGray $0.attributedPlaceholder = NSAttributedString( string: "Search...", attributes: [NSAttributedString.Key.foregroundColor: placeholderColor]