Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
da5583b
Inclui estrutura inicial do projeto
erikaaseg Aug 3, 2019
502cf6e
Inclui classes do dominio
erikaaseg Aug 10, 2019
574d0e1
Implementa caso de uso com chamada à API
erikaaseg Aug 11, 2019
4322b10
Cria tab view principal;Cria a formView com os 5 tipos de células(la…
erikaaseg Aug 18, 2019
f256214
Inclui preenchimento e validação do form
erikaaseg Aug 20, 2019
1b60153
Inclui tela de sucesso ao enviar form
erikaaseg Aug 20, 2019
96ff159
Inclui tratamento de espera pelo envio do formulário
erikaaseg Aug 20, 2019
5b35247
Inclui testes unitários da FormViewPresenter
erikaaseg Aug 21, 2019
ff28c73
Coloca células da tabela FormViewController em arquivos separados pa…
erikaaseg Aug 24, 2019
2e28538
Corrige protocolo
erikaaseg Aug 24, 2019
9d36cfc
Inclui primeiras informações do investimento na tela
erikaaseg Aug 25, 2019
612c2d1
Inclui linhas de "more info" no investimento
erikaaseg Aug 27, 2019
6489f51
Inclui informações faltantes no investimento;
erikaaseg Aug 27, 2019
816dfb6
Inclui texto padrão no botão de "downInfo" de um investimento
erikaaseg Aug 27, 2019
ee4afcb
Implementa SafariViewController
erikaaseg Aug 27, 2019
9503fe4
Inclui tematização da tela de contato
erikaaseg Aug 27, 2019
85be77e
Inclui testes do FundViewPresenter
erikaaseg Aug 27, 2019
141c74c
Adiciona gitignore
erikaaseg Aug 27, 2019
e15aac5
Adiciona gitignore
erikaaseg Aug 27, 2019
ec833cc
Configura projeto para iOS 9.0;
erikaaseg Aug 27, 2019
ee3aaaf
Update README.md
erikaaseg Aug 27, 2019
49382bf
Update README.md
erikaaseg Aug 27, 2019
1629dc4
Update README.md
erikaaseg Aug 27, 2019
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pods/
*.xcworkspace
Podfile.lock
19 changes: 19 additions & 0 deletions Domain/Domain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Model.h
// Model
//
// Created by Erika de Almeida Segatto on 06/09/18.
// Copyright © 2018 Erika de Almeida Segatto. All rights reserved.
//

#import <UIKit/UIKit.h>

//! Project version number for Model.
FOUNDATION_EXPORT double ModelVersionNumber;

//! Project version string for Model.
FOUNDATION_EXPORT const unsigned char ModelVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <Model/PublicHeader.h>


24 changes: 24 additions & 0 deletions Domain/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
17 changes: 17 additions & 0 deletions Domain/Model/CellType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CellType.swift
// Domain
//
// Created by Erika de Almeida Segatto on 03/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation

public enum CellType: Int {
case field = 1
case text = 2
case image = 3
case checkbox = 4
case send = 5
}
40 changes: 40 additions & 0 deletions Domain/Model/FieldType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// FieldType.swift
// Domain
//
// Created by Erika de Almeida Segatto on 03/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation

public enum FieldType: Int {
case text = 1
case telNumber = 2
case email = 3

static func get(_ type: String) -> FieldType? {
if let intType = type.asInt() {
return FieldType(rawValue: intType)
}
if type.uppercased() == "TEXT" {
return .text
}
if type.uppercased() == "TELNUMBER" {
return .telNumber
}
if type.uppercased() == "EMAIL" {
return .email
}
return .text
}

public func isValid(_ text: String) -> Bool {
switch self {
case .email: return text.isValidEmail()
case .telNumber: return text.isValidPhone()
case .text: return (text.count >= 1)
}
}
}

37 changes: 37 additions & 0 deletions Domain/Model/FormCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// FormCell.swift
// Domain
//
// Created by Erika de Almeida Segatto on 03/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation


public class FormCell {
public let id: Int
public let cellType: CellType
public let fieldType: FieldType
public let message: String
public let topSpacing: Double
public let show: Int?
public let hidden: Bool
public let required: Bool

public var input: Any? = nil

public init(id: Int, cellType: Int, fieldType: String, message: String, topSpacing: Double, show: Int?, hidden: Bool, required: Bool) throws {

guard let cellType = CellType(rawValue: cellType) else { throw DomainError.invalidCellType }
guard let fieldType = FieldType.get(fieldType) else { throw DomainError.invalidFieldType }
self.id = id
self.cellType = cellType
self.fieldType = fieldType
self.message = message
self.topSpacing = topSpacing
self.show = show
self.hidden = hidden
self.required = required
}
}
60 changes: 60 additions & 0 deletions Domain/Model/Fund.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Fund.swift
// Domain
//
// Created by Erika de Almeida Segatto on 03/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation

public struct FundValueInfo {
public let month: (fund: Double, cdi: Double)
public let year: (fund: Double, cdi: Double)
public let twelveMonths: (fund: Double, cdi: Double)

public init(monthFund: Double, monthCdi: Double, yearFund: Double, yearCdi: Double, twelveMonthsFund: Double, twelveMonthsCdi: Double) {
self.month = (monthFund, monthCdi)
self.year = (yearFund, yearCdi)
self.twelveMonths = (twelveMonthsFund, twelveMonthsCdi)
}
}

public struct FundInfo {
public var name: String
public var data: String

public init(name: String, data: String) {
self.name = name
self.data = data
}
}


public class Fund {
public let id: String
public let title: String
public let fundName: String
public let whatIs: String
public let definition: String
public let riskTitle: String
public let risk: Int
public let infoTitle: String
public let moreInfo: FundValueInfo
public let info: [FundInfo]
public let downInfo: [FundInfo]

public init(id: String, title: String, fundName: String, whatIs: String, definition: String, riskTitle: String, risk: Int, infoTitle: String, monthFund: Double, monthCdi: Double, yearFund: Double, yearCdi: Double, twelveMonthsFund: Double, twelveMonthsCdi: Double, info: [FundInfo], downInfo: [FundInfo]) {
self.id = id
self.title = title
self.fundName = fundName
self.whatIs = whatIs
self.definition = definition
self.riskTitle = riskTitle
self.risk = risk
self.infoTitle = infoTitle
self.moreInfo = FundValueInfo(monthFund: monthFund, monthCdi: monthCdi, yearFund: yearFund, yearCdi: yearCdi, twelveMonthsFund: twelveMonthsFund, twelveMonthsCdi: twelveMonthsCdi)
self.info = info
self.downInfo = downInfo
}
}
19 changes: 19 additions & 0 deletions Domain/Number+ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Number+ext.swift
// Domain
//
// Created by Erika de Almeida Segatto on 26/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation


extension Double {
public func formatAsPercentage() -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 2
return (formatter.string(from: self as NSNumber) ?? String(format: "%.2f", self)) + "%"
}
}
85 changes: 85 additions & 0 deletions Domain/String+ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// String+ext.swift
// Platform
//
// Created by Erika Segatto on 19/03/18.
// Copyright © 2018 evologica. All rights reserved.
//

import Foundation

extension String {


func asInt() -> Int? {
if let number = self.asNumber() {
return Int(exactly: number)
}
return nil
}

func asNumber() -> NSNumber? {
let numFormatter = NumberFormatter()
numFormatter.decimalSeparator = "."
if let number = numFormatter.number(from: self){
return number
}
numFormatter.decimalSeparator = ","
return numFormatter.number(from: self)
}


// MARK: String Format
public func formatAsPhone() -> String {
let cleanString = String(self.formatAsNumeric().prefix(11))

switch cleanString.count {
case 11: return cleanString.applyMask(mask: "(**) *****-****")
default: return cleanString.applyMask(mask: "(**) ****-****")
}
}

func formatAsNumeric() -> String {
return self.replacingOccurrences(of:"[^0-9]", with: "", options: .regularExpression)
}


private func applyMask(mask: String) -> String {
var result = ""

var maskIndex = mask.startIndex
var selfIndex = self.startIndex

while selfIndex.encodedOffset != self.endIndex.encodedOffset {
if mask[maskIndex] == "*" {
result.append(self[selfIndex])
selfIndex = self.index(after: selfIndex)
} else {
result.append(mask[maskIndex])
}
maskIndex = mask.index(after: maskIndex)
if maskIndex.encodedOffset == mask.endIndex.encodedOffset {
result.append(String(self.suffix(from: selfIndex)))
return result
}
}

return result
}

// MARK: is Valid

func isValidEmail() -> Bool {
let emailFormat = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailFormat)
return emailPredicate.evaluate(with: self)
}

func isValidPhone() -> Bool {
let formatedPhoneFormat = "\\([0-9]{2}\\) ?[0-9]{4,5}-[0-9]{4}"
let unformatedPhoneFormat = "[0-9]{10,11}"
let predicate = NSPredicate(format: "SELF MATCHES %@ OR SELF MATCHES %@", formatedPhoneFormat, unformatedPhoneFormat)
return predicate.evaluate(with: self)
}

}
17 changes: 17 additions & 0 deletions Domain/UseCases/ApiUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ApiUseCase.swift
// Domain
//
// Created by Erika de Almeida Segatto on 03/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation
import RxSwift


public protocol ApiUseCase {
func getFormFields() -> Observable<[FormCell]>
func getFundInfo() -> Observable<Fund>
func sendForm(_ form: [FormCell]) -> Observable<Void>
}
26 changes: 26 additions & 0 deletions Domain/UseCases/DomainError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// DomainError.swift
// Domain
//
// Created by Erika de Almeida Segatto on 10/08/19.
// Copyright © 2019 Erika de Almeida Segatto. All rights reserved.
//

import Foundation

public enum DomainError: Error {
case invalidCellType
case invalidFieldType
}


extension DomainError: LocalizedError {
public var errorDescription: String? {
switch self {
case .invalidCellType:
return "Cell Type not identified"
case .invalidFieldType:
return "Field Type not identified"
}
}
}
Loading