From 6ec716643d3386a2439f4ac87c4a178ee01274a6 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 4 Mar 2021 14:29:29 -0300 Subject: [PATCH 1/2] desenvolvendo aplicativo de desafio Accenture --- .gitignore | 15 ++ .idea/.gitignore | 3 + .idea/.name | 1 + .idea/compiler.xml | 6 + .idea/gradle.xml | 22 +++ .idea/jarRepositories.xml | 25 +++ .idea/misc.xml | 9 + .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 50 +++++ app/proguard-rules.pro | 21 +++ .../ExampleInstrumentedTest.kt | 24 +++ app/src/main/AndroidManifest.xml | 31 ++++ .../example/accentureprojectbank/Adapter.kt | 33 ++++ .../com/example/accentureprojectbank/Api.kt | 38 ++++ .../accentureprojectbank/ExtratoActivity.kt | 101 ++++++++++ .../accentureprojectbank/MainActivity.kt | 139 ++++++++++++++ .../example/accentureprojectbank/Recibos.kt | 3 + .../StatementsResponse.kt | 20 ++ .../UserAccountResponse.kt | 29 +++ .../accentureprojectbank/ViewHolder.kt | 18 ++ .../drawable-v24/ic_launcher_foreground.xml | 30 +++ app/src/main/res/drawable-v24/logo.png | Bin 0 -> 4662 bytes app/src/main/res/drawable-v24/logout.png | Bin 0 -> 519 bytes app/src/main/res/drawable/custom_layout.xml | 21 +++ .../ic_baseline_account_circle_24.xml | 5 + .../main/res/drawable/ic_baseline_lock_24.xml | 5 + .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ app/src/main/res/font/helvetica.ttf | Bin 0 -> 308432 bytes app/src/main/res/font/helvetica_light.ttf | Bin 0 -> 106100 bytes app/src/main/res/layout/activity_main.xml | 83 +++++++++ app/src/main/res/layout/extrato_activitiy.xml | 150 +++++++++++++++ .../main/res/layout/extrato_view_holder.xml | 94 ++++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes app/src/main/res/values-night/themes.xml | 16 ++ app/src/main/res/values/colors.xml | 14 ++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/themes.xml | 18 ++ .../accentureprojectbank/ExampleUnitTest.kt | 17 ++ build.gradle | 26 +++ gradle.properties | 21 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 2 + 57 files changed, 1542 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/accentureprojectbank/ExampleInstrumentedTest.kt create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/accentureprojectbank/Adapter.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/Api.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/ExtratoActivity.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/MainActivity.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/Recibos.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/StatementsResponse.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/UserAccountResponse.kt create mode 100644 app/src/main/java/com/example/accentureprojectbank/ViewHolder.kt create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable-v24/logo.png create mode 100644 app/src/main/res/drawable-v24/logout.png create mode 100644 app/src/main/res/drawable/custom_layout.xml create mode 100644 app/src/main/res/drawable/ic_baseline_account_circle_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_lock_24.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/font/helvetica.ttf create mode 100644 app/src/main/res/font/helvetica_light.ttf create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/extrato_activitiy.xml create mode 100644 app/src/main/res/layout/extrato_view_holder.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/test/java/com/example/accentureprojectbank/ExampleUnitTest.kt create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle 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/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