Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 45 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@ apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "br.com.aisdigital.androidchallenge"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
Expand All @@ -26,10 +41,31 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation "com.google.dagger:dagger:2.37"
kapt "com.google.dagger:dagger-compiler:2.37"

api 'com.google.dagger:dagger-android:2.37'
api 'com.google.dagger:dagger-android-support:2.37'
kapt 'com.google.dagger:dagger-android-processor:2.37'

implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"

implementation 'com.google.android.material:material:1.3.0'

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

testImplementation 'junit:junit:4.13'

androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

kapt {
correctErrorTypes true
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package br.com.aisdigital.androidchallenge

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.aisdigital.androidchallenge">

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

<application
android:name=".ChallengeApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package br.com.aisdigital.androidchallenge

import android.R
import android.app.ProgressDialog
import android.os.Handler
import android.os.HandlerThread
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper

open class BaseActivity : AppCompatActivity() {

var handler: Handler? = null;
var handlerThread: HandlerThread? = null;
var progressDialog: ProgressDialog? = null;

fun makeToast(message: String) {
Toast.makeText(
this,
message,
Toast.LENGTH_LONG
).show();
}

open fun showProgressDialog(title: String?, message: String?) {
if (!isFinishing) {
progressDialog =
ProgressDialog(ContextThemeWrapper(this, R.style.Theme_Holo_Light_Dialog));

if (!title.isNullOrEmpty()) progressDialog!!.setTitle(title);
if (!message.isNullOrEmpty()) progressDialog!!.setMessage(message);

progressDialog!!.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog!!.setCancelable(false);
progressDialog!!.setIndeterminate(true);
progressDialog!!.show();
}
}

open fun closeProgressDialog() {
if (!isFinishing && progressDialog != null) {
try {
progressDialog!!.dismiss();
} catch (e: Exception) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package br.com.aisdigital.androidchallenge

import android.app.Application
import br.com.aisdigital.androidchallenge.retrofit.RequestService
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject

@HiltAndroidApp
class ChallengeApplication : Application() {

@Inject
lateinit var requestService: RequestService;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,85 @@
package br.com.aisdigital.androidchallenge

import androidx.appcompat.app.AppCompatActivity
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.view.View
import android.widget.Button
import android.widget.EditText
import br.com.aisdigital.androidchallenge.retrofit.RequestService
import br.com.aisdigital.androidchallenge.util.SharedPrefUtil
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

class MainActivity : AppCompatActivity() {
@AndroidEntryPoint
class MainActivity : BaseActivity(), View.OnClickListener {

@Inject
lateinit var requestService: RequestService;

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setContentView(R.layout.activity_main);

findViewById<Button>(R.id.button_auth).setOnClickListener(this);
}

override fun onClick(view: View?) {
when (view?.id) {
R.id.button_auth -> {
onAuthClick();
}
}
}

private fun onAuthClick() {
val username: String = findViewById<EditText>(R.id.edit_username).text.toString();
val password: String = findViewById<EditText>(R.id.edit_password).text.toString();

if (username.isNullOrEmpty() || password.isNullOrEmpty()) {
makeToast("Login ou Senha incorreto.");
return;
}

showProgressDialog("Logando...", "");

val doAuth = Runnable {
val response = requestService.postAuth(username, password).execute();
if (response.isSuccessful) {
response.body()?.token?.let {
SharedPrefUtil.putToken(this@MainActivity, it)
};

onLogin();
} else {
makeToast("Erro ao tentar realizar a autenticação. Tente novamente mais tarde");
}
}

handlerThread = HandlerThread("Auth");
handlerThread!!.start();
handler = Handler(handlerThread!!.looper);
handler!!.post(doAuth);
}

private fun onLogin() {
val doLogin = Runnable {
val response = requestService.getLogin().execute();
if (response.isSuccessful) {
makeToast(String.format("Logado com o usuário: %s", response.body()?.name));

val intent = Intent(this@MainActivity, TeamListActivity::class.java);
startActivity(intent)

} else {
makeToast("Erro ao tentar buscar os dados do usuário. Tente novamente mais tarde");
}
}

handlerThread = HandlerThread("Login");
handlerThread!!.start();
handler = Handler(handlerThread!!.looper);
handler!!.post(doLogin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package br.com.aisdigital.androidchallenge

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import br.com.aisdigital.androidchallenge.util.SharedPrefUtil

class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
}

override fun onPostResume() {
super.onPostResume();

val intent = if (SharedPrefUtil.getToken(this@SplashActivity).isNullOrEmpty()) {
Intent(this@SplashActivity, MainActivity::class.java);
} else {
Intent(this@SplashActivity, TeamListActivity::class.java);
}
startActivity(intent);
finish();
}
}
Loading