-
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
41f8829
commit c88efe0
Showing
12 changed files
with
246 additions
and
17 deletions.
There are no files selected for viewing
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
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
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,20 @@ | ||
// | ||
// GetCharacterDetail.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 2.03.2022. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import Resolver | ||
|
||
class GetCharacterDetail { | ||
@Injected private var repository: CharacterRepository | ||
|
||
func invoke(characterId: Int) -> AnyPublisher<CharacterDto, Error> { | ||
repository.getCharacter(characterId: characterId).map { (response: CharacterInfo) in | ||
response.toCharacterDto() | ||
}.eraseToAnyPublisher() | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
SwiftRorty.iOS/presentation/features/detail/DetailContentView.swift
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,40 @@ | ||
// | ||
// DetailContentView.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 3.03.2022. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct DetailContentView: View { | ||
var contents: [KeyValueModel] = [] | ||
|
||
var body: some View { | ||
ZStack { | ||
RoundedRectangle(cornerRadius: 8, style: .continuous) | ||
.fill(Color.Card).shadow(radius: 1) | ||
|
||
VStack(alignment: .leading, spacing: 12) { | ||
ForEach(contents, id: \.id) { content in | ||
HStack(alignment: .center) { | ||
Text(content.key!) | ||
.fontTemplate(AppFontTemplate.body4) | ||
.redacted(reason: content.key == nil ? .placeholder : []) | ||
Spacer() | ||
Text(content.value!) | ||
.fontTemplate(AppFontTemplate.body2) | ||
.redacted(reason: content.value == nil ? .placeholder : []) | ||
} | ||
Divider() | ||
} | ||
}.padding(EdgeInsets(top: 16, leading: 12, bottom: 0, trailing: 12)) | ||
} | ||
} | ||
} | ||
|
||
struct DetailContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
DetailContentView() | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
SwiftRorty.iOS/presentation/features/detail/DetailHeaderView.swift
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,39 @@ | ||
// | ||
// DetailHeaderView.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 3.03.2022. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct DetailHeaderView: View { | ||
var dto: CharacterDto? | ||
|
||
var body: some View { | ||
if let image = dto?.image, | ||
let url = URL(string: image) { | ||
AsyncImage(url: url) { image in | ||
image.resizable() | ||
} placeholder: { | ||
Color.gray | ||
} | ||
.aspectRatio(contentMode: .fit) | ||
.frame(width: 200, height: 200) | ||
.clipShape(RoundedRectangle(cornerRadius: 16)) | ||
.padding(EdgeInsets(top: 16, leading: 0, bottom: 16, trailing: 0)) | ||
} else { | ||
RoundedRectangle(cornerRadius: 16) | ||
.padding(EdgeInsets(top: 16, leading: 0, bottom: 16, trailing: 0)) | ||
.frame(width: 200, height: 200) | ||
.foregroundColor(.gray) | ||
} | ||
} | ||
} | ||
|
||
struct DetailHeaderView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
DetailHeaderView() | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
SwiftRorty.iOS/presentation/features/detail/DetailViewModel.swift
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,73 @@ | ||
// | ||
// DetailViewModel.swift | ||
// SwiftRorty.iOS | ||
// | ||
// Created by developersancho on 2.03.2022. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import Combine | ||
import Resolver | ||
|
||
class DetailViewModel: ObservableObject { | ||
@Injected | ||
private var getCharacterDetail: GetCharacterDetail | ||
@Published | ||
var dto: CharacterDto? | ||
@Published | ||
var details: [KeyValueModel] = [] | ||
private var cancelables = [AnyCancellable]() | ||
|
||
|
||
func loadDetail(characterId: Int) { | ||
getCharacterDetail.invoke(characterId: characterId) | ||
.receive(on: DispatchQueue.main) | ||
.sink(receiveCompletion: { _ in }, receiveValue: { [weak self] response in | ||
self?.dto = response | ||
self?.details = self!.getDetails(character: response) | ||
}) | ||
.store(in: &cancelables) | ||
} | ||
|
||
func getDetails(character: CharacterDto) -> [KeyValueModel] { | ||
var list: [KeyValueModel] = [] | ||
list.append( | ||
KeyValueModel( | ||
id: 0, | ||
key: "Name", | ||
value: character.name | ||
) | ||
) | ||
list.append( | ||
KeyValueModel( | ||
id: 1, | ||
key: "Species", | ||
value: character.species | ||
) | ||
) | ||
list.append( | ||
KeyValueModel( | ||
id: 2, | ||
key: "Gender", | ||
value: character.gender | ||
) | ||
) | ||
list.append( | ||
KeyValueModel( | ||
id: 3, | ||
key: "Last Know Location", | ||
value: character.origin?.name ?? "-" | ||
) | ||
) | ||
list.append( | ||
KeyValueModel( | ||
id: 4, | ||
key: "Location", | ||
value: character.location?.name ?? "-" | ||
) | ||
) | ||
|
||
return list | ||
} | ||
} |
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