diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..aa724b770 --- /dev/null +++ b/.gitignore @@ -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 +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 000000000..851e42fa4 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AccentureProjectBank \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..61a9130cd --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 000000000..23a89bbb6 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 000000000..a5f05cd8c --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..d5d35ec44 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..6c0b86358 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README-PASSO-A-PASSO-MARCOSCAMPOS.txt b/README-PASSO-A-PASSO-MARCOSCAMPOS.txt new file mode 100644 index 000000000..551a0b3ac --- /dev/null +++ b/README-PASSO-A-PASSO-MARCOSCAMPOS.txt @@ -0,0 +1,49 @@ + + +1º passo: +Desenvolvimento da activity main xml, adicionei 1 image view, 2 edit text e 1 button (conforme layout padrão) + +2º passo: + +Conforme API , criei o recyclerview: +Criei o xml da segunda tela (onde está o recycler view) e depois criei o xml do detalhamento dos recibos. Com isso criei a classe "Recibos" e o View Holder com os atributos necessários. +Depois criei a classe Adapter e por padrão preciso dar sobrescrever as funções onCreateViewHolder (passando o inflate do layout detalhado do recibo, view holder), +getItemCount (passando o tamanho da mutablelist das informações obtidas através da API), onBindViewHolder (onde indico o local que cada informação deve ficar no layout detalhado). + + +3º passo: +Criei a activity da segunda tela: "extrato activity" +Nela eu criei a função "montarLista" para finalização do recycler view, finalizei o adapter e o recycler. + + +4º passo: +No Postman retirei as informações necessárias para montar as classes UserAccountResponse (onde eu trato os dados do usuário) e StatementsResponse (onde eu trato os dados dos recibos). + +5º passo: +Criei uma interface API (onde passei as informações do Retrofit e da URL) +Com isso mapeei as duas chamadas. + + +6º passo: +Criei na Main a função "setarTexto" onde fiz um Bundle para passar as informações para a "ExtratoActivity" +E com o bundle na "ExtratoAcitivity" peguei as informações e passei para o layout. +Fiz também a ação da imagem de retornar para a página inicial e para finalizar o código da "ExtratoActivity" fiz a requisição da segunda chamada através da função fun fazeSegundaChamada. + + +7º passo: +Na main activity, fiz a função para fazer a verificação dos requisitos da senha: fun "passwordValidation" +Fiz o sharedPreferences para salvar as informações do nome do usuário e a senha para quando abrir o aplicativo essas informações ficarem salvas. +Fiz a função "validacao" que verificar se o nome do usuario e a senha foram preenchidas e caso sim, faz a verificação se a senha atende todos os requisitos (validar +se a senha tem pelo menos uma letra maiuscula, um caracter especial e um caracter alfanumérico) através da função "passwordValidation" +E caso atender todos os requisitos monto o body da minha chamada e faço e primeira chamada. Se der sucesso vai para a segunda tela. + + + + + + + + + + + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 000000000..c6706740d --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.example.accentureprojectbank" + minSdkVersion 19 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +// retrofit + + implementation 'com.squareup.retrofit2:retrofit:2.5.0' + + implementation 'com.squareup.retrofit2:converter-gson:2.5.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/accentureprojectbank/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/accentureprojectbank/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..44d3d0373 --- /dev/null +++ b/app/src/androidTest/java/com/example/accentureprojectbank/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.accentureprojectbank + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.accentureprojectbank", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..b32c39c56 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/accentureprojectbank/Adapter.kt b/app/src/main/java/com/example/accentureprojectbank/Adapter.kt new file mode 100644 index 000000000..667d373d9 --- /dev/null +++ b/app/src/main/java/com/example/accentureprojectbank/Adapter.kt @@ -0,0 +1,33 @@ +package com.example.accentureprojectbank + +import android.content.Intent +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView + +class Adapter(val listaInf: MutableList) : RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.extrato_view_holder, parent, false) + return ViewHolder(view) + } + + override fun getItemCount(): Int = listaInf.size + + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + + val payment = holder.pagamento + payment.text = listaInf[position].titulo + + val account = holder.conta + account.text = listaInf[position].descricao + + val date = holder.data + date.text = listaInf[position].data + + val value = holder.valor + value.text = listaInf[position].valor.toString() + } +} + diff --git a/app/src/main/java/com/example/accentureprojectbank/Api.kt b/app/src/main/java/com/example/accentureprojectbank/Api.kt new file mode 100644 index 000000000..37d7f63fb --- /dev/null +++ b/app/src/main/java/com/example/accentureprojectbank/Api.kt @@ -0,0 +1,38 @@ +package com.example.accentureprojectbank + +import retrofit2.Call +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.http.Body +import retrofit2.http.GET +import retrofit2.http.POST +import retrofit2.http.Path + +interface Api { + companion object ServiceBuilder { + /** Retorna uma Instância do Client Retrofit para Requisições + * @param path Caminho Principal da API + */ + fun getRetrofitInstance(): Retrofit { + return Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .build() + } + + private const val BASE_URL = "https://bank-app-test.herokuapp.com/api/" + } + + @POST("login") + fun fazerLogin( + @Body bodyLog : bodyLogin + ) : Call + + + @GET("statements/{idUser}") + fun dadosTransacoes( + @Path("idUser") idUsuaro : Int + ) : Call + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/accentureprojectbank/ExtratoActivity.kt b/app/src/main/java/com/example/accentureprojectbank/ExtratoActivity.kt new file mode 100644 index 000000000..60f99da08 --- /dev/null +++ b/app/src/main/java/com/example/accentureprojectbank/ExtratoActivity.kt @@ -0,0 +1,101 @@ +package com.example.accentureprojectbank + +import android.annotation.SuppressLint +import android.os.Bundle +import android.widget.EditText +import android.widget.ImageView +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class ExtratoActivity: AppCompatActivity() { + private var listStatementsItems: ArrayList = arrayListOf() + + @SuppressLint("WrongViewCast", "SetTextI18n") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.extrato_activitiy) + + val identificationUser = intent.getIntExtra("id_user", 1) + val identificationCount = intent.getStringExtra("count_user") + val identificationAg = intent.getStringExtra("ag_user") + val identificationValue = intent.getDoubleExtra("value_user", 1.1) + val identificationName = intent.getStringExtra("nome_user") + + val colocarNome = findViewById(R.id.nome_usuario) + colocarNome.text = identificationName.toString() + + val colocarAgAndConta = findViewById(R.id.ag_conta) + colocarAgAndConta.text = identificationCount.toString() + " / " + identificationAg.toString() + + val colocarSaldo = findViewById(R.id.saldo) + colocarSaldo.text = "R$ $identificationValue" + + + val retornar = findViewById(R.id.img) + retornar.setOnClickListener { + onBackPressed() + } + + + fazerSegundaChamada(identificationUser) + + } + + private fun fazerSegundaChamada(idUser: Int) { + + val retrofitClient = Api.getRetrofitInstance() + val endpoint = retrofitClient.create(Api::class.java) + val callback = endpoint.dadosTransacoes(idUser) + + callback.enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + val a = "deu erro" + } + + override fun onResponse(call: Call, response: Response) { + response.body()?.let { + val x = it + listStatementsItems = x.inf + montarLista() + + } + } + }) + + } + + private fun montarLista(){ + + val recycler by lazy { findViewById(R.id.recycler_view) } + val receipts = listStatementsItems + + recycler.layoutManager = LinearLayoutManager(this) + val adapter = Adapter(receipts as MutableList) + recycler.adapter = adapter + + } + + private fun getRecibos(): List { + val listaRecibosOk = mutableListOf() + + listaRecibosOk.add(Recibos("Pagamento 1", "Conta de Água", "01/01/2021", "R$50,00")) + listaRecibosOk.add(Recibos("Pagamento 2", "Conta de energia", "01/02/2021", "R$100,00")) + listaRecibosOk.add(Recibos("Pagamento 3", "Conta de gás", "10/02/2021", "R$80,00")) + listaRecibosOk.add(Recibos("Pagamento 4", "Compra 1", "15/02/2021", "R$150,00")) + listaRecibosOk.add(Recibos("Pagamento 5", "Compra 2", "18/02/2021", "R$180,00")) + listaRecibosOk.add(Recibos("Pagamento 6", "Compra 3", "20/02/2021", "R$200,00")) + + return listaRecibosOk + + } + + + +} + + diff --git a/app/src/main/java/com/example/accentureprojectbank/MainActivity.kt b/app/src/main/java/com/example/accentureprojectbank/MainActivity.kt new file mode 100644 index 000000000..aa29a083e --- /dev/null +++ b/app/src/main/java/com/example/accentureprojectbank/MainActivity.kt @@ -0,0 +1,139 @@ +package com.example.accentureprojectbank + +import android.content.Context +import android.content.Intent +import android.graphics.Typeface +import android.graphics.Typeface.* +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Button +import android.widget.EditText +import android.widget.TextView +import android.widget.Toast +import androidx.core.app.ActivityOptionsCompat +import com.example.accentureprojectbank.Api.ServiceBuilder.getRetrofitInstance +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import java.util.regex.Matcher +import java.util.regex.Pattern + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val retrofitClient = getRetrofitInstance() + val endpoint = retrofitClient.create(Api::class.java) + + val etUser = findViewById(R.id.et_user) + val etPass = findViewById(R.id.et_password) + + val btnLogin = findViewById