Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
[Fix] #58 ChartView category change is not working correctly (#60)
Browse files Browse the repository at this point in the history
### Describe
- In Charts View, list content seems like not changing when category is
changed but It's reloading
- New list was appended to existing list but it should replace existing
list
- Because `currentPage` property is added by 1 whenever category
changed, new list is considered as next list

### Changes Made
Remove currentPage adding code from `requestData(category:
MovieListCategory)`
```swift
    func requestData(category: MovieListCategory) {
        
        if currentCategory != category { currentPage = 1 }
        currentCategory = category
        fetchData(category: category)
        // current page += 1
    }

```


### Issues Resolved
- #58 
<!-- 
If this pull request addresses or closes any related issues, mention
them here. Use the GitHub issue linking format
(e.g., "Feature #123"). 
-->
  • Loading branch information
ChoiysApple committed Dec 12, 2023
2 parents 6902a8e + 759d6cf commit 5b7c4d1
Show file tree
Hide file tree
Showing 72 changed files with 399 additions and 329 deletions.
9 changes: 9 additions & 0 deletions MovieApp/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
disabled_rules:
- line_length
- trailing_whitespace
- blanket_disable_command
- unused_closure_parameter
- force_try # need to enable force_try after refactoring issue 43 fixed

excluded:
- Pods
121 changes: 83 additions & 38 deletions MovieApp/MovieApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand All @@ -31,6 +29,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?


func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }

guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = MainTabBarController()
window.makeKeyAndVisible()
self.window = window
}

func sceneDidDisconnect(_ scene: UIScene) {
Expand Down Expand Up @@ -47,6 +51,4 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// to restore the scene back to its current state.
}


}

33 changes: 0 additions & 33 deletions MovieApp/MovieApp/Base/Base.lproj/Main.storyboard

This file was deleted.

20 changes: 0 additions & 20 deletions MovieApp/MovieApp/Constant.swift

This file was deleted.

30 changes: 30 additions & 0 deletions MovieApp/MovieApp/Domain/Entities/GenreModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// GenreModel.swift
// MovieApp
//
// Created by Aakif Nadeem on 27/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"
]
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ struct ProductionCompany: Codable {

// MARK: - ProductionCountry
struct ProductionCountry: Codable {
let iso3166_1, name: String?
let countryCode, name: String?

enum CodingKeys: String, CodingKey {
case iso3166_1 = "iso_3166_1"
case countryCode = "iso_3166_1"
case name
}
}

// MARK: - SpokenLanguage
struct SpokenLanguage: Codable {
let englishName, iso639_1, name: String?
let englishName, languageCode, name: String?

enum CodingKeys: String, CodingKey {
case englishName
case iso639_1
case languageCode = "iso639_1"
case name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ struct MovieFront {
let ratingCount: Int
}


extension MovieFront{
extension MovieFront {
static func convertFromMovieInfo(movie: MovieListResult) -> MovieFront {

let genreValue: String = (movie.genreIDS.count > 0) ? genreCode[movie.genreIDS[0]] ?? "" : ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ struct MovieListResult: Codable {
case voteCount = "vote_count"
}
}

30 changes: 0 additions & 30 deletions MovieApp/MovieApp/Domain/Model/GenreModel.swift

This file was deleted.

67 changes: 3 additions & 64 deletions MovieApp/MovieApp/Domain/Service/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,16 @@ import RxSwift

class APIService {

/// Movie list
static func configureUrlString(category: MovieListCategory, language: Language, page: Int) -> String {
return "https://api.themoviedb.org/3/movie/\(category.key)?api_key=\(APIKey)&language=\(language.key)&page=\(page)"
}

/// Movie detail
static func configureUrlString(id: Int, language: Language) -> String {
return "https://api.themoviedb.org/3/movie/\(id)?api_key=\(APIKey)&language=\(language)"
}

/// Imagepath
static func configureUrlString(imagePath: String?) -> String? {
guard let imagePath else { return nil }
return "https://image.tmdb.org/t/p/original/\(imagePath)"
}

/// Keyword search
static func configureUrlString(keyword: String, language: Language, page: Int) -> String {
return "https://api.themoviedb.org/3/search/movie?query=\(keyword)&api_key=\(APIKey)&language=\(language.key)&page=\(page)"
}


static func fetchRequest(url: String, retries: Int, onComplete: @escaping (Result<Data, Error>) -> Void) {

guard let Url = URL(string: url) else {
guard let urlString = URL(string: url) else {
print("Error: invalid url")
return
}

let task = URLSession(configuration: .default).dataTask(with: Url) { (data, response, error) in
let task = URLSession(configuration: .default).dataTask(with: urlString) { (data, response, error) in

print("Request \(Url.absoluteString)")
print("Request \(urlString.absoluteString)")
if let error = error {
print("Error: \(error.localizedDescription)")
onComplete(.failure(error))
Expand All @@ -59,10 +37,6 @@ class APIService {
}
task.resume()
}
}

//MARK: Rx
extension APIService {

static func fetchWithRx(url: String, retries: Int) -> Observable<Data> {
return Observable.create { emitter in
Expand All @@ -87,38 +61,3 @@ extension String {
return "https://image.tmdb.org/t/p/original/\(self)"
}
}


//MARK: - Enumerations for API url configuration
enum MovieListCategory {
case Popular, Upcomming, TopRated, NowPlaying

var key: String {
switch self{
case .Popular: return "popular"
case .Upcomming: return "upcomming"
case .TopRated: return "top_rated"
case .NowPlaying: return "now_playing"
}
}

var title: String {
switch self{
case .Popular: return "Popular"
case .Upcomming: return "Upcomming"
case .TopRated: return "Top Rated"
case .NowPlaying: return "Now Playing"
}
}
}

enum Language {
case Korean, English

var key: String {
switch self{
case .Korean: return "ko-KR"
case .English: return "en-US"
}
}
}
67 changes: 67 additions & 0 deletions MovieApp/MovieApp/Domain/UseCase/MovieAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// MovieAPI.swift
// MovieApp
//
// Created by Daegeon Choi on 2023/11/22.
//

import Foundation

extension APIService {

/// Movie list
static func configureUrlString(category: MovieListCategory, language: Language, page: Int) -> String {
return "https://api.themoviedb.org/3/movie/\(category.key)?api_key=\(APIKey)&language=\(language.key)&page=\(page)"
}

/// Movie detail
static func configureUrlString(id: Int, language: Language) -> String {
return "https://api.themoviedb.org/3/movie/\(id)?api_key=\(APIKey)&language=\(language)"
}

/// Imagepath
static func configureUrlString(imagePath: String?) -> String? {
guard let imagePath else { return nil }
return "https://image.tmdb.org/t/p/original/\(imagePath)"
}

/// Keyword search
static func configureUrlString(keyword: String, language: Language, page: Int) -> String {
return "https://api.themoviedb.org/3/search/movie?query=\(keyword)&api_key=\(APIKey)&language=\(language.key)&page=\(page)"
}

}

// MARK: - Enumerations for API url configuration
enum MovieListCategory {
case popular, upcomming, topRated, nowPlaying

var key: String {
switch self {
case .popular: return "popular"
case .upcomming: return "upcomming"
case .topRated: return "top_rated"
case .nowPlaying: return "now_playing"
}
}

var title: String {
switch self {
case .popular: return "Popular"
case .upcomming: return "Upcomming"
case .topRated: return "Top Rated"
case .nowPlaying: return "Now Playing"
}
}
}

enum Language {
case korean, english

var key: String {
switch self {
case .korean: return "ko-KR"
case .english: return "en-US"
}
}
}
2 changes: 1 addition & 1 deletion MovieApp/MovieApp/Domain/Utils/Cache/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class Cache<Key: Hashable, Value> {
*/
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)")
print("Get cached data type: \(String(describing: Value.self))\n value: \(String(describing: entry?.value))")
return entry?.value
}

Expand Down
2 changes: 0 additions & 2 deletions MovieApp/MovieApp/Domain/Utils/Cache/ImageCacheManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ImageCacheManager {
- 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)
}

Expand All @@ -33,7 +32,6 @@ class ImageCacheManager {
- key: String url of UIImage
*/
func saveCacheData(of image: UIImage, for key: String) {
let itemURL = NSString(string: key)
cache.insertValue(image, forKey: key)
}
}
Loading

0 comments on commit 5b7c4d1

Please sign in to comment.