-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dad2110
commit e0e6311
Showing
30 changed files
with
714 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
SwiftRorty.iOS/Assets.xcassets/AccentColor.colorset/Contents.json
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
SwiftRorty.iOS/Assets.xcassets/blue_primary.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x41", | ||
"green" : "0x29", | ||
"red" : "0x25" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
SwiftRorty.iOS/Assets.xcassets/ic_splash.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "ic_app_logo.jpeg", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// LottieView.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import SwiftUI | ||
import Foundation | ||
import Lottie | ||
|
||
struct LottieView: UIViewRepresentable { | ||
@State var name: String | ||
var loopMode: LottieLoopMode = .playOnce | ||
var animationView = AnimationView() | ||
|
||
func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView { | ||
let view = UIView() | ||
|
||
animationView.animation = Animation.named(name) | ||
animationView.contentMode = .scaleAspectFill | ||
animationView.loopMode = .loop | ||
|
||
animationView.translatesAutoresizingMaskIntoConstraints = false | ||
view.addSubview(animationView) | ||
|
||
NSLayoutConstraint.activate([ | ||
animationView.widthAnchor.constraint(equalTo: view.widthAnchor), | ||
animationView.heightAnchor.constraint(equalTo: view.heightAnchor) | ||
]) | ||
|
||
return view | ||
} | ||
|
||
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LottieView>) { | ||
animationView.play() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// APIClient.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
protocol APIClient { | ||
func request<T: Decodable>(_ urlRequest: URLRequest) -> AnyPublisher<T, BaseError> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// APIClientImpl.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
class APIClientImpl: APIClient { | ||
|
||
private let session: URLSession | ||
|
||
init(session: URLSession = .shared) { | ||
self.session = session | ||
} | ||
|
||
func request<T>(_ urlRequest: URLRequest) -> AnyPublisher<T, BaseError> where T : Decodable { | ||
session.dataTaskPublisher(for: urlRequest) | ||
.mapError({ .api(description: $0.localizedDescription) }) | ||
.flatMap { response in | ||
Decoder().decode(response.data) | ||
}.eraseToAnyPublisher() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// APIMethod.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
enum APIMethod: String { | ||
case get = "GET" | ||
case post = "POST" | ||
case put = "PUT" | ||
case patch = "PATCH" | ||
case delete = "DELETE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// BaseError.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
enum BaseError : Error { | ||
case parse(description: String) | ||
case api(description: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// URLRequest.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 26.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
extension URLRequest { | ||
private static let baseUrl = "https://rickandmortyapi.com/api/" | ||
|
||
init(_ endpoint: APIEndpoint, | ||
_ method: APIMethod, | ||
_ parameters: [String: Any?]? = nil) { | ||
let urlString = "\(URLRequest.baseUrl)\(endpoint.path())" | ||
let url = URL(string: urlString)! | ||
self.init(url: url) | ||
self.httpMethod = method.rawValue | ||
processParameters(method, parameters) | ||
self.timeoutInterval = 30 | ||
} | ||
|
||
private mutating func processParameters(_ method: APIMethod, _ parameters: [String: Any?]? = nil) { | ||
switch method { | ||
case .get: | ||
processGetParameters(parameters) | ||
default: | ||
processPostParameters(parameters) | ||
} | ||
} | ||
|
||
private mutating func processPostParameters(_ parameters: [String: Any?]? = nil) { | ||
if let parameters = parameters, let jsonParameters = try? JSONSerialization.data(withJSONObject: parameters, | ||
options: []) { | ||
self.httpBody = jsonParameters | ||
} | ||
} | ||
|
||
private mutating func processGetParameters(_ parameters: [String: Any?]? = nil) { | ||
guard let parameters = parameters, !parameters.isEmpty else { return } | ||
let queryParameters = parameters.reduce("?") { (result, element) -> String in | ||
guard let value = element.value else { return result } | ||
if result.count > 1 { | ||
return "\(result)&\(element.key)=\(value)" | ||
} | ||
return "\(result)\(element.key)=\(value)" | ||
} | ||
var queryCharSet = NSCharacterSet.urlQueryAllowed | ||
queryCharSet.remove(charactersIn: "+") | ||
if let url = self.url?.absoluteString, | ||
let urlQueryParameters = queryParameters.addingPercentEncoding(withAllowedCharacters: queryCharSet) { | ||
let urlWithParameters = "\(url)\(urlQueryParameters)" | ||
self.url = URL(string: urlWithParameters)! | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// CharacterDto.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
struct CharacterDto: Identifiable { | ||
let created: String? | ||
let episode: [String]? | ||
let gender: String? | ||
let id: Int? | ||
let image: String? | ||
let location: Location? | ||
let name: String? | ||
let origin: Origin? | ||
let species: String? | ||
let status: Status? | ||
let type: String? | ||
let url: String? | ||
var isFavorite: Bool = false | ||
|
||
static func defaultDto() -> CharacterDto { | ||
return CharacterDto(created: nil, episode: nil, gender: nil, id: 1, image: nil, location: nil, name: "Rick Sanchez", origin: nil, species: "Human", status: Status.Alive, type: nil, url: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// DtoExtension.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
extension CharacterResponse { | ||
func toCharacterDtoList() -> [CharacterDto]? { | ||
results?.map { $0.toCharacterDto() } | ||
} | ||
} | ||
|
||
extension CharacterInfo { | ||
func toCharacterDto() -> CharacterDto { | ||
return .init(created: created, episode: episode, gender: gender, id: id, image: image, location: location, name: name, origin: origin, species: species, status: status, type: type, url: url) | ||
} | ||
} | ||
|
||
extension Location { | ||
func toLocationDto() -> LocationDto { | ||
return .init(locationId: 0, name: name, url: url) | ||
} | ||
} | ||
|
||
extension Origin { | ||
func toLocationDto() -> LocationDto { | ||
return .init(locationId: 0, name: name, url: url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// KeyValueModel.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct KeyValueModel { | ||
let key: String? | ||
let value: String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// LocationDto.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LocationDto { | ||
let locationId: Int? | ||
let name: String? | ||
let url: String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// StringExtension.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
// command + shift + / => comment/uncomment | ||
extension String { | ||
// func substringWithLastInstanceOf(character: Character) -> String? { | ||
// if let rangeOfIndex = rangeOfCharacterFromSet(NSCharacterSet(charactersInString: String(character)), options: .BackwardsSearch) { | ||
// return self.substringToIndex(rangeOfIndex.endIndex) | ||
// } | ||
// return nil | ||
// } | ||
// func substringWithoutLastInstanceOf(character: Character) -> String? { | ||
// if let rangeOfIndex = rangeOfCharacterFromSet(NSCharacterSet(charactersInString: String(character)), options: .BackwardsSearch) { | ||
// return self.substringToIndex(rangeOfIndex.startIndex) | ||
// } | ||
// return nil | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// APIEndpoint.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 25.02.2022. | ||
// | ||
|
||
import Foundation | ||
|
||
enum APIEndpoint { | ||
case characters(Int) | ||
|
||
func path() -> String { | ||
switch self { | ||
case .characters(let page): return "character/?page=\(page)" | ||
} | ||
} | ||
} |
Oops, something went wrong.