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

Babacros todayextension #17

Open
wants to merge 22 commits into
base: babacros
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
243 changes: 241 additions & 2 deletions ISICbalance.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions ISICbalance/Assets.xcassets/todayExtension.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Icon-180.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ISICbalance/Generated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal enum Asset {
internal static let janmisar = ImageAsset(name: "janmisar")
internal static let mightycreations = ImageAsset(name: "mightycreations")
internal static let reloadIcon = ImageAsset(name: "reloadIcon")
internal static let todayExtension = ImageAsset(name: "todayExtension")
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name

Expand Down
14 changes: 14 additions & 0 deletions ISICbalance/ISICbalance.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.eu.cz.babacros.ISICbalance</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>eu.cz.babacros.ISICbalance.keychaingroup</string>
</array>
</dict>
</plist>
14 changes: 14 additions & 0 deletions ISICbalance/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(APP_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>eu.cz.babacros.ISICbalance</string>
</dict>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>ISICbalance</string>
</array>
</dict>
<dict/>
</array>
<key>CFBundleVersion</key>
<string>BUILD_NUMBER</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
17 changes: 9 additions & 8 deletions ISICbalance/Services/KeychainManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
import Foundation
import ReactiveSwift
import SwiftKeychainWrapper
import Result

protocol HasKeychainManager {
var keychainManager: KeychainManagering { get }
}

protocol KeychainManagering {
func saveCredentials(username: String, password: String) -> SignalProducer<(),LoginError>
func getCredentialsFromKeychain() -> SignalProducer<User, NoError>
func getCredentialsFromKeychain() -> SignalProducer<User, Never>
}

final class KeychainManager: KeychainManagering {
func saveCredentials(username: String, password: String) -> SignalProducer<(),LoginError> {
return SignalProducer { observer, _ in
let saveUsername: Bool = KeychainWrapper.standard.set(username, forKey: "username")
let savePassword: Bool = KeychainWrapper.standard.set(password, forKey: "password")
let wrapper = KeychainWrapper(serviceName: "eu.cz.babacros", accessGroup: "eu.cz.babacros.ISICbalance.keychaingroup")
let saveUsername: Bool = wrapper.set(username, forKey: "username")
let savePassword: Bool = wrapper.set(password, forKey: "password")

if saveUsername && savePassword {
observer.sendCompleted()
Expand All @@ -34,10 +34,11 @@ final class KeychainManager: KeychainManagering {
}
}

func getCredentialsFromKeychain() -> SignalProducer<User, NoError> {
return SignalProducer<User, NoError> { observer, _ in
let username = KeychainWrapper.standard.string(forKey: "username") ?? ""
let password = KeychainWrapper.standard.string(forKey: "password") ?? ""
func getCredentialsFromKeychain() -> SignalProducer<User, Never> {
return SignalProducer<User, Never> { observer, _ in
let wrapper = KeychainWrapper(serviceName: "eu.cz.babacros", accessGroup: "eu.cz.babacros.ISICbalance.keychaingroup")
let username = wrapper.string(forKey: "username") ?? ""
let password = wrapper.string(forKey: "password") ?? ""
let user = User(username: username, password: password)

observer.send(value: user)
Expand Down
9 changes: 0 additions & 9 deletions ISICbalance/Services/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Alamofire
import SwiftSoup
import SwiftKeychainWrapper
import ReactiveSwift
import Result

protocol HasRequestManager {
var requestManager: RequestManagering { get }
Expand Down Expand Up @@ -159,8 +158,6 @@ final class RequestManager: RequestManagering {
Alamofire.request("https://agata.suz.cvut.cz/secure/index.php").responseString { response in
switch response.result {
case .success:
// TODO: delete after dev
print("Agata request success")
observer.send(value: response)
observer.sendCompleted()
case .failure:
Expand All @@ -175,8 +172,6 @@ final class RequestManager: RequestManagering {
Alamofire.request(urlString).responseString { responseShibboleth in
switch responseShibboleth.result {
case .success:
// TODO: delete after dev
print("SSO request success")
observer.send(value: responseShibboleth)
observer.sendCompleted()
case .failure:
Expand All @@ -191,8 +186,6 @@ final class RequestManager: RequestManagering {
Alamofire.request(credentialsUrl, method: .post, parameters: parameters).responseString { responseCredentials in
switch responseCredentials.result {
case .success:
// TODO: delete after dev
print("Credentials request success")
observer.send(value: responseCredentials)
observer.sendCompleted()
case .failure:
Expand All @@ -207,8 +200,6 @@ final class RequestManager: RequestManagering {
Alamofire.request(action, method: .post, parameters: formParameters) .responseString { responseBalanceSite in
switch responseBalanceSite.result {
case .success:
// TODO: delete after dev
print("Balance site request success")
observer.send(value: responseBalanceSite)
observer.sendCompleted()
case .failure:
Expand Down
5 changes: 3 additions & 2 deletions ISICbalance/ViewControllers/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class AccountViewController: BaseViewController, ValidateErrorPresentable {
}

// MARK: - Bindings
func setupBindings() {
private func setupBindings() {
usernameTextField <~> viewModel.username
passwordTextField <~> viewModel.password
loginButton.reactive.isEnabled <~ viewModel.actions.login.isExecuting.negate()
Expand All @@ -124,7 +124,8 @@ class AccountViewController: BaseViewController, ValidateErrorPresentable {
}

// MARK: - Actions
@objc func saveCredentials() {
@objc
private func saveCredentials(_ sender: UIButton) {
viewModel.actions.login.apply().start()
}
}
22 changes: 14 additions & 8 deletions ISICbalance/ViewControllers/BalanceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BalanceViewController: BaseViewController {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
accountButton.addTarget(self, action: #selector(accountBtnHandle), for: .touchUpInside)
reloadButton.addTarget(self, action: #selector(reloadBalance), for: .touchUpInside)
reloadButton.addTarget(self, action: #selector(reloadBtnHandle), for: .touchUpInside)
setupBindings()
}

Expand All @@ -87,7 +87,7 @@ class BalanceViewController: BaseViewController {
}

// MARK: - UI setup
fileprivate func setupBalanceField() {
private func setupBalanceField() {
let balanceTitle = UILabel()
balanceTitle.text = L10n.Balance.title
balanceTitle.textColor = UIColor.theme.labelBlue
Expand All @@ -105,7 +105,7 @@ class BalanceViewController: BaseViewController {
screenStackView.addArrangedSubview(balanceLabel)
}

fileprivate func setupButtonsStack() {
private func setupButtonsStack() {
let reloadButton = UIButton()
reloadButton.setImage(Asset.reloadIcon.image, for: .normal)
self.reloadButton = reloadButton
Expand All @@ -121,8 +121,8 @@ class BalanceViewController: BaseViewController {
}

// MARK: - Bindings
func setupBindings() {
self.balanceLabel.reactive.text <~ viewModel.localeBalance
private func setupBindings() {
balanceLabel.reactive.text <~ viewModel.localeBalance
// push accountViewController if there is some error duting balanceAction
viewModel.actions.getBalance.errors
.observe(on: UIScheduler())
Expand All @@ -136,19 +136,25 @@ class BalanceViewController: BaseViewController {
viewModel.actions.getBalance.completed
.observe(on: UIScheduler())
.observeValues {
SVProgressHUD.dismiss()
SVProgressHUD.dismiss(withDelay: 1)
}
}

// MARK: - Actions
@objc func reloadBalance() {
private func reloadBalance() {
DispatchQueue.main.async {
SVProgressHUD.show(withStatus: L10n.Balance.loading)
}
viewModel.actions.getBalance.apply().start()
}

@objc
private func reloadBtnHandle(_ sender: UIButton) {
reloadBalance()
}

@objc func accountBtnHandle() {
@objc
private func accountBtnHandle(_ sender: UIButton) {
flowDelegate?.accountButtonTapped(in: self)
}
}
8 changes: 3 additions & 5 deletions ISICbalance/ViewModels/AccountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import ReactiveSwift
import Result
import SwiftKeychainWrapper

protocol AccountViewModeling {
Expand All @@ -19,7 +18,7 @@ protocol AccountViewModeling {
}

protocol AccountViewModelingActions {
var login: Action<(),(),LoginError> { get }
var login: Action<Void,Void,LoginError> { get }
Copy link
Contributor

Choose a reason for hiding this comment

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

ještě mezery a bude to 🔝 nejlepší by bylo, kdybys nasadil Swiftlint

}

extension AccountViewModelingActions where Self: AccountViewModeling {
Expand All @@ -32,11 +31,10 @@ final class AccountViewModel: BaseViewModel, AccountViewModeling, AccountViewMod
let username: MutableProperty<String>
let password: MutableProperty<String>

let login: Action<(),(),LoginError>
let login: Action<Void,Void,LoginError>

// MARK: - Initialization
init(dependencies: Dependencies) {

username = MutableProperty("")
password = MutableProperty("")

Expand All @@ -57,7 +55,7 @@ final class AccountViewModel: BaseViewModel, AccountViewModeling, AccountViewMod
if validationErrors.isEmpty {
return dependencies.keychainManager.saveCredentials(username: username, password: password)
} else {
return SignalProducer<(), LoginError>(error: LoginError.validation(message: L10n.Validate.errorMessage))
return SignalProducer<Void, LoginError>(error: LoginError.validation(message: L10n.Validate.errorMessage))
}
}

Expand Down
8 changes: 3 additions & 5 deletions ISICbalance/ViewModels/BalanceViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
import Result
import ReactiveSwift
import Alamofire
import UIKit

protocol BalanceViewModeling {
Expand All @@ -19,7 +17,7 @@ protocol BalanceViewModeling {
}

protocol BalanceViewModelingActions {
var getBalance: Action<(),Balance,RequestError> { get }
var getBalance: Action<Void,Balance,RequestError> { get }
}

extension BalanceViewModelingActions where Self: BalanceViewModeling {
Expand All @@ -31,7 +29,7 @@ final class BalanceViewModel: BaseViewModel, BalanceViewModeling, BalanceViewMod

let balance: Property<Int>
let localeBalance: Property<String>
let getBalance: Action<(),Balance,RequestError>
let getBalance: Action<Void,Balance,RequestError>

// MARK: - Initialization
init(dependencies: Dependencies) {
Expand All @@ -41,7 +39,7 @@ final class BalanceViewModel: BaseViewModel, BalanceViewModeling, BalanceViewMod

balance = Property<Int>(initial: 0, then: getBalance.values.map { $0.balance })

localeBalance = Property(initial: " ", then: balance.producer.map { $0.asLocalCurrency() })
localeBalance = Property<String>(initial: " ", then: balance.producer.map { $0.asLocalCurrency() })

super.init()
}
Expand Down
39 changes: 39 additions & 0 deletions ISICbalanceExtension/Base.lproj/MainInterface.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Today View Controller-->
<scene sceneID="cwh-vc-ff4">
<objects>
<viewController id="M4Y-Lb-cyx" customClass="TodayViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN">
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello World" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="GcN-lo-r42">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="ssy-KU-ocm" firstAttribute="bottom" secondItem="GcN-lo-r42" secondAttribute="bottom" constant="20" symbolic="YES" id="0Q0-KW-PJ6"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="leading" secondItem="ssy-KU-ocm" secondAttribute="leading" constant="20" symbolic="YES" id="6Vq-gs-PHe"/>
<constraint firstItem="ssy-KU-ocm" firstAttribute="trailing" secondItem="GcN-lo-r42" secondAttribute="trailing" constant="20" symbolic="YES" id="L8K-9R-egU"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="top" secondItem="ssy-KU-ocm" secondAttribute="top" constant="20" symbolic="YES" id="mYS-Cv-VNx"/>
</constraints>
<viewLayoutGuide key="safeArea" id="ssy-KU-ocm"/>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="320" height="37"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
14 changes: 14 additions & 0 deletions ISICbalanceExtension/ISICbalanceExtension.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.eu.cz.babacros.ISICbalance</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>eu.cz.babacros.ISICbalance.keychaingroup</string>
</array>
</dict>
</plist>
Loading