Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/demo v2 #15

Merged
merged 5 commits into from Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions Demo/Viper-v2-Demo.xcodeproj/project.pbxproj
Expand Up @@ -16,6 +16,12 @@
521A3FB4207E2F88001EFB92 /* PokemonDetailsCommentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 521A3FB0207E2F88001EFB92 /* PokemonDetailsCommentTableViewCell.swift */; };
521A3FB5207E2F88001EFB92 /* PokemonDetailsCharacteristicsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 521A3FB1207E2F88001EFB92 /* PokemonDetailsCharacteristicsTableViewCell.swift */; };
521A3FB6207E2F88001EFB92 /* PokemonDetails.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 521A3FB2207E2F88001EFB92 /* PokemonDetails.storyboard */; };
526DF99120BEBCDE0011D29A /* RegisterInterfaces.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526DF98C20BEBCDE0011D29A /* RegisterInterfaces.swift */; };
526DF99220BEBCDE0011D29A /* RegisterPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526DF98D20BEBCDE0011D29A /* RegisterPresenter.swift */; };
526DF99320BEBCDE0011D29A /* RegisterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526DF98E20BEBCDE0011D29A /* RegisterViewController.swift */; };
526DF99420BEBCDE0011D29A /* RegisterInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526DF98F20BEBCDE0011D29A /* RegisterInteractor.swift */; };
526DF99520BEBCDE0011D29A /* RegisterWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526DF99020BEBCDE0011D29A /* RegisterWireframe.swift */; };
526DF99820BEBD430011D29A /* Register.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 526DF99720BEBD430011D29A /* Register.storyboard */; };
52AF85DE20808F7A00046F15 /* UITableView+DequeueCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52AF85DD20808F7A00046F15 /* UITableView+DequeueCell.swift */; };
52AF85E02080926E00046F15 /* PokedexNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52AF85DF2080926E00046F15 /* PokedexNavigationController.swift */; };
52AF85E2208495B100046F15 /* KeyDecodingStategy+KebabCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52AF85E1208495B100046F15 /* KeyDecodingStategy+KebabCase.swift */; };
Expand Down Expand Up @@ -100,6 +106,12 @@
521A3FB0207E2F88001EFB92 /* PokemonDetailsCommentTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PokemonDetailsCommentTableViewCell.swift; sourceTree = "<group>"; };
521A3FB1207E2F88001EFB92 /* PokemonDetailsCharacteristicsTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PokemonDetailsCharacteristicsTableViewCell.swift; sourceTree = "<group>"; };
521A3FB2207E2F88001EFB92 /* PokemonDetails.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = PokemonDetails.storyboard; sourceTree = "<group>"; };
526DF98C20BEBCDE0011D29A /* RegisterInterfaces.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterInterfaces.swift; sourceTree = "<group>"; };
526DF98D20BEBCDE0011D29A /* RegisterPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterPresenter.swift; sourceTree = "<group>"; };
526DF98E20BEBCDE0011D29A /* RegisterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterViewController.swift; sourceTree = "<group>"; };
526DF98F20BEBCDE0011D29A /* RegisterInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterInteractor.swift; sourceTree = "<group>"; };
526DF99020BEBCDE0011D29A /* RegisterWireframe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterWireframe.swift; sourceTree = "<group>"; };
526DF99720BEBD430011D29A /* Register.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Register.storyboard; sourceTree = "<group>"; };
52AF85DD20808F7A00046F15 /* UITableView+DequeueCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableView+DequeueCell.swift"; sourceTree = "<group>"; };
52AF85DF2080926E00046F15 /* PokedexNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokedexNavigationController.swift; sourceTree = "<group>"; };
52AF85E1208495B100046F15 /* KeyDecodingStategy+KebabCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyDecodingStategy+KebabCase.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -229,6 +241,20 @@
path = Cells;
sourceTree = "<group>";
};
526DF99620BEBD0F0011D29A /* Register */ = {
isa = PBXGroup;
children = (
526DF98C20BEBCDE0011D29A /* RegisterInterfaces.swift */,
526DF98D20BEBCDE0011D29A /* RegisterPresenter.swift */,
526DF98E20BEBCDE0011D29A /* RegisterViewController.swift */,
526DF98F20BEBCDE0011D29A /* RegisterInteractor.swift */,
526DF99020BEBCDE0011D29A /* RegisterWireframe.swift */,
526DF99720BEBD430011D29A /* Register.storyboard */,
);
name = Register;
path = "New Group";
sourceTree = "<group>";
};
52CD615D207DE22600AFB254 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -327,6 +353,7 @@
521A3FA3207E2F32001EFB92 /* Details */,
52CD61F5207DEB5C00AFB254 /* Home */,
52CD61E8207DE3E100AFB254 /* Login */,
526DF99620BEBD0F0011D29A /* Register */,
);
path = Modules;
sourceTree = "<group>";
Expand Down Expand Up @@ -580,6 +607,7 @@
521A3FB6207E2F88001EFB92 /* PokemonDetails.storyboard in Resources */,
52CD61F4207DE82900AFB254 /* Login.storyboard in Resources */,
52CD61D0207DE32200AFB254 /* Assets.xcassets in Resources */,
526DF99820BEBD430011D29A /* Register.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -734,10 +762,12 @@
52CD61F0207DE3F700AFB254 /* LoginViewController.swift in Sources */,
52CD61D1207DE32200AFB254 /* Section.swift in Sources */,
52CD61DB207DE32200AFB254 /* InteractorInterface.swift in Sources */,
526DF99520BEBCDE0011D29A /* RegisterWireframe.swift in Sources */,
521A3FAC207E2F4A001EFB92 /* PokemonDetailsInteractor.swift in Sources */,
521A3FAA207E2F4A001EFB92 /* PokemonDetailsPresenter.swift in Sources */,
52CD61FF207DEB7000AFB254 /* HomeWireframe.swift in Sources */,
52CD61F1207DE3F700AFB254 /* LoginInteractor.swift in Sources */,
526DF99220BEBCDE0011D29A /* RegisterPresenter.swift in Sources */,
52CD61DC207DE32200AFB254 /* PokedexValidate.swift in Sources */,
521A3FA9207E2F4A001EFB92 /* PokemonDetailsInterfaces.swift in Sources */,
52CD6203207DF3B200AFB254 /* HomeTableViewCell.swift in Sources */,
Expand All @@ -749,13 +779,15 @@
52AF85E2208495B100046F15 /* KeyDecodingStategy+KebabCase.swift in Sources */,
52AF85EA2084C4B400046F15 /* PartialURL.swift in Sources */,
52CD61EE207DE3F700AFB254 /* LoginInterfaces.swift in Sources */,
526DF99120BEBCDE0011D29A /* RegisterInterfaces.swift in Sources */,
52CD61F2207DE3F700AFB254 /* LoginWireframe.swift in Sources */,
52CD61D5207DE32200AFB254 /* Error+Message.swift in Sources */,
52CD61E2207DE32200AFB254 /* UserService.swift in Sources */,
52CD61DA207DE32200AFB254 /* ViewInterface.swift in Sources */,
52CD61E1207DE32200AFB254 /* PasswordValidator.swift in Sources */,
52CD61D6207DE32200AFB254 /* UIColor+Pokedex.swift in Sources */,
52CD61FC207DEB7000AFB254 /* HomePresenter.swift in Sources */,
526DF99420BEBCDE0011D29A /* RegisterInteractor.swift in Sources */,
52CD61D2207DE32200AFB254 /* JSONAPIObject.swift in Sources */,
52CD61EF207DE3F700AFB254 /* LoginPresenter.swift in Sources */,
52CD61DE207DE32200AFB254 /* AuthorizationAdapter.swift in Sources */,
Expand All @@ -779,6 +811,7 @@
52CD61CC207DE32200AFB254 /* ThemeInitializer.swift in Sources */,
52CD61D3207DE32200AFB254 /* User.swift in Sources */,
52CD61DD207DE32200AFB254 /* APIError.swift in Sources */,
526DF99320BEBCDE0011D29A /* RegisterViewController.swift in Sources */,
52AF85E42084975800046F15 /* String+IndexOf.swift in Sources */,
52CD61FE207DEB7000AFB254 /* HomeInteractor.swift in Sources */,
);
Expand Down
22 changes: 22 additions & 0 deletions Demo/Viper-v2-Demo/Common/Services/UserService.swift
Expand Up @@ -33,5 +33,27 @@ class UserService: NSObject {
parameters: parameters
).pokedexValidate().responseCodableJSONAPI(keyPath: "data", decoder: .kebabCaseDecoder, completionHandler: completion)
}

@discardableResult
func registerUser(with username: String, email: String, password: String, confirmedPassword: String, completion: @escaping LoginCompletionBlock) -> DataRequest {

let parameters: Parameters = [
"data": [
"type": "users",
"attributes": [
"username":username,
"email": email,
"password": password,
"password_confirmation": confirmedPassword
]
]
]

return Alamofire.request(
Constants.API.URLBase.appendingPathComponent("api/v1/users"),
method: .post,
parameters: parameters
).pokedexValidate().responseCodableJSONAPI(keyPath: "data", decoder: .kebabCaseDecoder, completionHandler: completion)
}

}
36 changes: 27 additions & 9 deletions Demo/Viper-v2-Demo/Modules/Login/Login.storyboard
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="No2-Kp-lBu">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="No2-Kp-lBu">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -23,11 +23,8 @@
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="pokeball" translatesAutoresizingMaskIntoConstraints="NO" id="uSn-Xg-txX">
<rect key="frame" x="112" y="150" width="151" height="151"/>
</imageView>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="pokedex-title" translatesAutoresizingMaskIntoConstraints="NO" id="26L-yw-rY4">
<rect key="frame" x="67.5" y="50" width="240" height="100"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="J3d-o3-YPy">
<rect key="frame" x="0.0" y="617" width="375" height="50"/>
<rect key="frame" x="0.0" y="617" width="187.5" height="50"/>
<color key="backgroundColor" red="0.20000000000000001" green="0.31372549019607843" blue="0.55294117647058827" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="e8X-W3-yPt"/>
Expand All @@ -40,6 +37,20 @@
<action selector="loginButtonActionHandler" destination="Pqm-ss-XDF" eventType="touchUpInside" id="OnE-ER-JR6"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2Qq-HF-Nlp">
<rect key="frame" x="187.5" y="617" width="187.5" height="50"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="ZNT-Qn-wem"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<state key="normal" title="Register">
<color key="titleColor" red="0.20000000000000001" green="0.31372549019607843" blue="0.55294117647058827" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="registerButtonActionHandler" destination="Pqm-ss-XDF" eventType="touchUpInside" id="VxJ-No-r2C"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="ytS-rz-p43">
<rect key="frame" x="30" y="552" width="315" height="40"/>
<color key="backgroundColor" red="0.96078431372549022" green="0.96078431372549022" blue="0.96078431372549022" alpha="1" colorSpace="calibratedRGB"/>
Expand All @@ -66,22 +77,28 @@
<outlet property="delegate" destination="Pqm-ss-XDF" id="09J-t3-4no"/>
</connections>
</textField>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="pokedex-title" translatesAutoresizingMaskIntoConstraints="NO" id="26L-yw-rY4">
<rect key="frame" x="67" y="50" width="240" height="100"/>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="uSn-Xg-txX" firstAttribute="centerX" secondItem="NXk-MK-lYr" secondAttribute="centerX" id="4TB-y5-4Jh"/>
<constraint firstItem="ytS-rz-p43" firstAttribute="leading" secondItem="Xhe-Cm-17S" secondAttribute="leading" id="Cwn-4v-Gzd"/>
<constraint firstItem="ytS-rz-p43" firstAttribute="trailing" secondItem="Xhe-Cm-17S" secondAttribute="trailing" id="DiT-XY-xko"/>
<constraint firstItem="lRJ-fR-6hr" firstAttribute="top" secondItem="J3d-o3-YPy" secondAttribute="bottom" id="Nin-OI-2Ir"/>
<constraint firstItem="J3d-o3-YPy" firstAttribute="leading" secondItem="NXk-MK-lYr" secondAttribute="leading" id="O1r-T4-3aF"/>
<constraint firstItem="2Qq-HF-Nlp" firstAttribute="width" secondItem="J3d-o3-YPy" secondAttribute="width" id="UTN-wb-fRD"/>
<constraint firstAttribute="trailing" secondItem="2Qq-HF-Nlp" secondAttribute="trailing" id="UqP-Rd-097"/>
<constraint firstItem="ytS-rz-p43" firstAttribute="top" secondItem="Xhe-Cm-17S" secondAttribute="bottom" constant="20" id="bdE-1Q-Gvm"/>
<constraint firstItem="uSn-Xg-txX" firstAttribute="top" secondItem="26L-yw-rY4" secondAttribute="bottom" id="cFo-gF-GP4"/>
<constraint firstAttribute="trailing" secondItem="J3d-o3-YPy" secondAttribute="trailing" id="g5j-qV-Guc"/>
<constraint firstItem="2Qq-HF-Nlp" firstAttribute="centerY" secondItem="J3d-o3-YPy" secondAttribute="centerY" id="eWt-BT-2KM"/>
<constraint firstItem="26L-yw-rY4" firstAttribute="top" secondItem="ubr-6l-8GZ" secondAttribute="bottom" constant="30" id="kE8-Kh-9da"/>
<constraint firstItem="ytS-rz-p43" firstAttribute="leading" secondItem="NXk-MK-lYr" secondAttribute="leading" constant="30" id="m0b-UP-VEO"/>
<constraint firstItem="lRJ-fR-6hr" firstAttribute="top" secondItem="J3d-o3-YPy" secondAttribute="bottom" id="myl-Lw-KNH"/>
<constraint firstItem="2Qq-HF-Nlp" firstAttribute="leading" secondItem="J3d-o3-YPy" secondAttribute="trailing" id="oOS-BQ-4jq"/>
<constraint firstItem="ytS-rz-p43" firstAttribute="centerX" secondItem="NXk-MK-lYr" secondAttribute="centerX" id="rdc-XS-znj"/>
<constraint firstItem="26L-yw-rY4" firstAttribute="centerX" secondItem="NXk-MK-lYr" secondAttribute="centerX" id="tLk-JB-zVc"/>
<constraint firstItem="26L-yw-rY4" firstAttribute="top" secondItem="ubr-6l-8GZ" secondAttribute="bottom" constant="30" id="uim-sR-YQL"/>
<constraint firstItem="J3d-o3-YPy" firstAttribute="top" secondItem="ytS-rz-p43" secondAttribute="bottom" constant="25" id="wEe-Ki-oI7"/>
</constraints>
<connections>
Expand All @@ -93,9 +110,10 @@
<outlet property="ballImageView" destination="uSn-Xg-txX" id="fAc-nG-RzE"/>
<outlet property="emailTextField" destination="Xhe-Cm-17S" id="f2e-K9-9w7"/>
<outlet property="loginButton" destination="J3d-o3-YPy" id="WyB-Tg-HwJ"/>
<outlet property="loginButtonBottomMargin" destination="Nin-OI-2Ir" id="7bp-Nb-cYv"/>
<outlet property="loginButtonBottomMargin" destination="myl-Lw-KNH" id="HyX-oj-H63"/>
<outlet property="logoImageView" destination="26L-yw-rY4" id="3mL-0u-dh2"/>
<outlet property="passwordTextField" destination="ytS-rz-p43" id="QNq-6h-RZQ"/>
<outlet property="registerButton" destination="2Qq-HF-Nlp" id="Xle-Ap-LmY"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pr7-5o-bas" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 2 additions & 0 deletions Demo/Viper-v2-Demo/Modules/Login/LoginInterfaces.swift
Expand Up @@ -13,6 +13,7 @@ import Alamofire

enum LoginNavigationOption {
case home
case register
}

protocol LoginWireframeInterface: WireframeInterface {
Expand All @@ -24,6 +25,7 @@ protocol LoginViewInterface: ViewInterface {

protocol LoginPresenterInterface: PresenterInterface {
func didSelectLoginAction(with email: String?, password: String?)
func didSelectRegisterAction()
}

protocol LoginInteractorInterface: InteractorInterface {
Expand Down
4 changes: 4 additions & 0 deletions Demo/Viper-v2-Demo/Modules/Login/LoginPresenter.swift
Expand Up @@ -63,6 +63,10 @@ extension LoginPresenter: LoginPresenterInterface {
}
}

func didSelectRegisterAction() {
_wireframe.navigate(to: .register)
}

private func _handleLoginResult(_ result: Result<User>) {
switch result {
case .success(let jsonObject):
Expand Down
7 changes: 6 additions & 1 deletion Demo/Viper-v2-Demo/Modules/Login/LoginViewController.swift
Expand Up @@ -24,7 +24,8 @@ final class LoginViewController: UIViewController {

@IBOutlet private weak var loginButton: UIButton!
@IBOutlet private weak var loginButtonBottomMargin: NSLayoutConstraint!

@IBOutlet private weak var registerButton: UIButton!

// MARK: - Lifecycle -

override func viewDidLoad() {
Expand Down Expand Up @@ -52,6 +53,10 @@ final class LoginViewController: UIViewController {
)
}

@IBAction func registerButtonActionHandler() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be private.

presenter.didSelectRegisterAction()
}

@IBAction func tapGestureRecognizerActionHandler() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be private.

view.endEditing(true)
}
Expand Down