Skip to content
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
15 changes: 15 additions & 0 deletions SantanderApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
/.idea/
8 changes: 8 additions & 0 deletions SantanderApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Teste Raphael Castro Martin

## Executando o projeto
Para testar o aplicativo basta abrir o diretório SantanderApp com o Android Studio, selecionar o dispositivo que irá executar o aplicativo no AVD Manager, e no menu Run clicar em Run...

## Executando testes unitários
Para executar os testes unitários e obter relatório de cobertura de código basta clicar com o botão direito na pasta do módulo app no Android Studio e clicar em Run 'All Tests' with Coverage

1 change: 1 addition & 0 deletions SantanderApp/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions SantanderApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.qintess.santanderapp"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

testOptions {
unitTests.includeAndroidResources = true
unitTests {
returnDefaultValues = true
includeAndroidResources = true
}
}

}

dependencies {
// Libs do app
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation("com.squareup.okhttp3:okhttp:4.7.2")

// Libs de teste
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'org.json:json:20180813'
}
21 changes: 21 additions & 0 deletions SantanderApp/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
26 changes: 26 additions & 0 deletions SantanderApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.qintess.santanderapp">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup">
<activity android:name=".ui.view.statementsScreen.StatementsActivity" />
<activity android:name=".ui.view.loginScreen.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.qintess.santanderapp.helper

import android.annotation.SuppressLint
import java.math.RoundingMode
import java.text.DateFormat
import java.text.DecimalFormat
import java.text.NumberFormat
import java.text.SimpleDateFormat
import java.util.*

object Formatter {
fun formatMoney(value: Double): String {
val formatter = getMoneyFormatter()
return formatter.format(value)
}

fun formatDate(strDate: String): String {
val toDateFormatter = getDateFormatterStringToDate()
val toStringFormatter = getDateFormatterDateToString()

val date = toDateFormatter.parse(strDate)
return toStringFormatter.format(date)
}

private fun getMoneyFormatter(): DecimalFormat {
val nf = NumberFormat.getInstance(Locale.US) as DecimalFormat
nf.roundingMode = RoundingMode.HALF_UP
nf.minimumFractionDigits = 2
nf.maximumFractionDigits = 2

val symbols = nf.decimalFormatSymbols
symbols.groupingSeparator = '.'
symbols.decimalSeparator = ','
nf.decimalFormatSymbols = symbols

nf.positivePrefix = "R$ "
nf.negativePrefix = "R$ -"

return nf
}

@SuppressLint("SimpleDateFormat")
private fun getDateFormatterStringToDate(): DateFormat {
return SimpleDateFormat("yyyy-MM-dd")
}

@SuppressLint("SimpleDateFormat")
private fun getDateFormatterDateToString(): DateFormat {
return SimpleDateFormat("dd/MM/yyyy")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.qintess.santanderapp.helper

import org.json.JSONArray
import org.json.JSONObject

fun JSONArray.forEach(callback: (JSONObject) -> Unit) {
for (i in 0 until this.length()) {
callback(this.getJSONObject(i))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.qintess.santanderapp.helper

import android.content.Context
import android.content.SharedPreferences
import com.qintess.santanderapp.BuildConfig

class Prefs(ctx: Context) {
enum class Key(val value: String?) {
LastUser("LAST_USER")
}

private val PREFS_FILE_NAME = BuildConfig.APPLICATION_ID
private var sharedPreferences: SharedPreferences

init {
sharedPreferences = ctx.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE)
}

fun putString(key: Key, value: String) {
with(sharedPreferences.edit()) {
putString(key.value, value)
commit()
}
}

fun getString(key: Key): String? {
return sharedPreferences.getString(key.value, null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.qintess.santanderapp.helper

class Validator {
companion object {
const val LOGIN_TITLE_ERROR = "Não foi possível realizar o login"

const val CREDENTIALS_TITLE_ERROR = "Credenciais inválidas"
const val USER_ERROR = "Preencha um usuário válido. O usuário deve ser um CPF ou e-mail"
const val PASS_ERROR = "Preencha uma senha válida. A senha deve conter uma letra maiúsula, um caractere especial e um número."

const val STATEMENTS_TITLE_ERROR = "Não foi possível buscar os lançamentos"

fun isEmailValid(email: String): Boolean {
val pattern = "[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}".toRegex()
return email.matches(pattern)
}

fun isCpfValid(cpf: String): Boolean {
val mask = Regex("[.-]")
val unmasked_cpf = mask.replace(cpf, "")

if (unmasked_cpf.length != 11) {
return false
}

val numbers = arrayListOf<Int>()

unmasked_cpf.filter { it.isDigit() }.forEach {
numbers.add(it.toString().toInt())
}

if (numbers.size != 11) return false

//repeticao
(0..9).forEach { n ->
val digits = arrayListOf<Int>()
(0..10).forEach { digits.add(n) }
if (numbers == digits) return false
}

//digito 1
val dv1 = ((0..8).sumBy { (it + 1) * numbers[it] }).rem(11).let {
if (it >= 10) 0 else it
}

val dv2 = ((0..8).sumBy { it * numbers[it] }.let { (it + (dv1 * 9)).rem(11) }).let {
if (it >= 10) 0 else it
}

return numbers[9] == dv1 && numbers[10] == dv2
}

fun isPasswordValid(password: String): Boolean {
if (
!password.matches(".*[A-Z].*".toRegex()) ||
!password.matches(".*[!@#\$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>/?].*".toRegex()) ||
!password.matches(".*[0-9].*".toRegex())
) {
return false
}

return true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.qintess.santanderapp.model

data class CredentialsModel(val user: String, val password: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.qintess.santanderapp.model

enum class StatementType(val value: String) {
Debit("Pagamento"),
Credit("Recebimento")
}

data class StatementModel(val title: String,
val desc: String,
val date: String,
val value: Double,
val type: StatementType)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.qintess.santanderapp.model

import android.os.Parcel
import android.os.Parcelable

data class UserModel (val userId: Int,
val name: String,
val bankAccount: String,
val agency: String,
val balance: Double): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readDouble()
) {
}

override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeInt(userId)
dest?.writeString(name)
dest?.writeString(bankAccount)
dest?.writeString(agency)
dest?.writeDouble(balance)
}
override fun describeContents(): Int { return 0 }

companion object CREATOR : Parcelable.Creator<UserModel> {
override fun createFromParcel(parcel: Parcel): UserModel {
return UserModel(parcel)
}

override fun newArray(size: Int): Array<UserModel?> {
return arrayOfNulls(size)
}
}
}
Loading