Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desafio Android #38

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
98 changes: 98 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.siedg.desafio_android"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "BASE_URL", "\"http://swapi.dev/\""
buildConfigField "String", "FAVORITE_API_URL", "\"http://docs.starwarsfavorites.apiary.io/#\""
}

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'
}
buildFeatures {
dataBinding = true
}
}

dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
def lifecycle_version = "2.2.0"
def coroutines_version = "1.3.8"
def timber_version = "4.7.1"
def dagger_version = "2.28.3"
def retrofit_version = "2.9.0"
def ok_http_version = "4.8.1"
def groupie_version = "2.3.0"
def glide_version = "4.11.0"

// Groupie
implementation "com.xwray:groupie:$groupie_version"
implementation "com.xwray:groupie-kotlin-android-extensions:$groupie_version"
implementation "com.xwray:groupie-databinding:$groupie_version"

// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
// Timber
implementation "com.jakewharton.timber:timber:$timber_version"
// Dagger
implementation "com.google.dagger:dagger:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
// Gson Converter
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
// OkHTTP
implementation "com.squareup.okhttp3:okhttp:$ok_http_version"
// Glide
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"



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.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

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

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

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.siedg.desafio_android

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.siedg.desafio_android", appContext.packageName)
}
}
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.siedg.desafio_android">

<application
android:name=".presentation.App"
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/Theme.Desafioandroid">
<activity android:name=".presentation.ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
17 changes: 17 additions & 0 deletions app/src/main/java/com/siedg/desafio_android/data/api/ApiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.siedg.desafio_android.data.api

import com.siedg.desafio_android.data.model.*
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query

interface ApiService {
@GET("people")
suspend fun getPersonList(@Query("page") index: Int): Response<PersonList>

@GET("planets")
suspend fun getPlanetsList(@Query("page") index: Int): Response<PlanetList>

@GET("species")
suspend fun getSpeciesList(@Query("page") index: Int): Response<SpecieList>
}
60 changes: 60 additions & 0 deletions app/src/main/java/com/siedg/desafio_android/data/model/Person.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.siedg.desafio_android.data.model

import com.google.gson.annotations.SerializedName

data class Person(
@SerializedName("name")
val name: String,
@SerializedName("height")
val height: String,
@SerializedName("mass")
val mass: String,
@SerializedName("hair_color")
val hairColor: String,
@SerializedName("skin_color")
val skinColor: String,
@SerializedName("eye_color")
val eyeColor: String,
@SerializedName("birth_year")
val birthYear: String,
@SerializedName("gender")
val gender: String,
@SerializedName("homeworld")
val homeworld: String,
@SerializedName("films")
val films: List<String>,
@SerializedName("species")
val species: List<String>,
@SerializedName("vehicles")
val vehicles: List<String>,
@SerializedName("starships")
val starships: List<String>,
@SerializedName("created")
val created: String,
@SerializedName("edited")
val edited: String,
@SerializedName("url")
val url: String
)

fun Person.toModel() : PersonModel {
return PersonModel(
name,
height.toDouble(),
mass.toDouble(),
hairColor,
skinColor,
eyeColor,
birthYear,
gender,
homeworld,
films,
species,
vehicles,
starships,
created,
edited,
url,
false
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.siedg.desafio_android.data.model

import com.google.gson.annotations.SerializedName

data class PersonList(
@SerializedName("count")
val count: Int,
@SerializedName("next")
val next: String?,
@SerializedName("previous")
val previous: String?,
@SerializedName("results")
val results: List<Person>
)

fun PersonList.mapToModel(): List<PersonModel> {
return this.results.map { value -> value.toModel() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.siedg.desafio_android.data.model

data class PersonModel (
val name: String,
val height: Double,
val mass: Double,
val hairColor: String,
val skinColor: String,
val eyeColor: String,
val birthYear: String,
val gender: String,
val homeworld: String,
val films: List<String>,
val species: List<String>,
val vehicles: List<String>,
val starships: List<String>,
val created: String,
val edited: String,
val url: String,
val isFavorite: Boolean
)
46 changes: 46 additions & 0 deletions app/src/main/java/com/siedg/desafio_android/data/model/Planet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.siedg.desafio_android.data.model

import com.google.gson.annotations.SerializedName

data class Planet (
@SerializedName("climate")
val climate: String,
@SerializedName("diameter")
val diameter: String,
@SerializedName("gravity")
val gravity: String,
@SerializedName("name")
val name: String,
@SerializedName("orbital_period")
val orbitalPeriod: String,
@SerializedName("population")
val population: String,
@SerializedName("residents")
val residents: List<String>,
@SerializedName("rotation_period")
val rotationPeriod: String,
@SerializedName("surface_water")
val surfaceWater: String,
@SerializedName("terrain")
val terrain: String,
@SerializedName("url")
val url: String


)

fun Planet.toModel(): PlanetModel {
return PlanetModel(
climate,
diameter,
gravity,
name,
orbitalPeriod,
population,
residents,
rotationPeriod,
surfaceWater,
terrain,
url
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.siedg.desafio_android.data.model

import com.google.gson.annotations.SerializedName

data class PlanetList(
@SerializedName("count")
val count: Int,
@SerializedName("next")
val next: String?,
@SerializedName("previous")
val previous: String?,
@SerializedName("results")
val results: List<Planet>
)

fun PlanetList.mapToModel(): List<PlanetModel> {
return this.results.map { value -> value.toModel() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.siedg.desafio_android.data.model

import com.google.gson.annotations.SerializedName

class PlanetModel (
val climate: String,
val diameter: String,
val gravity: String,
val name: String,
val orbitalPeriod: String,
val population: String,
val residents: List<String>,
val rotationPeriod: String,
val surfaceWater: String,
val terrain: String,
val url: String
)
Loading