Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
xramos committed May 27, 2022
1 parent e01bea1 commit 5d6508b
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 106 deletions.
48 changes: 32 additions & 16 deletions Pokemon/Pokemon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
DAD0D35D283FCD3A00436272 /* ServerPokemon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D35C283FCD3A00436272 /* ServerPokemon.swift */; };
DAD0D35F283FCF1500436272 /* ServerTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D35E283FCF1500436272 /* ServerTypes.swift */; };
DAD0D361283FCF3D00436272 /* ServerType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D360283FCF3D00436272 /* ServerType.swift */; };
DAD0D367283FD0B400436272 /* PokemonType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D366283FD0B400436272 /* PokemonType.swift */; };
DAD0D369283FD1A600436272 /* Pokemon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D368283FD1A600436272 /* Pokemon.swift */; };
DAD0D36B283FD3B300436272 /* APIManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D36A283FD3B300436272 /* APIManager.swift */; };
DAD0D36D283FD40100436272 /* HTTPError.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D36C283FD40100436272 /* HTTPError.swift */; };
Expand All @@ -27,7 +26,6 @@
DAD0D3762840B6D800436272 /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D3742840B6D800436272 /* Model.xcdatamodeld */; };
DAD0D3782840B7A000436272 /* ServerSprite.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D3772840B7A000436272 /* ServerSprite.swift */; };
DAD0D37A2840B82F00436272 /* DBPokemon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D3792840B82F00436272 /* DBPokemon.swift */; };
DAD0D37C2840B85100436272 /* DBPokemonType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D37B2840B85100436272 /* DBPokemonType.swift */; };
DAD0D37F2840BEAA00436272 /* DateFormatter+Pokemon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D37E2840BEAA00436272 /* DateFormatter+Pokemon.swift */; };
DAD0D3812840C29900436272 /* PokemonRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D3802840C29900436272 /* PokemonRepository.swift */; };
DAD0D3832840C45300436272 /* LocalPokemonDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD0D3822840C45300436272 /* LocalPokemonDataSource.swift */; };
Expand All @@ -54,6 +52,8 @@
DAE24310284106CE00AD4FE1 /* PokemonDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2430F284106CE00AD4FE1 /* PokemonDetailViewModel.swift */; };
DAE243142841095F00AD4FE1 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE243132841095F00AD4FE1 /* ToastView.swift */; };
DAE2431A28410A2A00AD4FE1 /* PokemonBackgroundModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2431928410A2A00AD4FE1 /* PokemonBackgroundModifier.swift */; };
DAE243202841105300AD4FE1 /* TitleValueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE2431F2841105300AD4FE1 /* TitleValueView.swift */; };
DAE24323284113CF00AD4FE1 /* TitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE24322284113CF00AD4FE1 /* TitleView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -87,7 +87,6 @@
DAD0D35C283FCD3A00436272 /* ServerPokemon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerPokemon.swift; sourceTree = "<group>"; };
DAD0D35E283FCF1500436272 /* ServerTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerTypes.swift; sourceTree = "<group>"; };
DAD0D360283FCF3D00436272 /* ServerType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerType.swift; sourceTree = "<group>"; };
DAD0D366283FD0B400436272 /* PokemonType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonType.swift; sourceTree = "<group>"; };
DAD0D368283FD1A600436272 /* Pokemon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pokemon.swift; sourceTree = "<group>"; };
DAD0D36A283FD3B300436272 /* APIManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIManager.swift; sourceTree = "<group>"; };
DAD0D36C283FD40100436272 /* HTTPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPError.swift; sourceTree = "<group>"; };
Expand All @@ -97,7 +96,6 @@
DAD0D3752840B6D800436272 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
DAD0D3772840B7A000436272 /* ServerSprite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSprite.swift; sourceTree = "<group>"; };
DAD0D3792840B82F00436272 /* DBPokemon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBPokemon.swift; sourceTree = "<group>"; };
DAD0D37B2840B85100436272 /* DBPokemonType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBPokemonType.swift; sourceTree = "<group>"; };
DAD0D37E2840BEAA00436272 /* DateFormatter+Pokemon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Pokemon.swift"; sourceTree = "<group>"; };
DAD0D3802840C29900436272 /* PokemonRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonRepository.swift; sourceTree = "<group>"; };
DAD0D3822840C45300436272 /* LocalPokemonDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalPokemonDataSource.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -125,6 +123,8 @@
DAE2430F284106CE00AD4FE1 /* PokemonDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonDetailViewModel.swift; sourceTree = "<group>"; };
DAE243132841095F00AD4FE1 /* ToastView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
DAE2431928410A2A00AD4FE1 /* PokemonBackgroundModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PokemonBackgroundModifier.swift; sourceTree = "<group>"; };
DAE2431F2841105300AD4FE1 /* TitleValueView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleValueView.swift; sourceTree = "<group>"; };
DAE24322284113CF00AD4FE1 /* TitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -175,20 +175,20 @@
DAD0D31A283FC74100436272 /* Pokemon */ = {
isa = PBXGroup;
children = (
DAE243112841095F00AD4FE1 /* ViewModifiers */,
DAE242F12840DA4500AD4FE1 /* Views */,
DAD0D3942840CC2900436272 /* Info.plist */,
DAD0D37D2840BE7300436272 /* Extensions */,
DAD0D354283FCD2B00436272 /* API */,
DAD0D31F283FC74200436272 /* Assets.xcassets */,
DAD0D351283FC7B000436272 /* Constants.swift */,
DAD0D35A283FCD2B00436272 /* DataBase */,
DAD0D355283FCD2B00436272 /* Entities */,
DAD0D37D2840BE7300436272 /* Extensions */,
DAD0D3942840CC2900436272 /* Info.plist */,
DAD0D31B283FC74100436272 /* PokemonApp.swift */,
DAD0D321283FC74200436272 /* Preview Content */,
DAD0D359283FCD2B00436272 /* Repositories */,
DAD0D35B283FCD2B00436272 /* Scenes */,
DAD0D353283FCD2B00436272 /* UseCases */,
DAD0D31B283FC74100436272 /* PokemonApp.swift */,
DAD0D31F283FC74200436272 /* Assets.xcassets */,
DAD0D321283FC74200436272 /* Preview Content */,
DAD0D351283FC7B000436272 /* Constants.swift */,
DAE243112841095F00AD4FE1 /* ViewModifiers */,
DAE242F12840DA4500AD4FE1 /* Views */,
);
path = Pokemon;
sourceTree = "<group>";
Expand Down Expand Up @@ -252,7 +252,6 @@
isa = PBXGroup;
children = (
DAD0D3792840B82F00436272 /* DBPokemon.swift */,
DAD0D37B2840B85100436272 /* DBPokemonType.swift */,
);
path = DBEntities;
sourceTree = "<group>";
Expand All @@ -271,7 +270,6 @@
DAD0D358283FCD2B00436272 /* Entities */ = {
isa = PBXGroup;
children = (
DAD0D366283FD0B400436272 /* PokemonType.swift */,
DAD0D368283FD1A600436272 /* Pokemon.swift */,
);
path = Entities;
Expand Down Expand Up @@ -359,6 +357,8 @@
DAE242F12840DA4500AD4FE1 /* Views */ = {
isa = PBXGroup;
children = (
DAE24321284113C100AD4FE1 /* TitleView */,
DAE2431E2841105300AD4FE1 /* TitleValueView */,
DAE243052840FF3E00AD4FE1 /* ImageView */,
DAE242F52840DD0200AD4FE1 /* BackPackCardView */,
DAE242F62840DD0200AD4FE1 /* PokemonCardView */,
Expand Down Expand Up @@ -425,6 +425,22 @@
path = PokemonBackgroundModifier;
sourceTree = "<group>";
};
DAE2431E2841105300AD4FE1 /* TitleValueView */ = {
isa = PBXGroup;
children = (
DAE2431F2841105300AD4FE1 /* TitleValueView.swift */,
);
path = TitleValueView;
sourceTree = "<group>";
};
DAE24321284113C100AD4FE1 /* TitleView */ = {
isa = PBXGroup;
children = (
DAE24322284113CF00AD4FE1 /* TitleView.swift */,
);
path = TitleView;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -574,6 +590,7 @@
DAD0D35F283FCF1500436272 /* ServerTypes.swift in Sources */,
DAD0D36B283FD3B300436272 /* APIManager.swift in Sources */,
DAE242FC2840E3C700AD4FE1 /* BackpackViewModel.swift in Sources */,
DAE24323284113CF00AD4FE1 /* TitleView.swift in Sources */,
DAD0D3892840C76700436272 /* GetPokemonUseCase.swift in Sources */,
DAD0D31C283FC74100436272 /* PokemonApp.swift in Sources */,
DAD0D352283FC7B000436272 /* Constants.swift in Sources */,
Expand All @@ -589,13 +606,12 @@
DAE243082840FF3E00AD4FE1 /* ImageLoader.swift in Sources */,
DAD0D36F283FDA2F00436272 /* Persistence.swift in Sources */,
DAD0D38B2840C7C600436272 /* SavePokemonUseCase.swift in Sources */,
DAD0D367283FD0B400436272 /* PokemonType.swift in Sources */,
DAE242FA2840E3BB00AD4FE1 /* BackpackView.swift in Sources */,
DAE243042840E75500AD4FE1 /* BackPackCardView.swift in Sources */,
DAE242F82840DD0D00AD4FE1 /* PokemonCardView.swift in Sources */,
DAD0D38F2840C83100436272 /* GetPokemonsUseCase.swift in Sources */,
DAD0D3732840B60F00436272 /* DBManager.swift in Sources */,
DAD0D37C2840B85100436272 /* DBPokemonType.swift in Sources */,
DAE243202841105300AD4FE1 /* TitleValueView.swift in Sources */,
DAE243022840E63800AD4FE1 /* TabBar.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
10 changes: 1 addition & 9 deletions Pokemon/Pokemon/DataBase/DBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,7 @@ class DBManager: Persistence {
dbPokemon.experience = Int16(pokemon.experience)
dbPokemon.url = pokemon.url
dbPokemon.date = dateString

// Create and assign DBPokemonTypes
for type in pokemon.types {
let dbPokemonType = DBPokemonType(context: coreDataStack.managedContext)
dbPokemonType.id = UUID()
dbPokemonType.slot = Int16(type.slot)
dbPokemonType.name = type.name
dbPokemonType.pokemon = dbPokemon
}
dbPokemon.types = pokemon.types

// Save DBEntitites
coreDataStack.saveContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
<attribute name="height" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="types" optional="YES" attributeType="String"/>
<attribute name="url" optional="YES" attributeType="String"/>
<attribute name="weight" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<relationship name="types" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="DBPokemonType" inverseName="pokemon" inverseEntity="DBPokemonType"/>
</entity>
<entity name="DBPokemonType" representedClassName="DBPokemonType" syncable="YES" codeGenerationType="class">
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="slot" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<relationship name="pokemon" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="DBPokemon" inverseName="types" inverseEntity="DBPokemon"/>
</entity>
<elements>
<element name="DBPokemon" positionX="-63" positionY="-18" width="128" height="149"/>
<element name="DBPokemonType" positionX="-54" positionY="27" width="128" height="89"/>
</elements>
</model>
9 changes: 1 addition & 8 deletions Pokemon/Pokemon/Entities/DBEntities/DBPokemon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@ extension DBPokemon {

func convertToEntity() -> Pokemon {

var pokemonTypes: [PokemonType] = []

if let types = types, let dbPokemonTypes = types.allObjects as? [DBPokemonType] {

pokemonTypes = dbPokemonTypes.map({ $0.convertToEntity() })
}

return Pokemon(id: Int(id),
name: name ?? "",
weight: Int(weight),
height: Int(height),
experience: Int(experience),
url: url ?? "",
date: date ?? "",
types: pokemonTypes)
types: types ?? "")
}
}
18 changes: 0 additions & 18 deletions Pokemon/Pokemon/Entities/DBEntities/DBPokemonType.swift

This file was deleted.

3 changes: 1 addition & 2 deletions Pokemon/Pokemon/Entities/Entities/Pokemon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ struct Pokemon: Identifiable {
let experience: Int
let url: String
let date: String

let types: [PokemonType]
let types: String
}
14 changes: 0 additions & 14 deletions Pokemon/Pokemon/Entities/Entities/PokemonType.swift

This file was deleted.

12 changes: 10 additions & 2 deletions Pokemon/Pokemon/Entities/ServerEntities/ServerPokemon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ struct ServerPokemon: Codable {

func convertToEntity() -> Pokemon {

var pokemonTypes: [PokemonType] = []
var pokemonTypes: String = ""

if let types = types {
pokemonTypes = types.map({ $0.convertToEntity() })

for type in types {

pokemonTypes = "\(pokemonTypes), \(type.type.name)"
}

pokemonTypes.remove(at: pokemonTypes.startIndex)
pokemonTypes.remove(at: pokemonTypes.startIndex)
}

return Pokemon(id: id,
Expand Down
6 changes: 0 additions & 6 deletions Pokemon/Pokemon/Entities/ServerEntities/ServerTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ struct ServerTypes: Codable {

let slot: Int
let type: ServerType

func convertToEntity() -> PokemonType {

return PokemonType(slot: slot,
name: type.name)
}
}
1 change: 1 addition & 0 deletions Pokemon/Pokemon/Scenes/Backpack/BackpackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct BackpackView: View {
BackPackCardView(name: pokemon.name,
image: pokemon.url)
}
.buttonStyle(PlainButtonStyle())
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions Pokemon/Pokemon/Scenes/PokemonDetail/PokemonDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,30 @@ struct PokemonDetailView: View {

VStack {

VStack {
VStack(alignment: .center) {

ImageView(withURL: viewModel.pokemon.url)

VStack(alignment: .leading, spacing: 4) {

Text(viewModel.pokemon.name)
.bold()
TitleView(title: viewModel.pokemon.name)

Text("weight: \(viewModel.pokemon.weight)")
TitleValueView(title: "Weight:", value: "\(viewModel.pokemon.weight)")

Text("height: \(viewModel.pokemon.height)")
TitleValueView(title: "Height: ", value: "\(viewModel.pokemon.height)")

Text("Experience: \(viewModel.pokemon.experience)")
TitleValueView(title: "Experience:", value: "\(viewModel.pokemon.experience)")

Text("Caught on: \(viewModel.pokemon.date)")
TitleValueView(title: "Caught on:", value: "\(viewModel.pokemon.date)")

TitleValueView(title: "Types:", value: "\(viewModel.pokemon.types)")

Spacer().frame(height: 10)
}
.padding([.leading, .trailing, .bottom], 10)
}
.pokemonBackground()
.padding(20)
.padding(.bottom, 20)
}
}
}
Expand All @@ -53,7 +54,7 @@ struct PokemonDetailView_Previews: PreviewProvider {
experience: 0,
url: "",
date: "",
types: [])
types: "")

PokemonDetailView(viewModel: PokemonDetailViewModel(pokemon: pokemon))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PokemonDetailViewModel: ObservableObject {
experience: 0,
url: "",
date: "",
types: [])
types: "")

// MARK: - Methods

Expand Down
1 change: 0 additions & 1 deletion Pokemon/Pokemon/Scenes/PokemonWorld/PokemonWorldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ struct PokemonWorldView: View {
self.viewModel.caughtPokemon()
}
.disabled(viewModel.isCatched ? true : false)
//.opacity(viewModel.isCatched ? 0.3 : 1.0)
.blur(radius: viewModel.isCatched ? 4 : 0)
}

Expand Down
11 changes: 11 additions & 0 deletions Pokemon/Pokemon/Scenes/TabBar/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ struct TabBar: View {

@State var activeTab: Tab = .pokemonWorld

init() {

let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.backgroundColor = UIColor(named: "pokemonYellow")
tabBarAppearance.shadowColor = UIColor.gray
tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.black]
tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
UITabBar.appearance().standardAppearance = tabBarAppearance
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}

var body: some View {

TabView(selection: $activeTab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ struct BackPackCardView: View {

ImageView(withURL: image)

Text(name)
.bold()
TitleView(title: name)

Spacer().frame(height: 10)

Expand Down
Loading

0 comments on commit 5d6508b

Please sign in to comment.