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

Add logout button (clear user token ) #84

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Papr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1090D75275C09BAE87BE25BD /* Pods_Papr.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D778F2E1EFA76CEB59A377CB /* Pods_Papr.framework */; };
63CC2B27C8EE9499B1D6C702 /* Pods_PaprTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD3D8A956FB1C8A8D3B456A7 /* Pods_PaprTests.framework */; };
B15C6FAD2280A44F008D641D /* ButtonRounded.swift in Sources */ = {isa = PBXBuildFile; fileRef = B15C6FAC2280A44F008D641D /* ButtonRounded.swift */; };
C006934F2189DB4500AC6736 /* CollectionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C006934D2189DB4500AC6736 /* CollectionCell.xib */; };
C00739572151547500F51C91 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C00739562151547500F51C91 /* LoadingView.swift */; };
C09D7656216CC91E0035F54D /* UserProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09D7654216CC91E0035F54D /* UserProfileViewController.swift */; };
Expand Down Expand Up @@ -361,6 +362,7 @@
54A367A7275D753D93ACC1AB /* Pods-Papr.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Papr.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Papr/Pods-Papr.debug.xcconfig"; sourceTree = "<group>"; };
73C64AFFEE5BB0DA9AE1AB4D /* Pods-Papr.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Papr.release.xcconfig"; path = "Pods/Target Support Files/Pods-Papr/Pods-Papr.release.xcconfig"; sourceTree = "<group>"; };
7ADA4A068C8B3E3A9F491B6C /* Pods-PaprUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PaprUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PaprUITests/Pods-PaprUITests.release.xcconfig"; sourceTree = "<group>"; };
B15C6FAC2280A44F008D641D /* ButtonRounded.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonRounded.swift; sourceTree = "<group>"; };
C006934D2189DB4500AC6736 /* CollectionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CollectionCell.xib; sourceTree = "<group>"; };
C00739562151547500F51C91 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
C09D7654216CC91E0035F54D /* UserProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfileViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -779,6 +781,7 @@
DCB915AE20B9A8DE003D1069 /* PinterestLayout.swift */,
DC3918CE21046AE8003DA2CA /* PaprNavigationController.swift */,
DC487F482104FCB00042DBBC /* BouncyView.swift */,
B15C6FAC2280A44F008D641D /* ButtonRounded.swift */,
);
path = "Custom UI";
sourceTree = "<group>";
Expand Down Expand Up @@ -1368,6 +1371,7 @@
C0CD2444213EB2BD0053A802 /* CollectionsViewController.swift in Sources */,
DCBB1B5B1FA8B840004E95F0 /* SceneTransitionType.swift in Sources */,
DCB915B520BB1A9A003D1069 /* SearchPhotosCell.swift in Sources */,
B15C6FAD2280A44F008D641D /* ButtonRounded.swift in Sources */,
DC5AF7591FAD2F1E00ADA2BB /* OrderBy.swift in Sources */,
DCBB1B671FA8BA39004E95F0 /* LoginViewModel.swift in Sources */,
DC487F432104F0970042DBBC /* ClassIdentifiable.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Papr/Commons/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Constants {

struct Style {
static let imageCornersRadius: CGFloat = 8.0
static let imageCornersRadiusWidth: CGFloat = 3.0
}
}

Expand Down
109 changes: 109 additions & 0 deletions Papr/Custom UI/ButtonRounded.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// ButtonRounded.swift
// Papr
//
// Created by imo on 6.05.19.
// Copyright © 2019 Joan Disho. All rights reserved.
//

import Foundation
import UIKit

enum ButtonRoundedStyle {
case border, fill
}

class ButtonRounded: UIButton {

var style: ButtonRoundedStyle = .border

public func configure(type: ButtonRoundedStyle) {
style = type
setNeedsLayout()
layoutIfNeeded()
}

override func layoutSubviews() {
super.layoutSubviews()

layer.cornerRadius = Constants.Appearance.Style.imageCornersRadius
backgroundColor = .clear

if style == .border {
layer.borderWidth = Constants.Appearance.Style.imageCornersRadiusWidth
layer.borderColor = UIColor.black.cgColor
layer.backgroundColor = UIColor.white.cgColor

setTitleColor(.black, for: .normal)

} else {
layer.borderColor = UIColor.clear.cgColor
layer.backgroundColor = UIColor.black.cgColor

setTitleColor(.white, for: .normal)
}
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
borderDissapear(highlighted: true)
titleDissapear(highlighted: true)
backgroundDissapear(highlighted: true)
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
borderDissapear(highlighted: false)
titleDissapear(highlighted: false)
backgroundDissapear(highlighted: false)
}

func borderDissapear (highlighted: Bool) {
let animation = CABasicAnimation(keyPath: "borderColor")
animation.duration = 0.1
animation.autoreverses = false
animation.repeatCount = 1
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
if highlighted {
animation.fromValue = self.layer.borderColor?.copy(alpha: 1)
animation.toValue = self.layer.borderColor?.copy(alpha: 0.3)
} else if !highlighted {
animation.fromValue = self.layer.borderColor?.copy(alpha: 0.3)
animation.toValue = self.layer.borderColor?.copy(alpha: 1)
}
self.layer.add(animation, forKey: "borderColor")
}

func titleDissapear (highlighted: Bool) {
if !highlighted {
self.titleLabel?.textColor = self.titleLabel?.textColor.withAlphaComponent(0.3)
} else {
self.titleLabel?.textColor = self.titleLabel?.textColor.withAlphaComponent(1)
}

UIView.animate(withDuration: 0.1, delay: 0, options: [.transitionCrossDissolve, .beginFromCurrentState], animations: {
if highlighted {
self.titleLabel?.textColor = self.titleLabel?.textColor.withAlphaComponent(0.3)
} else {
self.titleLabel?.textColor = self.titleLabel?.textColor.withAlphaComponent(1)
}
}, completion: nil)
}

func backgroundDissapear (highlighted: Bool) {
let animation = CABasicAnimation(keyPath: "backgroundColor")
animation.duration = 0.1
animation.autoreverses = false
animation.repeatCount = 1
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
if highlighted {
animation.fromValue = self.layer.backgroundColor?.copy(alpha: 1)
animation.toValue = self.layer.backgroundColor?.copy(alpha: 0.3)
} else if !highlighted {
animation.fromValue = self.layer.backgroundColor?.copy(alpha: 0.3)
animation.toValue = self.layer.backgroundColor?.copy(alpha: 1)
}
self.layer.add(animation, forKey: "backgroundColor")
}

}
17 changes: 15 additions & 2 deletions Papr/Scenes/UserProfile/UserProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@
//

import UIKit
import RxSwift

class UserProfileViewController: UIViewController, BindableType {

@IBOutlet weak var logoutButton: ButtonRounded!

var viewModel: UserProfileViewModel!


private let disposeBag = DisposeBag()

override func viewDidLoad() {
super.viewDidLoad()

logoutButton.configure(type: .border)

title = "User profile"
}

func bindViewModel() {}
func bindViewModel() {
let inputs = viewModel.inputs

logoutButton.rx.action = inputs.logoutAction
}
}
27 changes: 21 additions & 6 deletions Papr/Scenes/UserProfile/UserProfileViewController.xib
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_0" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UserProfileViewController" customModule="Papr" customModuleProvider="target">
<connections>
<outlet property="logoutButton" destination="FVq-Z3-qKZ" id="3dE-ar-YNL"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="UserProfile" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wAS-DG-yI9">
<rect key="frame" x="16" y="333" width="343" height="21"/>
<rect key="frame" x="16" y="283.5" width="288" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FVq-Z3-qKZ" customClass="ButtonRounded" customModule="Papr" customModuleProvider="target">
<rect key="frame" x="24" y="496" width="272" height="48"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="fUB-pd-MMd"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="16"/>
<state key="normal" title="Log out">
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="FVq-Z3-qKZ" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="4cE-f9-dfX"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="FVq-Z3-qKZ" secondAttribute="bottom" constant="24" id="GAi-de-TAY"/>
<constraint firstItem="wAS-DG-yI9" firstAttribute="centerY" secondItem="fnl-2z-Ty3" secondAttribute="centerY" id="ULU-NX-HrU"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="FVq-Z3-qKZ" secondAttribute="trailing" constant="24" id="YKr-7R-vH9"/>
<constraint firstItem="wAS-DG-yI9" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="aek-Lf-LsA"/>
<constraint firstItem="FVq-Z3-qKZ" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="24" id="hyO-dG-Ejb"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="wAS-DG-yI9" secondAttribute="trailing" constant="16" id="iek-82-xAH"/>
</constraints>
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
Expand Down
34 changes: 33 additions & 1 deletion Papr/Scenes/UserProfile/UserProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,39 @@

import Foundation
import RxSwift
import Action

class UserProfileViewModel {
protocol UserProfileViewModelInput {
var logoutAction: CocoaAction { get }
}

protocol UserProfileViewModelOutput {
}

protocol UserProfileViewModelType {
var inputs: UserProfileViewModelInput { get }
var outputs: UserProfileViewModelOutput { get }
}

class UserProfileViewModel: UserProfileViewModelType, UserProfileViewModelInput, UserProfileViewModelOutput {

var inputs: UserProfileViewModelInput { return self }
var outputs: UserProfileViewModelOutput { return self }


// MARK: Private
private let sceneCoordinator: SceneCoordinatorType

init(sceneCoordinator: SceneCoordinatorType = SceneCoordinator.shared) {
self.sceneCoordinator = sceneCoordinator
}


lazy var logoutAction: CocoaAction = {
return CocoaAction { _ in
UnsplashAuthManager.shared.clearAccessToken()

return self.sceneCoordinator.transition(to: Scene.papr)
}
}()
}
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 7bb83ef22953fe01a8077c84b732c839ebdb4a78

COCOAPODS: 1.6.0.beta.2
COCOAPODS: 1.6.1