Skip to content

Commit

Permalink
POKEDEX
Browse files Browse the repository at this point in the history
  • Loading branch information
Mac authored and Mac committed May 4, 2017
1 parent d6d5fb9 commit bcf464c
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 7 deletions.
4 changes: 4 additions & 0 deletions PokeDex.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
0408CDAF1EA282760096DB20 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0408CDAE1EA282760096DB20 /* Assets.xcassets */; };
0408CDB21EA282760096DB20 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0408CDB01EA282760096DB20 /* LaunchScreen.storyboard */; };
0447D1FB1EA4636100CAE3DA /* PokeDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0447D1FA1EA4636100CAE3DA /* PokeDetailVC.swift */; };
04740E111EBA6A9900415415 /* music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 04740E101EBA6A9900415415 /* music.mp3 */; };
04BDE2961EA2915800CECD25 /* pokemon.csv in Resources */ = {isa = PBXBuildFile; fileRef = 04BDE2951EA2915800CECD25 /* pokemon.csv */; };
04BDE2991EA2945400CECD25 /* Pokemon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04BDE2981EA2945400CECD25 /* Pokemon.swift */; };
04BDE29C1EA29EB600CECD25 /* PokeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04BDE29B1EA29EB600CECD25 /* PokeCell.swift */; };
Expand All @@ -31,6 +32,7 @@
0408CDB11EA282760096DB20 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
0408CDB31EA282760096DB20 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0447D1FA1EA4636100CAE3DA /* PokeDetailVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PokeDetailVC.swift; sourceTree = "<group>"; };
04740E101EBA6A9900415415 /* music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = music.mp3; sourceTree = "<group>"; };
04BDE2951EA2915800CECD25 /* pokemon.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = pokemon.csv; sourceTree = "<group>"; };
04BDE2981EA2945400CECD25 /* Pokemon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pokemon.swift; sourceTree = "<group>"; };
04BDE29B1EA29EB600CECD25 /* PokeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PokeCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -113,6 +115,7 @@
children = (
04C7167D1EA3C737006742B3 /* Pokemon Solid.ttf */,
04BDE2951EA2915800CECD25 /* pokemon.csv */,
04740E101EBA6A9900415415 /* music.mp3 */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -222,6 +225,7 @@
files = (
04C7167E1EA3C737006742B3 /* Pokemon Solid.ttf in Resources */,
0408CDB21EA282760096DB20 /* LaunchScreen.storyboard in Resources */,
04740E111EBA6A9900415415 /* music.mp3 in Resources */,
0408CDAF1EA282760096DB20 /* Assets.xcassets in Resources */,
04BDE2961EA2915800CECD25 /* pokemon.csv in Resources */,
0408CDAD1EA282760096DB20 /* Main.storyboard in Resources */,
Expand Down
13 changes: 10 additions & 3 deletions PokeDex/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@
</constraints>
</view>
<navigationItem key="navigationItem" title="PokeDex" id="5Xd-H0-ddM">
<barButtonItem key="rightBarButtonItem" image="musicnav" id="9yJ-A7-YEC"/>
<barButtonItem key="rightBarButtonItem" image="musicnav" id="9yJ-A7-YEC">
<connections>
<action selector="musicButtonPressed:" destination="BYZ-38-t0r" id="1jt-qY-ssE"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="collectionSearchBar" destination="X4h-Ky-GGl" id="qhf-iT-fZz"/>
<outlet property="musicBtn" destination="9yJ-A7-YEC" id="laZ-7C-JML"/>
<outlet property="pokeCollectionView" destination="nBu-fs-wgV" id="fPV-pX-RTw"/>
<segue destination="zXj-Ig-5E2" kind="show" identifier="PokeDetailVc" id="IVc-Rh-CY3"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="985" y="-544"/>
<point key="canvasLocation" x="1074" y="-544"/>
</scene>
<!--Poke DetailVC-->
<scene sceneID="mIU-pQ-dQu">
Expand Down Expand Up @@ -148,7 +153,7 @@
<constraint firstAttribute="width" secondItem="u6w-Ar-lrA" secondAttribute="height" id="fyL-2V-ScM"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="8" translatesAutoresizingMaskIntoConstraints="NO" id="TYa-Dw-tLe">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="8" translatesAutoresizingMaskIntoConstraints="NO" id="TYa-Dw-tLe">
<rect key="frame" x="168" y="60" width="195" height="151"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="16"/>
<nil key="textColor"/>
Expand Down Expand Up @@ -337,7 +342,9 @@
<outlet property="heightLbl" destination="mUG-iN-iDQ" id="W3P-KH-PPk"/>
<outlet property="idLbl" destination="6X7-1D-FhH" id="4zW-vD-z0T"/>
<outlet property="lblDescription" destination="TYa-Dw-tLe" id="hhd-t9-O6P"/>
<outlet property="lblNextEvolutions" destination="WFZ-Er-eBt" id="FKV-oZ-mcb"/>
<outlet property="mainImg" destination="u6w-Ar-lrA" id="WAL-v5-87s"/>
<outlet property="nextEvoImage" destination="u5K-uL-Kct" id="Ejw-1O-oTy"/>
<outlet property="typeLbl" destination="cnZ-od-ZQR" id="5Pg-3H-EVv"/>
<outlet property="weightLbl" destination="gxE-g3-Wmj" id="EDf-M1-HWd"/>
</connections>
Expand Down
28 changes: 27 additions & 1 deletion PokeDex/PokeDetailVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class PokeDetailVC: UIViewController {

@IBOutlet weak var lblDescription:UILabel!

@IBOutlet weak var nextEvoImage:UIImageView!

@IBOutlet weak var lblNextEvolutions:UILabel!







Expand Down Expand Up @@ -68,5 +75,24 @@ class PokeDetailVC: UIViewController {
baseAttackLbl.text = detailedPokemon.baseAttack
typeLbl.text = detailedPokemon.type
lblDescription.text = detailedPokemon.description
}

if detailedPokemon.nextEvolutionId == ""{

lblNextEvolutions.text = " No Evolutions"
nextEvoImage.isHidden = true

} else {
nextEvoImage.isHidden = false
nextEvoImage.image = UIImage(named: detailedPokemon.nextEvolutionId)

let str = "NEXT EVOLUTION: \(detailedPokemon.nextEvolutionName) LEVEL \(detailedPokemon.nextEvolutionLevel)"

lblNextEvolutions.text = str

}
}




}
100 changes: 98 additions & 2 deletions PokeDex/Pokemon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,60 @@ class Pokemon{
private var _height:String!
private var _weight:String!
private var _baseAttack:String!
private var nextEvolutionText:String!
private var _nextEvolutionText:String!
private var _nextEvolutionName:String!
private var _nextEvolutionId:String!
private var _nextEvolutionLevel:String!
private var _pokemonURL:String!



var nextEvolutionName:String{

if _nextEvolutionName == nil{

_nextEvolutionName = ""

}
return _nextEvolutionName
}

var nextEvolutionText:String{

if _nextEvolutionText == nil {

_nextEvolutionText = ""
}

return _nextEvolutionText
}


var nextEvolutionId:String{

if _nextEvolutionId == nil{

_nextEvolutionId = ""

}
return _nextEvolutionId

}

var nextEvolutionLevel:String{

if _nextEvolutionLevel == nil {

_nextEvolutionLevel = ""

}

return _nextEvolutionLevel
}




var type:String{

if _type == nil {
Expand Down Expand Up @@ -194,7 +243,54 @@ class Pokemon{
}
}


if let evolutions = Dict["evolutions"] as? [Dictionary<String,AnyObject>] , evolutions.count > 0{

if let nextEvo = evolutions[0]["to"] as? String{


if nextEvo.range(of: "mega") == nil {


self._nextEvolutionName = nextEvo

if let uri = evolutions[0]["resource_uri"] as? String {

let newStr = uri.replacingOccurrences(of: "/api/v1/pokemon/", with: "")

let nextEvoID = newStr.replacingOccurrences(of: "/", with: "")

self._nextEvolutionId = nextEvoID


if let levelExist = evolutions[0]["level"]{


if let level = levelExist as? Int{


self._nextEvolutionLevel = "\(level)"
} else {

self._nextEvolutionLevel = ""

}
}


}

}




}





}


}
Expand Down
93 changes: 92 additions & 1 deletion PokeDex/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
//

import UIKit
import AVFoundation

class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout ,UISearchBarDelegate,UISearchControllerDelegate,UITextFieldDelegate{


@IBOutlet weak var pokeCollectionView:UICollectionView!
@IBOutlet weak var collectionSearchBar:UISearchBar!

@IBOutlet weak var musicBtn: UIBarButtonItem!


var pokemon = [Pokemon]()
var inSearchmode:Bool!
var filteredPokemon = [Pokemon]()

var muscicPlayer:AVAudioPlayer!




Expand All @@ -29,15 +33,49 @@ class ViewController: UIViewController,UICollectionViewDelegate,UICollectionView
self.collectionSearchBar.delegate = self

parsePokemonCSV()
initAudio()

inSearchmode = false
collectionSearchBar.returnKeyType = .done


// collectionSearchBar.showsCancelButton = false


}

func initAudio(){

let path = Bundle.main.path(forResource: "music", ofType: "mp3")!

do {

muscicPlayer = try AVAudioPlayer(contentsOf: URL(string: path)!)
muscicPlayer.prepareToPlay()
muscicPlayer.numberOfLoops = -1
muscicPlayer.play()


} catch let err as NSError{

print(err.debugDescription)

}

}

func playAudio(){


}


func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
view.endEditing(true)


searchBar.text = ""
inSearchmode = false

}

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
Expand Down Expand Up @@ -178,4 +216,57 @@ class ViewController: UIViewController,UICollectionViewDelegate,UICollectionView
}
}

@IBAction func musicButtonPressed(_ sender: Any) {



if muscicPlayer.isPlaying{

muscicPlayer.pause()

} else {

muscicPlayer.play()

}




}

}


































Binary file added PokeDex/music.mp3
Binary file not shown.

0 comments on commit bcf464c

Please sign in to comment.