diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c71cd77e --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ + +SantanderTeste/.idea/codeStyles/Project.xml +SantanderTeste/.idea/gradle.xml +SantanderTeste/.idea/jarRepositories.xml +SantanderTeste/.idea/misc.xml +SantanderTeste/.idea/vcs.xml +SantanderTeste/.idea/codeStyles/Project.xml +SantanderTeste/.idea/gradle.xml +SantanderTeste/.idea/misc.xml diff --git a/SantanderTeste/.gitignore b/SantanderTeste/.gitignore new file mode 100644 index 00000000..fd45b12f --- /dev/null +++ b/SantanderTeste/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/SantanderTeste/.idea/codeStyles/Project.xml b/SantanderTeste/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..30aa626c --- /dev/null +++ b/SantanderTeste/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SantanderTeste/.idea/gradle.xml b/SantanderTeste/.idea/gradle.xml new file mode 100644 index 00000000..7ac24c77 --- /dev/null +++ b/SantanderTeste/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/SantanderTeste/.idea/misc.xml b/SantanderTeste/.idea/misc.xml new file mode 100644 index 00000000..e0d5b93f --- /dev/null +++ b/SantanderTeste/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/SantanderTeste/.idea/runConfigurations.xml b/SantanderTeste/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/SantanderTeste/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/SantanderTeste/README.md b/SantanderTeste/README.md new file mode 100644 index 00000000..e2501099 --- /dev/null +++ b/SantanderTeste/README.md @@ -0,0 +1,17 @@ +Commit V8 = MVP da aplicação 1.2.1 - testes unitários +NEW: Refactor para Clean Arch + MVP +//@TODO1: criar PDF da tela de investimento; + + +1. para rodar a aplicação, clone o a aplicaçao na linha de comando? +-> git clone https://github.com/alesefs/TesteAndroid.git + +2. abra no android studio como "open an existing Android Studio Project" + +3. ajuste o SDK para o caaminho do SDK instalado na sua máquina (deve vir o alerta assim que você abrir a aplicação) + +4. espere a atualização do gradle e rode a aplicação no emulador ou no device físico + + +OBS.: caso tente no device físico, verifique se a opção de desenvolvedor está habilitada, se a depuração por USB +também está habilitada. diff --git a/SantanderTeste/app/.gitignore b/SantanderTeste/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/SantanderTeste/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/SantanderTeste/app/build.gradle b/SantanderTeste/app/build.gradle new file mode 100644 index 00000000..870fc2c8 --- /dev/null +++ b/SantanderTeste/app/build.gradle @@ -0,0 +1,44 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.example.alessandrofsouza.santanderapp" + minSdkVersion 19 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + vectorDrawables.useSupportLibrary = true + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + testOptions { + unitTests { + includeAndroidResources = true + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-core:2.7.22' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'org.mockito:mockito-android:2.7.22' + + implementation 'com.android.support:design:28.0.0' + implementation 'com.android.support:recyclerview-v7:28.0.0' + + implementation 'com.squareup.retrofit2:retrofit:2.5.0' + implementation 'com.squareup.retrofit2:converter-gson:2.5.0' + + implementation 'com.github.vipulasri.layouttoimage:library:1.0.0' +} diff --git a/SantanderTeste/app/proguard-rules.pro b/SantanderTeste/app/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/SantanderTeste/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 diff --git a/SantanderTeste/app/src/androidTest/java/com/example/alessandrofsouza/santanderapp/ExampleInstrumentedTest.java b/SantanderTeste/app/src/androidTest/java/com/example/alessandrofsouza/santanderapp/ExampleInstrumentedTest.java new file mode 100644 index 00000000..465633ae --- /dev/null +++ b/SantanderTeste/app/src/androidTest/java/com/example/alessandrofsouza/santanderapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.alessandrofsouza.santanderapp; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.alessandrofsouza.santanderapp", appContext.getPackageName()); + } +} diff --git a/SantanderTeste/app/src/main/AndroidManifest.xml b/SantanderTeste/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8782d026 --- /dev/null +++ b/SantanderTeste/app/src/main/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/MainActivity.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/MainActivity.java new file mode 100644 index 00000000..7dc9c1f1 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/MainActivity.java @@ -0,0 +1,33 @@ +package com.example.alessandrofsouza.santanderapp; + +import android.os.Bundle; +import android.support.design.widget.TabLayout; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; + +import com.example.alessandrofsouza.santanderapp.presentation.adapters.PageAdapter; + +public class MainActivity extends AppCompatActivity { + + private static final String TAG = "Santander "; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + getSupportActionBar().hide(); + +// PageAdapter adapter = new PageAdapter(getSupportFragmentManager()); +// adapter.add(new InvestmentPresenter(), getString(R.string.investimento)); +// adapter.add(new ContactPresenter(), getString(R.string.contato)); + + PagerAdapter adapter = new PageAdapter(this, getSupportFragmentManager()); + + ViewPager viewPager = findViewById(R.id.mainPage); + viewPager.setAdapter(adapter); + + TabLayout tabLayout = findViewById(R.id.pageTab); + tabLayout.setupWithViewPager(viewPager); + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/data/service/ApiService.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/data/service/ApiService.java new file mode 100644 index 00000000..3a7c5145 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/data/service/ApiService.java @@ -0,0 +1,37 @@ +package com.example.alessandrofsouza.santanderapp.data.service; + +import com.example.alessandrofsouza.santanderapp.domain.model.ContactModel; +import com.example.alessandrofsouza.santanderapp.domain.model.InvestmentModel; + +import java.util.Set; + +import retrofit2.Call; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; +import retrofit2.http.GET; + +public class ApiService { + + //private String BASE_URL = "https://floating-mountain-50292.herokuapp.com/"; + + public ServiceApi getApi() { + Retrofit retrofit = new Retrofit + .Builder() + .baseUrl(ServiceApi.BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + return retrofit.create(ServiceApi.class); + } + + public interface ServiceApi { + + public static final String BASE_URL = "https://floating-mountain-50292.herokuapp.com"; + + @GET("/cells.json") + Call listCells(); + + @GET("/fund.json") + Call listInvestment(); + + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Cell.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Cell.java new file mode 100644 index 00000000..9a1d2f70 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Cell.java @@ -0,0 +1,107 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import com.google.gson.annotations.Expose; + +public class Cell { + + @Expose + public int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Expose + public int type; + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + @Expose + public String message; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Expose + public String typefield; + + public String getTypefield() { + return typefield; + } + + public void setTypefield(String typefield) { + this.typefield = typefield; + } + + @Expose + public boolean hidden; + + public boolean isHidden() { + return hidden; + } + + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + @Expose + public int topSpacing; + + public int getTopSpacing() { + return topSpacing; + } + + public void setTopSpacing(int topSpacing) { + this.topSpacing = topSpacing; + } + + @Expose + public int show; + + public int getShow() { + return show; + } + + public void setShow(int show) { + this.show = show; + } + + @Expose + public boolean required; + + public boolean isRequired() { + return required; + } + + public void setRequired(boolean required) { + this.required = required; + } + + + + private String editTextValue; + + public String getEditTextValue() { + return editTextValue; + } + + public void setEditTextValue(String editTextValue) { + this.editTextValue = editTextValue; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/ContactModel.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/ContactModel.java new file mode 100644 index 00000000..2b5900e9 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/ContactModel.java @@ -0,0 +1,18 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import java.util.ArrayList; + +public class ContactModel { + + //@Expose + public ArrayList cells; + + public ArrayList getCells() { + return cells; + } + + public void setCells(ArrayList cells) { + this.cells = cells; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Infos.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Infos.java new file mode 100644 index 00000000..ec7a2e99 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Infos.java @@ -0,0 +1,48 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import com.google.gson.annotations.Expose; + +public class Infos { + + @Expose + public String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + @Expose + public String data; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + + + public String title; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Infos(String sTitle, String sName, String sData) { + title = sTitle; + name = sName; + data = sData; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/InvestmentModel.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/InvestmentModel.java new file mode 100644 index 00000000..993b7418 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/InvestmentModel.java @@ -0,0 +1,20 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class InvestmentModel { + + @SerializedName("screen") + @Expose + public Screen screen; + + public Screen getScreen() { + return screen; + } + + public void setScreen(Screen screen) { + this.screen = screen; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/MoreInfo.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/MoreInfo.java new file mode 100644 index 00000000..1da1dd17 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/MoreInfo.java @@ -0,0 +1,44 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class MoreInfo { + + @Expose + public MoreInfoValues month; + + public MoreInfoValues getMonth() { + return month; + } + + public void setMonth(MoreInfoValues month) { + this.month = month; + } + + + @Expose + public MoreInfoValues year; + + public MoreInfoValues getYear() { + return year; + } + + public void setYear(MoreInfoValues year) { + this.year = year; + } + + + @SerializedName("12months") + @Expose + public MoreInfoValues months12; + + public MoreInfoValues getMonths12() { + return months12; + } + + public void setMonths12(MoreInfoValues months12) { + this.months12 = months12; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/MoreInfoValues.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/MoreInfoValues.java new file mode 100644 index 00000000..33af63cc --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/MoreInfoValues.java @@ -0,0 +1,29 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import com.google.gson.annotations.Expose; + +public class MoreInfoValues { + + @Expose + public Double fund; + + public Double getFund() { + return fund; + } + + public void setFund(Double fund) { + this.fund = fund; + } + + @Expose + public Double CDI; + + public Double getCDI() { + return CDI; + } + + public void setCDI(Double CDI) { + this.CDI = CDI; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Screen.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Screen.java new file mode 100644 index 00000000..cbe0fc34 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/domain/model/Screen.java @@ -0,0 +1,128 @@ +package com.example.alessandrofsouza.santanderapp.domain.model; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; + +public class Screen { + + @Expose + public String title; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + + @Expose + public String fundName; + + public String getFundName() { + return fundName; + } + + public void setFundName(String fundName) { + this.fundName = fundName; + } + + + @Expose + public String whatIs; + + public String getWhatIs() { + return whatIs; + } + + public void setWhatIs(String whatIs) { + this.whatIs = whatIs; + } + + + @Expose + public String definition; + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } + + + @Expose + public String riskTitle; + + public String getRiskTitle() { + return riskTitle; + } + + public void setRiskTitle(String riskTitle) { + this.riskTitle = riskTitle; + } + + + @Expose + public int risk; + + public int getRisk() { + return risk; + } + + public void setRisk(int risk) { + this.risk = risk; + } + + + @Expose + public String infoTitle; + + public String getInfoTitle() { + return infoTitle; + } + + public void setInfoTitle(String infoTitle) { + this.infoTitle = infoTitle; + } + + + @Expose + public MoreInfo moreInfo; + + public MoreInfo getMoreInfo() { + return moreInfo; + } + + public void setMoreInfo(MoreInfo moreInfo) { + this.moreInfo = moreInfo; + } + + + @Expose + public ArrayList info; + + public ArrayList getInfo() { + return info; + } + + public void setInfo(ArrayList info) { + this.info = info; + } + + + @Expose + public ArrayList downInfo; + + public ArrayList getDownInfo() { + return downInfo; + } + + public void setDownInfo(ArrayList downInfo) { + this.downInfo = downInfo; + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/adapters/PageAdapter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/adapters/PageAdapter.java new file mode 100644 index 00000000..baffcda9 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/adapters/PageAdapter.java @@ -0,0 +1,71 @@ +package com.example.alessandrofsouza.santanderapp.presentation.adapters; + +import android.content.Context; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.presentation.pages.contact.ContactFragment; +import com.example.alessandrofsouza.santanderapp.presentation.pages.contact.ContactPresenter; +import com.example.alessandrofsouza.santanderapp.presentation.pages.investment.InvestmentFragment; +import com.example.alessandrofsouza.santanderapp.presentation.pages.investment.InvestmentPresenter; + +import java.util.ArrayList; + +public class PageAdapter extends FragmentPagerAdapter { + + private ArrayList fragments = new ArrayList<>(); + private ArrayList title = new ArrayList<>(); + private Context context; + + public PageAdapter(Context ctx, FragmentManager fm) { + super(fm); + context = ctx; + } + +// public void add(Fragment frag, String title) { +// this.fragments.add(frag); +// this.title.add(title); +// } + + @Override + public Fragment getItem(int i) { +// return this.fragments.get(i); + + switch (i) { + case 0: + InvestmentFragment fragment1 = InvestmentFragment.newInstance(); + new InvestmentPresenter(fragment1); + return fragment1; + + case 1: + ContactFragment fragment0 = ContactFragment.newInstance(); + new ContactPresenter(fragment0); + return fragment0; + + default: + return null; + + } + } + + @Override + public int getCount() { +// return this.fragments.size(); + return 2; + } + + @Override + public CharSequence getPageTitle(int position) { +// return this.title.get(position); + switch (position) { + case 0: + return context.getResources().getString(R.string.investimento); + case 1: + return context.getResources().getString(R.string.contato); + default: + return null; + } + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/base/BasePresenter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/base/BasePresenter.java new file mode 100644 index 00000000..ff94f6d9 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/base/BasePresenter.java @@ -0,0 +1,5 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.base; + +public interface BasePresenter { + void init(); +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/base/BaseView.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/base/BaseView.java new file mode 100644 index 00000000..fb8e3c1d --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/base/BaseView.java @@ -0,0 +1,5 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.base; + +public interface BaseView { + void setPresenter(T presenter); +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactActionView.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactActionView.java new file mode 100644 index 00000000..34352d69 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactActionView.java @@ -0,0 +1,11 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.contact; + +import android.view.View; + +interface ContactActionView { +// void setTitle(String title); +// +// void setStarCount(int starCount); + + void click(View itemView, int position); +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactAdapter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactAdapter.java new file mode 100644 index 00000000..16c05adb --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactAdapter.java @@ -0,0 +1,123 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.contact; + +import android.support.annotation.NonNull; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.TextView; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Cell; +import com.example.alessandrofsouza.santanderapp.presentation.utils.Constants; + +import java.util.ArrayList; + +public class ContactAdapter extends RecyclerView.Adapter { + + private static final String TAG = "Santander "; + private ArrayList dataSet; + private Cell cell; + private final ContactListPresenter presenter; + private ContactActionView rowView0; + + + + + public ContactAdapter(ContactActionView listener) { + dataSet = new ArrayList<>(); + cell = new Cell(); + presenter = new ContactListPresenter(dataSet); + rowView0 = listener; + } + + + @NonNull + @Override + public ContactAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + switch (i){ + case Constants.TYPE_FIELD: + return new ContactAdapter.ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_edit_text, viewGroup, false), rowView0); + + case Constants.TYPE_SEND: + return new ContactAdapter.ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_button_round, viewGroup, false), rowView0); + + case Constants.TYPE_CHECKBOX: + return new ContactAdapter.ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_checkbox, viewGroup, false), rowView0); + + case Constants.TYPE_TEXT: + return new ContactAdapter.ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_text, viewGroup, false), rowView0); + + default: + //@TODO: change to ImageView or create 1 more field to + return new ContactAdapter.ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_text, viewGroup, false), rowView0); + } + } + + @Override + public void onBindViewHolder(@NonNull ContactAdapter.ViewHolder viewHolder, int i) { + presenter.onBindRepositoryRowViewAtPosition(i, viewHolder); + } + + @Override + public int getItemViewType(int position) { + cell = dataSet.get(position); + int viewType = cell.getType(); + return viewType; + } + + @Override + public int getItemCount() { + return presenter.getRepositoriesRowsCount(); + } + + public void addListContact(ArrayList cellList) { + dataSet.clear(); + dataSet.addAll(cellList); + notifyDataSetChanged(); + } + + public boolean getValidatorForm() { + return presenter.getValidForm(); + } + + public void clearListContact() { + presenter.clearForm(); + } + + + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + + public TextView textView; + public TextInputLayout textInputLayout; + public TextInputEditText textInputEditText; + public Button roundedButton; + public CheckBox checkBox; + + public ContactActionView contactActionView; + + + public ViewHolder(@NonNull View itemView, ContactActionView listerner) { + super(itemView); + textView = itemView.findViewById(R.id.textView); + textInputLayout = itemView.findViewById(R.id.editTextLayout); + textInputEditText = itemView.findViewById(R.id.editTextInput); + roundedButton = itemView.findViewById(R.id.buttonRound); + checkBox = itemView.findViewById(R.id.checkBox); + + contactActionView = listerner; + itemView.setOnClickListener(this); + } + + + @Override + public void onClick(View v) { + contactActionView.click(itemView, getAdapterPosition()); + } + + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactContract.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactContract.java new file mode 100644 index 00000000..620e5d2e --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactContract.java @@ -0,0 +1,19 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.contact; + +import com.example.alessandrofsouza.santanderapp.domain.model.Cell; +import com.example.alessandrofsouza.santanderapp.presentation.pages.base.BasePresenter; +import com.example.alessandrofsouza.santanderapp.presentation.pages.base.BaseView; + +import java.util.ArrayList; + +public interface ContactContract { + + interface View extends BaseView { + void showContactCells(ArrayList cellList); + } + + interface Presenter extends BasePresenter { + void getContactCells(); + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactFragment.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactFragment.java new file mode 100644 index 00000000..dea13857 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactFragment.java @@ -0,0 +1,111 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.contact; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.support.constraint.ConstraintLayout; +import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Cell; + +import java.util.ArrayList; + +@SuppressLint("ValidFragment") +public class ContactFragment extends Fragment implements ContactContract.View { + + private static final String TAG = "Santander "; + private ContactContract.Presenter presenter; + private ContactAdapter contactAdapter; + private RecyclerView recyclerView; + private ContactListPresenter listPresenter0; + private ContactActionView rowView0; + + private ConstraintLayout layout1; + private ConstraintLayout layout2; + private Button btnBack; + + + public static ContactFragment newInstance() { + return new ContactFragment(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + View view = inflater.inflate(R.layout.contact, container, false); + + layout1 = view.findViewById(R.id.constLayout1); + layout2 = view.findViewById(R.id.constLayout2); + btnBack = view.findViewById(R.id.buttonBack); + recycleView(view); + returnContactLayout(view); + + return view; + } + + @Override + public void onStart() { + super.onStart(); + presenter.init(); + } + + @Override + public void setPresenter(ContactContract.Presenter contractPresenter) { + presenter = contractPresenter; + } + + @Override + public void showContactCells(ArrayList cellList) { + //Envia pro recycleView + contactAdapter.addListContact(cellList); + } + + private void recycleView(View view) { + contractActionExtra(); + recyclerView = view.findViewById(R.id.recycleViewContact); + recyclerView.setHasFixedSize(true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); + recyclerView.setLayoutManager(linearLayoutManager); + contactAdapter = new ContactAdapter(rowView0); + recyclerView.setAdapter(contactAdapter); + } + + + + private void contractActionExtra() { + rowView0 = new ContactActionView() { + @Override + public void click(View itemView, int position) { +// Log.i(TAG, "->: " + contactAdapter.getValidatorForm()); + switch (position) { + case 5: + if (contactAdapter.getValidatorForm()) { + layout1.setVisibility(View.GONE); + layout2.setVisibility(View.VISIBLE); + } + break; + } + } + }; + } + + private void returnContactLayout(View view) { + btnBack = view.findViewById(R.id.buttonBack); + btnBack.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + contactAdapter.clearListContact(); + layout1.setVisibility(View.VISIBLE); + layout2.setVisibility(View.GONE); + } + }); + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactListPresenter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactListPresenter.java new file mode 100644 index 00000000..1d99ff1e --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactListPresenter.java @@ -0,0 +1,304 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.contact; + +import android.content.res.Resources; +import android.graphics.PorterDuff; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.support.v4.content.res.ResourcesCompat; +import android.text.Editable; +import android.text.InputType; +import android.text.TextWatcher; +import android.util.TypedValue; +import android.view.View; +import android.widget.CheckBox; +import android.widget.EditText; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Cell; +import com.example.alessandrofsouza.santanderapp.presentation.utils.Constants; +import com.example.alessandrofsouza.santanderapp.presentation.utils.EmailValidator; +import com.example.alessandrofsouza.santanderapp.presentation.utils.NameValidator; +import com.example.alessandrofsouza.santanderapp.presentation.utils.PhoneNumberFormat; +import com.example.alessandrofsouza.santanderapp.presentation.utils.PhoneValidator; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; + +class ContactListPresenter { + + private static final String TAG = "Santander "; + private final ArrayList dataCell; + private Resources resources; + private View view; + private Cell cell; + + private ContactListPresenter listPresenter0; + private ContactActionView rowView0; + private ContactAdapter contactAdapter; + + private boolean checkCheckbox = false; + private CheckBox checkBox; + + private TextInputLayout editLayout; + private TextInputEditText editTextName; + private TextInputEditText editTextMail; + private TextInputEditText editTextPhone; + + private PhoneNumberFormat phoneformat; + + + + public ContactListPresenter(ArrayList dataCell) { + this.dataCell = dataCell; + } + + + public void onBindRepositoryRowViewAtPosition(int i, final ContactAdapter.ViewHolder viewHolder) { + cell = dataCell.get(i); + resources = viewHolder.itemView.getContext().getResources(); + contactAdapter = new ContactAdapter(rowView0); + +// viewHolder.setTitle(cell.getMessage()); + + switch (cell.getType()) { + + case Constants.TYPE_FIELD: + viewHolder.textInputLayout.setHint(cell.getMessage()); + viewHolder.textInputLayout.setHint(cell.getMessage()); + viewHolder.textInputLayout.setVisibility(cell.isHidden() ? View.GONE : View.VISIBLE); + viewHolder.textInputLayout.setId(cell.getId()); + viewHolder.textInputLayout.setPadding(0, cell.getTopSpacing(), 0, 0); + viewHolder.textInputLayout.clearFocus(); + + switch (cell.getTypefield()) { + + case Constants.TYPEFIELD_TEXT_T: + viewHolder.textInputEditText.setInputType(InputType.TYPE_CLASS_TEXT); + viewHolder.textInputEditText.setText(cell.getEditTextValue()); + editTextName = viewHolder.textInputEditText; + + editTextName.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void afterTextChanged(Editable editable) { + NameValidator.validateName(editable); + styleNameField(); + } + + public boolean styleNameField() { + String nameInput = editTextName.getText().toString().trim(); + + if (nameInput.isEmpty()) { + editTextName.setError("Está vázio"); + editTextName.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + return false; + + } else if (!NameValidator.NAME_PATTERN.matcher(nameInput).matches()) { + editTextName.setError("Está incorreto"); + editTextName.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + return false; + + } else { + editTextName.setError(null); + editTextName.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderCorrect), PorterDuff.Mode.SRC_ATOP); + return true; + } + } + }); + break; + + case Constants.TYPEFIELD_TELNUMBER_T: + viewHolder.textInputEditText.setInputType(InputType.TYPE_CLASS_PHONE); + editTextPhone = viewHolder.textInputEditText; + + phoneformat = new PhoneNumberFormat(new WeakReference(editTextPhone)); + editTextPhone.addTextChangedListener(phoneformat); + editTextPhone.setSelection(editTextPhone.getText().length()); + + editTextPhone.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { } + + @Override + public void afterTextChanged(Editable s) { + stylePhoneField(); + } + }); + + break; + + case Constants.TYPEFIELD_EMAIL_T: + viewHolder.textInputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + editLayout = viewHolder.textInputLayout; + editTextMail = viewHolder.textInputEditText; + + + editTextMail.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } + + @Override + public void afterTextChanged(Editable editable) { + EmailValidator.validateEmail(editable); + styleEmailField(); + } + + private boolean styleEmailField() { + String emailInput = editTextMail.getText().toString().trim(); + if (emailInput.isEmpty()) { + editTextMail.setError("Está vázio"); + editTextMail.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + return false; + + } else if (!EmailValidator.EMAIL_PATTERN.matcher(emailInput).matches()) { + editTextMail.setError("Está incorreto"); + editTextMail.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + return false; + + } else { + editTextMail.setError(null); + editTextMail.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderCorrect), PorterDuff.Mode.SRC_ATOP); + return true; + } + } + }); + break; + + default: + viewHolder.textInputEditText.setInputType(InputType.TYPE_CLASS_TEXT); + break; + } + + break; + + case Constants.TYPE_TEXT: + viewHolder.textView.setText(cell.getMessage()); + viewHolder.textView.setVisibility(cell.isHidden() ? View.GONE : View.VISIBLE); + viewHolder.textView.setId(cell.getId()); + viewHolder.textView.setPadding(0, cell.getTopSpacing(), 0, cell.getTopSpacing()); + viewHolder.textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txtRegular)); + break; + + case Constants.TYPE_CHECKBOX: + viewHolder.checkBox.setText(cell.getMessage()); + viewHolder.checkBox.setVisibility(cell.isHidden() ? View.GONE : View.VISIBLE); + viewHolder.checkBox.setId(cell.getId()); + viewHolder.checkBox.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txtRegular)); + viewHolder.checkBox.setTypeface(ResourcesCompat.getFont(viewHolder.itemView.getContext(), R.font.dinpro_medium)); + viewHolder.checkBox.setPadding(0, cell.getTopSpacing(), 0, cell.getTopSpacing()); + viewHolder.checkBox.setChecked(cell.isHidden()); + viewHolder.checkBox.setOnCheckedChangeListener(null); + + checkBox = viewHolder.checkBox; + + viewHolder.checkBox.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + if(checkBox.isChecked()) { + checkCheckbox = true; + editLayout.setVisibility(View.VISIBLE); + } else { + checkCheckbox = false; + editLayout.setVisibility(View.GONE); + } + } + }); + break; + + case Constants.TYPE_SEND: + viewHolder.roundedButton.setText(cell.getMessage()); + viewHolder.roundedButton.setVisibility(cell.isHidden() ? View.GONE : View.VISIBLE); + viewHolder.roundedButton.setId(cell.getId()); + viewHolder.roundedButton.setPadding(0, cell.getTopSpacing(), 0, cell.getTopSpacing()); + viewHolder.roundedButton.setOnClickListener(viewHolder); + break; + + default: + //@TODO: change to ImageView or create 1 more field to + viewHolder.textView.setText(cell.getMessage()); + viewHolder.textView.setVisibility(cell.isHidden() ? View.GONE : View.VISIBLE); + viewHolder.textView.setId(cell.getId()); + viewHolder.textView.setPadding(0, cell.getTopSpacing(), 0, cell.getTopSpacing()); + viewHolder.textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txtRegular)); + break; + } + } + + + private void stylePhoneField() { + + switch (phoneformat.STATE_PHONE_VALIDATOR) { + case "0": + editTextPhone.setError("Está vázio"); + editTextPhone.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + break; + case "1": + editTextPhone.setError("Está incorreto"); + editTextPhone.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + break; + case "2": + editTextPhone.setError(null); + editTextPhone.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderCorrect), PorterDuff.Mode.SRC_ATOP); + break; + default: + editTextPhone.setError("Está incorreto"); + editTextPhone.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderRed), PorterDuff.Mode.SRC_ATOP); + break; + } + } + + + public int getRepositoriesRowsCount() { + return dataCell.size(); + } + + + public boolean getValidForm() { + if (!checkCheckbox) { + if (NameValidator.NAME_PATTERN.matcher(editTextName.getText().toString().trim()).matches() && PhoneValidator.PHONE8_PATTERN.matcher(phoneformat.phoneNumbers.trim()).matches() || + NameValidator.NAME_PATTERN.matcher(editTextName.getText().toString().trim()).matches() && PhoneValidator.PHONE9_PATTERN.matcher(phoneformat.phoneNumbers.trim()).matches()) { + return true; + } else { + return false; + } + + } else { + if (NameValidator.NAME_PATTERN.matcher(editTextName.getText().toString().trim()).matches() && EmailValidator.EMAIL_PATTERN.matcher(editTextMail.getText().toString().trim()).matches() && PhoneValidator.PHONE8_PATTERN.matcher(phoneformat.phoneNumbers.trim()).matches() || + NameValidator.NAME_PATTERN.matcher(editTextName.getText().toString().trim()).matches() && EmailValidator.EMAIL_PATTERN.matcher(editTextMail.getText().toString().trim()).matches() && PhoneValidator.PHONE9_PATTERN.matcher(phoneformat.phoneNumbers.trim()).matches()) { + return true; + } else { + return false; + } + } + } + + + public void clearForm() { + editTextName.setText(null); + editTextName.setError("", null); + editTextName.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderLtGray), PorterDuff.Mode.SRC_ATOP); + + editTextPhone.setText(null); + editTextPhone.setError("", null); + editTextPhone.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderLtGray), PorterDuff.Mode.SRC_ATOP); + + checkBox.setChecked(false); + + editLayout.setVisibility(View.GONE); + editTextMail.setText(null); + editTextMail.setError("", null); + editTextMail.getBackground().mutate().setColorFilter(resources.getColor(R.color.santanderLtGray), PorterDuff.Mode.SRC_ATOP); + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactPresenter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactPresenter.java new file mode 100644 index 00000000..837a4a16 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/contact/ContactPresenter.java @@ -0,0 +1,53 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.contact; + +import android.support.annotation.NonNull; +import android.util.Log; + +import com.example.alessandrofsouza.santanderapp.data.service.ApiService; +import com.example.alessandrofsouza.santanderapp.domain.model.ContactModel; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + + +public class ContactPresenter implements ContactContract.Presenter{ + + private static final String TAG = "Santander "; + private ContactContract.View view; + private ApiService service; + + public ContactPresenter(@NonNull ContactContract.View contractView) { + view = contractView; + view.setPresenter(this); + service = new ApiService(); + } + + @Override + public void init() { + getContactCells(); + } + + public void getContactCells() { + service.getApi().listCells().enqueue(new Callback() { + @NonNull + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + ContactModel contactModel = response.body(); + view.showContactCells(contactModel.getCells()); + + } else { + Log.e(TAG, "Error Unsuccessful " + response.errorBody()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Log.e(TAG, "Error Failure " + t.getMessage()); + } + }); + } + + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentAdapter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentAdapter.java new file mode 100644 index 00000000..e8319b5d --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentAdapter.java @@ -0,0 +1,114 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import android.content.Context; +import android.content.res.Resources; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Screen; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class InvestmentAdapter extends RecyclerView.Adapter { + + public ArrayList dataScreenSet; + private View view; + private Context context; + private Resources resources; + private Screen screen; + private final InvestmentListPresenter presenter; + + public InvestmentAdapter() { + dataScreenSet = new ArrayList<>(); + presenter = new InvestmentListPresenter(dataScreenSet); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.frame_layout_invest, viewGroup, false); + context = view.getContext(); + +// recycleInfo(view, context);//chama o recycleView +// recycleDownInfo(view, context);//chama o recycleView + + return new ViewHolder(view); + } + + + @Override + public void onBindViewHolder(@NonNull InvestmentAdapter.ViewHolder viewHolder, int i) { + presenter.onBindRepositoryRowViewAtPosition(i, viewHolder); + } + + + @Override + public int getItemViewType(int position) { + return position; + } + + @Override + public int getItemCount() { + return presenter.getRepositoriesRowsCount(); + } + + public void addListInvestment(Screen screen) { + dataScreenSet.clear(); + dataScreenSet.addAll(Collections.singleton(screen)); + notifyDataSetChanged(); + } + + + public class ViewHolder extends RecyclerView.ViewHolder { + + public TextView investTitle; + public TextView investFundName; + public TextView whatIs; + public TextView definition; + public TextView riskTitle; + + public ImageView arrowRisk; + private View viewColors1; + private View viewColors2; + private View viewColors3; + private View viewColors4; + private View viewColors5; + public ArrayList viewRisk; + + public TextView infoTitle; + public Button btnInvestment; + + + public ViewHolder(@NonNull View itemView) { + super(itemView); + + investTitle = itemView.findViewById(R.id.investTitle); + investFundName = itemView.findViewById(R.id.investFundName); + whatIs = itemView.findViewById(R.id.whatIs); + definition = itemView.findViewById(R.id.definition); + riskTitle = itemView.findViewById(R.id.riskTitle); + + arrowRisk = itemView.findViewById(R.id.arrowRisk); + viewColors1 = itemView.findViewById(R.id.viewColors1); + viewColors2 = itemView.findViewById(R.id.viewColors2); + viewColors3 = itemView.findViewById(R.id.viewColors3); + viewColors4 = itemView.findViewById(R.id.viewColors4); + viewColors5 = itemView.findViewById(R.id.viewColors5); + viewRisk = new ArrayList<>(Arrays.asList(null, viewColors1, viewColors2, viewColors3, viewColors4, viewColors5)); + + infoTitle = itemView.findViewById(R.id.infoTitle); + + btnInvestment = itemView.findViewById(R.id.buttonRound); + + } + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentContract.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentContract.java new file mode 100644 index 00000000..2994a290 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentContract.java @@ -0,0 +1,17 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import com.example.alessandrofsouza.santanderapp.domain.model.Screen; +import com.example.alessandrofsouza.santanderapp.presentation.pages.base.BasePresenter; +import com.example.alessandrofsouza.santanderapp.presentation.pages.base.BaseView; + +public interface InvestmentContract { + + interface View extends BaseView { + void showInvestmentScreen(Screen screen); + } + + interface Presenter extends BasePresenter { + void getInvestmentScreen(); + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentFragment.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentFragment.java new file mode 100644 index 00000000..e8af920d --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentFragment.java @@ -0,0 +1,73 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Toast; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Screen; + +@SuppressLint("ValidFragment") +public class InvestmentFragment extends Fragment implements InvestmentContract.View { + + private InvestmentContract.Presenter presenter; + private InvestmentAdapter investmentAdapter; + private RecyclerView recyclerView; + public Button btnPrint; + + public static InvestmentFragment newInstance() { + return new InvestmentFragment(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + View view = inflater.inflate(R.layout.investment, container, false); + + recycleView(view); + + btnPrint = view.findViewById(R.id.buttonPrint); + btnPrint.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(getContext(), R.string.disable, Toast.LENGTH_SHORT).show(); + } + }); + + return view; + } + + @Override + public void onStart() { + super.onStart(); + presenter.init(); + } + + @Override + public void setPresenter(InvestmentContract.Presenter investmentPresenter) { + presenter = investmentPresenter; + } + + + @Override + public void showInvestmentScreen(Screen screen) { + investmentAdapter.addListInvestment(screen); + } + + private void recycleView(View view) { + recyclerView = view.findViewById(R.id.recycleViewInvestment); + recyclerView.setHasFixedSize(true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); + recyclerView.setLayoutManager(linearLayoutManager); + investmentAdapter = new InvestmentAdapter(); + recyclerView.setAdapter(investmentAdapter); + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentInfoAdapter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentInfoAdapter.java new file mode 100644 index 00000000..9c9b769c --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentInfoAdapter.java @@ -0,0 +1,89 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import android.content.res.Resources; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Infos; + +import java.util.ArrayList; + +class InvestmentInfoAdapter extends RecyclerView.Adapter { + + + private static final String TAG = "Santander "; + private ArrayList dataSet; + + public InvestmentInfoAdapter() { + dataSet = new ArrayList<>(); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + View viewText = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.invest_info, viewGroup, false); + return new ViewHolder(viewText); + } + + @Override + public void onBindViewHolder(@NonNull final InvestmentInfoAdapter.ViewHolder viewHolder, int i) { + //TODO: create holderPresenter + + Infos info = dataSet.get(i); + Resources resources = viewHolder.itemView.getContext().getResources(); + + viewHolder.info_title.setText(info.getName()); + + if(info.getData() != null) { + viewHolder.buttonDown.setAlpha(0); + viewHolder.buttonDown.setClickable(false); + viewHolder.info_content.setText(info.getData()); + } else { + viewHolder.info_content.setAlpha(0); + viewHolder.buttonDown.setText(resources.getText(R.string.baixar)); + viewHolder.buttonDown.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(viewHolder.itemView.getContext(), R.string.disable, Toast.LENGTH_SHORT).show(); + } + }); + } + } + + @Override + public int getItemViewType(int position) { + return position; + } + + @Override + public int getItemCount() { + return dataSet.size(); + } + + public void addListInfo(ArrayList listInfo) { + dataSet.addAll(listInfo); + notifyDataSetChanged(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + private TextView info_title; + private TextView info_content; + private Button buttonDown; + + public ViewHolder(@NonNull View itemView) { + super(itemView); + + info_title = itemView.findViewById(R.id.info_title); + info_content = itemView.findViewById(R.id.info_content); + buttonDown = itemView.findViewById(R.id.buttonDown); + } + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentListPresenter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentListPresenter.java new file mode 100644 index 00000000..311bece9 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentListPresenter.java @@ -0,0 +1,141 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.View; +import android.view.ViewTreeObserver; +import android.widget.Toast; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Infos; +import com.example.alessandrofsouza.santanderapp.domain.model.MoreInfo; +import com.example.alessandrofsouza.santanderapp.domain.model.Screen; + +import java.util.ArrayList; + +class InvestmentListPresenter { + + private final ArrayList dataScreenSet; + private Resources resources; + private Screen screen; + private ViewTreeObserver observer; + private RecyclerView recyclerView; + private InvestmentInfoAdapter investmentInfoAdapter; + private InvestmentMoreInfoAdapter investmentmoreInfoAdapter; + private View view; + private Context context; + + + public InvestmentListPresenter(ArrayList dataScreen) { + this.dataScreenSet = dataScreen; + } + + public void onBindRepositoryRowViewAtPosition(int i, final InvestmentAdapter.ViewHolder viewHolder) { + resources = viewHolder.itemView.getContext().getResources(); + screen = dataScreenSet.get(i); + + viewHolder.investTitle.setText(screen.getTitle()); + viewHolder.investTitle.setPadding(0, ((int) resources.getDimension(R.dimen.lMargin)), 0, 0); + + viewHolder.investFundName.setText(screen.getFundName()); + viewHolder.investFundName.setPadding(0, ((int) resources.getDimension(R.dimen.mMargin)), 0, 0); + + viewHolder.whatIs.setText(screen.getWhatIs()); + viewHolder.whatIs.setPadding(0, ((int) resources.getDimension(R.dimen.sMargin)), 0, 0); + + viewHolder.definition.setText(screen.getDefinition()); + viewHolder.definition.setPadding(0, ((int) resources.getDimension(R.dimen.sMargin) / 2), 0, 0); + + viewHolder.riskTitle.setText(screen.getRiskTitle()); + viewHolder.riskTitle.setPadding(0, ((int) resources.getDimension(R.dimen.sMargin)), 0, 0); + + + observer = viewHolder.arrowRisk.getViewTreeObserver(); + observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + for (int j = 0; j < viewHolder.viewRisk.size(); j++) { + viewHolder.viewRisk.get(screen.getRisk()).setScaleY(2); + viewHolder.arrowRisk.setX(viewHolder.viewRisk.get(screen.getRisk()).getX() + viewHolder.viewRisk.get(screen.getRisk()).getPivotX() - viewHolder.arrowRisk.getWidth() / 3); + } + } + }); + + + viewHolder.infoTitle.setText(screen.getInfoTitle()); + viewHolder.infoTitle.setPadding(0, ((int) resources.getDimension(R.dimen.sMargin)), 0, 0); + + + viewHolder.btnInvestment.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(viewHolder.itemView.getContext(), R.string.disable, Toast.LENGTH_SHORT).show(); + } + }); + + + + + recycleMoreInfo(viewHolder.itemView, context);//chama o recycleView + ArrayList moreInfo = addListInvestmentMoreInfo(screen.getMoreInfo()); + investmentmoreInfoAdapter.addListMoreInfo(moreInfo); + + recycleInfo(viewHolder.itemView, context);//chama o recycleView + ArrayList listInfo = screen.getInfo(); + investmentInfoAdapter.addListInfo(listInfo); + + recycleDownInfo(viewHolder.itemView, context);//chama o recycleView + ArrayList listDownInfo = screen.getDownInfo(); + investmentInfoAdapter.addListInfo(listDownInfo); + + } + + + private ArrayList addListInvestmentMoreInfo(MoreInfo moreInfo) { + ArrayList moreInfoList = new ArrayList<>(); + moreInfoList.add(new Infos("", "Fundo", "CDI")); + moreInfoList.add(new Infos("No mês", moreInfo.getMonth().getFund().toString().concat("%"), moreInfo.getMonth().getCDI().toString().concat("%"))); + moreInfoList.add(new Infos("No ano", moreInfo.getYear().getFund().toString().concat("%"), moreInfo.getYear().getCDI().toString().concat("%"))); + moreInfoList.add(new Infos("12 meses", moreInfo.getMonths12().getFund().toString().concat("%"), moreInfo.getMonths12().getCDI().toString().concat("%"))); + + //Log.i("TAGX", ""+moreInfoList.size()); + return moreInfoList; + } + + + public int getRepositoriesRowsCount() { + return dataScreenSet.size(); + } + + + private void recycleMoreInfo(View view, Context context) { + recyclerView = view.findViewById(R.id.recycleViewMoreInfo); + investmentmoreInfoAdapter = new InvestmentMoreInfoAdapter(); + recyclerView.setAdapter(investmentmoreInfoAdapter); + recyclerView.setHasFixedSize(true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); + recyclerView.setLayoutManager(linearLayoutManager); + } + + + private void recycleInfo(View view, Context context) { + recyclerView = view.findViewById(R.id.recycleViewInfo); + investmentInfoAdapter = new InvestmentInfoAdapter(); + recyclerView.setAdapter(investmentInfoAdapter); + recyclerView.setHasFixedSize(true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); + recyclerView.setLayoutManager(linearLayoutManager); + } + + private void recycleDownInfo(View view, Context context) { + recyclerView = view.findViewById(R.id.recycleViewDownInfo); + investmentInfoAdapter = new InvestmentInfoAdapter(); + recyclerView.setAdapter(investmentInfoAdapter); + recyclerView.setHasFixedSize(true); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); + recyclerView.setLayoutManager(linearLayoutManager); + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentMoreInfoAdapter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentMoreInfoAdapter.java new file mode 100644 index 00000000..cc652b5f --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentMoreInfoAdapter.java @@ -0,0 +1,75 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import android.content.res.Resources; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.example.alessandrofsouza.santanderapp.R; +import com.example.alessandrofsouza.santanderapp.domain.model.Infos; + +import java.util.ArrayList; + +class InvestmentMoreInfoAdapter extends RecyclerView.Adapter { + + private static final String TAG = "Santander "; + private ArrayList dataSet; + + public InvestmentMoreInfoAdapter() { + dataSet = new ArrayList<>(); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + View viewText = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.invest_more_info, viewGroup, false); + return new InvestmentMoreInfoAdapter.ViewHolder(viewText); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { + //TODO: create holderPresenter + Infos info = dataSet.get(i); + Resources resources = viewHolder.itemView.getContext().getResources(); + + viewHolder.info_title.setText(info.getTitle()); + viewHolder.info_fundo.setText(info.getName()); + viewHolder.info_Cdi.setText(info.getData()); + + } + + @Override + public int getItemViewType(int position) { + return position; + } + + @Override + public int getItemCount() { + return dataSet.size(); + } + + public void addListMoreInfo(ArrayList moreInfo) { + dataSet.addAll(moreInfo); + notifyDataSetChanged(); + } + + + public class ViewHolder extends RecyclerView.ViewHolder { + + private TextView info_title; + private TextView info_fundo; + private TextView info_Cdi; + + + public ViewHolder(@NonNull View itemView) { + super(itemView); + + info_title = itemView.findViewById(R.id.moreInfo_title); + info_fundo = itemView.findViewById(R.id.moreInfo_fundo); + info_Cdi = itemView.findViewById(R.id.moreInfo_cdi); + } + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentPresenter.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentPresenter.java new file mode 100644 index 00000000..6a15571b --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/pages/investment/InvestmentPresenter.java @@ -0,0 +1,52 @@ +package com.example.alessandrofsouza.santanderapp.presentation.pages.investment; + +import android.support.annotation.NonNull; +import android.util.Log; + +import com.example.alessandrofsouza.santanderapp.data.service.ApiService; +import com.example.alessandrofsouza.santanderapp.domain.model.InvestmentModel; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class InvestmentPresenter implements InvestmentContract.Presenter{ + + private static final String TAG = "Santander "; + private InvestmentContract.View view; + private ApiService service; + + public InvestmentPresenter(@NonNull InvestmentContract.View investmentView) { + view = investmentView; + view.setPresenter(this); + service = new ApiService(); + } + + @Override + public void init() { + getInvestmentScreen(); + } + + @Override + public void getInvestmentScreen() { + service.getApi().listInvestment().enqueue(new Callback() { + @NonNull + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + InvestmentModel investmentModel = response.body(); + + view.showInvestmentScreen(investmentModel.getScreen()); + } else { + Log.e(TAG, "Error Unsuccessful " + response.errorBody()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Log.e(TAG, "Error Failure " + t.getMessage()); + } + }); + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/Constants.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/Constants.java new file mode 100644 index 00000000..871ff99e --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/Constants.java @@ -0,0 +1,15 @@ +package com.example.alessandrofsouza.santanderapp.presentation.utils; + +public class Constants { + + public static final int TYPE_FIELD = 1; + public static final int TYPE_TEXT = 2; + public static final int TYPE_IMAGE = 3; + public static final int TYPE_CHECKBOX = 4; + public static final int TYPE_SEND = 5; + + public static final String TYPEFIELD_TEXT_T = "1"; + public static final String TYPEFIELD_TELNUMBER_T = "telnumber"; + public static final String TYPEFIELD_EMAIL_T = "3"; + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/EmailValidator.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/EmailValidator.java new file mode 100644 index 00000000..3626f435 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/EmailValidator.java @@ -0,0 +1,20 @@ +package com.example.alessandrofsouza.santanderapp.presentation.utils; + +import java.util.regex.Pattern; + +public class EmailValidator { + + public static final Pattern EMAIL_PATTERN = Pattern.compile( + ("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + + "\\@" + + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + + "(" + + "\\." + + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + + "){1,2}") + ); + + public static boolean validateEmail(CharSequence email) { + return email != null && EMAIL_PATTERN.matcher(email).matches(); + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/NameValidator.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/NameValidator.java new file mode 100644 index 00000000..d45da3d2 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/NameValidator.java @@ -0,0 +1,15 @@ +package com.example.alessandrofsouza.santanderapp.presentation.utils; + +import java.util.regex.Pattern; + +public class NameValidator { + + public static final Pattern NAME_PATTERN = Pattern.compile( + ("^[a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+(?:[\\s.]+[a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+)*${1,6}") + ); + + public static boolean validateName(CharSequence name) { + return name != null && NAME_PATTERN.matcher(name).matches(); + } + +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/PhoneNumberFormat.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/PhoneNumberFormat.java new file mode 100644 index 00000000..492c4109 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/PhoneNumberFormat.java @@ -0,0 +1,159 @@ +package com.example.alessandrofsouza.santanderapp.presentation.utils; + +import android.support.annotation.NonNull; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.widget.EditText; + +import java.lang.ref.WeakReference; + +public class PhoneNumberFormat implements TextWatcher { + + private boolean mFormatting; // this is a flag which prevents the stack(onTextChanged) + private boolean clearFlag; + private int mLastStartLocation; + private String mLastBeforeText; + private WeakReference mWeakEditText; + private int MAX_SIZE = 10; + public String phoneNumbers; + + public String STATE_PHONE_VALIDATOR = "0"; + + + public PhoneNumberFormat(WeakReference editTextPhone) { + this.mWeakEditText = editTextPhone; + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + if (after == 0 && s.toString().equals("(")) { + clearFlag = true; + } + mLastStartLocation = start; + mLastBeforeText = s.toString(); + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + @Override + public void afterTextChanged(Editable s) { + // Make sure to ignore calls to afterTextChanged caused by the work done below + if (!mFormatting) { + mFormatting = true; + int curPos = mLastStartLocation; + String beforeValue = mLastBeforeText; + String currentValue = s.toString(); + String formattedValue = formatPhone(s); + if (currentValue.length() > beforeValue.length()) { + int setCusorPos = formattedValue.length() + - (beforeValue.length() - curPos); + mWeakEditText.get().setSelection(setCusorPos < 0 ? 0 : setCusorPos); + } else { + int setCusorPos = formattedValue.length() + - (currentValue.length() - curPos); + if(setCusorPos > 0 && !Character.isDigit(formattedValue.charAt(setCusorPos -1))){ + setCusorPos--; + } + mWeakEditText.get().setSelection(setCusorPos < 0 ? 0 : setCusorPos); + } + mFormatting = false; + stylePhoneField(); + } + } + + public String formatPhone(@NonNull Editable text) { + StringBuilder formattedString = new StringBuilder(); + + // Remove everything except digits + int p = 0; + while (p < text.length()) { + char ch = text.charAt(p); + if (!Character.isDigit(ch)) { + text.delete(p, p + 1); + } else { + p++; + } + } + + // Now only digits are remaining + String allDigitString = text.toString(); + + int totalDigitCount = allDigitString.length(); + + //clean if dont have numbers + if (totalDigitCount == 0) { + text.clear(); + text.append(allDigitString); + return allDigitString; + } + + int alreadyPlacedDigitCount = 0; + + // The first 2 numbers must be enclosed in brackets "()" + if (totalDigitCount - alreadyPlacedDigitCount > 2) { + formattedString.append("(" + + allDigitString.substring(alreadyPlacedDigitCount, + alreadyPlacedDigitCount + 2) + ") "); + alreadyPlacedDigitCount += 2; + } + + //dash"-" (valid BR 9 for mobile phones) + if (totalDigitCount - alreadyPlacedDigitCount > 5) { + int validDigit = 2; + + if (String.valueOf(allDigitString.charAt(validDigit)).equals("9")) { + MAX_SIZE = 11; + formattedString.append(allDigitString.substring(alreadyPlacedDigitCount, alreadyPlacedDigitCount + 5) + "-"); + alreadyPlacedDigitCount += 5; + + } else { + MAX_SIZE = 10; + formattedString.append(allDigitString.substring(alreadyPlacedDigitCount, alreadyPlacedDigitCount + 4) + "-"); + alreadyPlacedDigitCount += 4; + } + } + + + // All the required formatting is done so we'll just copy the remaining digits. + if (totalDigitCount > alreadyPlacedDigitCount) { + formattedString.append(allDigitString + .substring(alreadyPlacedDigitCount)); + } + + //delete number after max size + if(totalDigitCount > MAX_SIZE) { + formattedString.delete(text.length() - 1, text.length()).toString(); + } + + + text.clear(); + text.append(formattedString.toString()); + + PhoneValidator.validatePhone(formattedString.toString()); + phoneNumbers = formattedString.toString().replaceAll("[^\\d]", ""); + + return formattedString.toString(); + //REF: https://stackoverflow.com/a/23659268 + } + + + public String stylePhoneField() { + + if (phoneNumbers.isEmpty()) { + STATE_PHONE_VALIDATOR = "0"; + + } else if (MAX_SIZE == 10 && PhoneValidator.PHONE8_PATTERN.matcher(phoneNumbers).matches()) { + STATE_PHONE_VALIDATOR = "2"; + + } else if (MAX_SIZE == 11 && PhoneValidator.PHONE9_PATTERN.matcher(phoneNumbers).matches()) { + STATE_PHONE_VALIDATOR = "2"; + + } else { + STATE_PHONE_VALIDATOR = "1"; + } + + return STATE_PHONE_VALIDATOR; + } +} diff --git a/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/PhoneValidator.java b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/PhoneValidator.java new file mode 100644 index 00000000..08051019 --- /dev/null +++ b/SantanderTeste/app/src/main/java/com/example/alessandrofsouza/santanderapp/presentation/utils/PhoneValidator.java @@ -0,0 +1,23 @@ +package com.example.alessandrofsouza.santanderapp.presentation.utils; + + +import java.util.regex.Pattern; + +public class PhoneValidator { + + private static final String TAG = "Santander "; + + public static final Pattern PHONE8_PATTERN = Pattern.compile( + ("^[+]?[0-9]{10}$") + ); + + public static final Pattern PHONE9_PATTERN = Pattern.compile( + ("^[+]?[0-9]{11}$") + ); + + + public static boolean validatePhone(CharSequence phone) { + return phone != null && PHONE8_PATTERN.matcher(phone).matches() || phone != null && PHONE9_PATTERN.matcher(phone).matches(); + } + +} diff --git a/SantanderTeste/app/src/main/res/drawable-v21/separator.xml b/SantanderTeste/app/src/main/res/drawable-v21/separator.xml new file mode 100644 index 00000000..1d53b957 --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable-v21/separator.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/SantanderTeste/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..1f6bb290 --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/SantanderTeste/app/src/main/res/drawable/arrow.xml b/SantanderTeste/app/src/main/res/drawable/arrow.xml new file mode 100644 index 00000000..1d94a211 --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable/arrow.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/drawable/bg_tab.xml b/SantanderTeste/app/src/main/res/drawable/bg_tab.xml new file mode 100644 index 00000000..ea8ce322 --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable/bg_tab.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/drawable/download.xml b/SantanderTeste/app/src/main/res/drawable/download.xml new file mode 100644 index 00000000..debff14f --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable/download.xml @@ -0,0 +1,28 @@ + + + + + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/drawable/ic_launcher_background.xml b/SantanderTeste/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..e1572508 --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SantanderTeste/app/src/main/res/drawable/roundedbutton.xml b/SantanderTeste/app/src/main/res/drawable/roundedbutton.xml new file mode 100644 index 00000000..9aa14d2b --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable/roundedbutton.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/drawable/separator.xml b/SantanderTeste/app/src/main/res/drawable/separator.xml new file mode 100644 index 00000000..1d53b957 --- /dev/null +++ b/SantanderTeste/app/src/main/res/drawable/separator.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/drawable/shape.png b/SantanderTeste/app/src/main/res/drawable/shape.png new file mode 100644 index 00000000..b94e990c Binary files /dev/null and b/SantanderTeste/app/src/main/res/drawable/shape.png differ diff --git a/SantanderTeste/app/src/main/res/drawable/share.png b/SantanderTeste/app/src/main/res/drawable/share.png new file mode 100644 index 00000000..3a5d1765 Binary files /dev/null and b/SantanderTeste/app/src/main/res/drawable/share.png differ diff --git a/SantanderTeste/app/src/main/res/font/dinengschriftstd.otf b/SantanderTeste/app/src/main/res/font/dinengschriftstd.otf new file mode 100755 index 00000000..ae85f8ee Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinengschriftstd.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinmttelschriftstd.otf b/SantanderTeste/app/src/main/res/font/dinmttelschriftstd.otf new file mode 100755 index 00000000..9a6e0d4f Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinmttelschriftstd.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinneuzeitgroteskstd_bdcond.otf b/SantanderTeste/app/src/main/res/font/dinneuzeitgroteskstd_bdcond.otf new file mode 100755 index 00000000..1da42b06 Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinneuzeitgroteskstd_bdcond.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinneuzeitgroteskstd_light.otf b/SantanderTeste/app/src/main/res/font/dinneuzeitgroteskstd_light.otf new file mode 100755 index 00000000..0cda2e5b Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinneuzeitgroteskstd_light.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinpro_black.otf b/SantanderTeste/app/src/main/res/font/dinpro_black.otf new file mode 100755 index 00000000..2092a7bb Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinpro_black.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinpro_bold.otf b/SantanderTeste/app/src/main/res/font/dinpro_bold.otf new file mode 100755 index 00000000..7c839536 Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinpro_bold.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinpro_light.otf b/SantanderTeste/app/src/main/res/font/dinpro_light.otf new file mode 100755 index 00000000..8a7f085a Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinpro_light.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinpro_medium.otf b/SantanderTeste/app/src/main/res/font/dinpro_medium.otf new file mode 100755 index 00000000..b4608d06 Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinpro_medium.otf differ diff --git a/SantanderTeste/app/src/main/res/font/dinpro_regular.otf b/SantanderTeste/app/src/main/res/font/dinpro_regular.otf new file mode 100755 index 00000000..84d57abb Binary files /dev/null and b/SantanderTeste/app/src/main/res/font/dinpro_regular.otf differ diff --git a/SantanderTeste/app/src/main/res/layout/activity_main.xml b/SantanderTeste/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..893d9f24 --- /dev/null +++ b/SantanderTeste/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,30 @@ + + + + + + + + \ No newline at end of file diff --git a/SantanderTeste/app/src/main/res/layout/contact.xml b/SantanderTeste/app/src/main/res/layout/contact.xml new file mode 100644 index 00000000..e494b362 --- /dev/null +++ b/SantanderTeste/app/src/main/res/layout/contact.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + +