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

Teste Finalizado #29

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
553f579
First commit
PauloRenatoG Nov 13, 2020
d99fa86
First project setup with dagger, retrofit and Room.
PauloRenatoG Nov 14, 2020
f7bce42
Merge pull request #1 from PauloRenatoG/feature/setup
PauloRenatoG Nov 14, 2020
2d282b2
Setup data base, paging, use case and repositories to get list of peo…
PauloRenatoG Nov 15, 2020
62a826f
Created fragment with navigation to list people.
PauloRenatoG Nov 15, 2020
a0b6130
Update Room and Paging version.
PauloRenatoG Nov 15, 2020
8888f35
Merge pull request #2 from PauloRenatoG/feature/list-people
PauloRenatoG Nov 15, 2020
bf749ae
Created data source to person detail.
PauloRenatoG Nov 16, 2020
0fa66bf
Created domain to person details.
PauloRenatoG Nov 16, 2020
20550ee
Created layout to display person details.
PauloRenatoG Nov 16, 2020
d102bdf
Merge pull request #3 from PauloRenatoG/feature/people_detail
PauloRenatoG Nov 16, 2020
277f89c
Merge pull request #4 from PauloRenatoG/develop
PauloRenatoG Nov 21, 2020
782d70c
Included filter to list favorites from database local.
PauloRenatoG Nov 21, 2020
2bf29fe
Merge pull request #5 from PauloRenatoG/feature/favorites
PauloRenatoG Nov 21, 2020
8c2095d
Merge pull request #6 from PauloRenatoG/develop
PauloRenatoG Nov 21, 2020
30eb766
Included ApiPeople favorite
PauloRenatoG Nov 21, 2020
8cb33e0
Merge pull request #7 from PauloRenatoG/feature/favorites
PauloRenatoG Nov 21, 2020
77892c9
refactor: update version of libraries and sdk version
PauloRenatoG Jan 5, 2022
e6c6a94
refactor: update di annotations from hilt
PauloRenatoG Jan 5, 2022
5c5c8e4
refactor: update code logic from paging
PauloRenatoG Jan 5, 2022
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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*.iml
.gradle
/local.properties
/.idea
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
build
/captures
.externalNativeBuild
.cxx
*.class
bin/
gen/
local.properties
local.gradle
release/
staging/
debug/
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
91 changes: 91 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id "androidx.navigation.safeargs.kotlin"
id 'dagger.hilt.android.plugin'
}

android {
compileSdkVersion 31
buildToolsVersion "31.0.0"

defaultConfig {
applicationId "br.com.example.starwars"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

dataBinding {
enabled = true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", "API_ENDPOINT", "\"$rootProject.ext.apiEndpoint/\""
}

debug {
buildConfigField "String", "API_ENDPOINT", "\"$rootProject.ext.apiEndpoint/\""
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

// Kotlin
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "androidx.core:core-ktx:$kotlinCoreVersion"

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$navVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navVersion"

// LifeCycle
implementation "androidx.lifecycle:lifecycle-extensions:$lifeCycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$viewModelVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$viewModelVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$liveDataVersion"
implementation "androidx.fragment:fragment-ktx:1.4.0"

// Hilt
implementation "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"

// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
api "com.squareup.retrofit2:converter-gson:$retrofitVersion"

// Room
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
implementation "androidx.room:room-ktx:$roomVersion"
implementation "androidx.room:room-paging:2.4.0"

// Android
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintlayoutVersion"
implementation "com.google.android.material:material:$materialVersion"

// Paging
implementation "androidx.paging:paging-runtime-ktx:$pagingVersion"
testImplementation "androidx.paging:paging-common-ktx:$pagingVersion"

// Tests
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$junitExtVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
}
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 br.com.example.starwars

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

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".presentation.ApplicationStarWars"
android:theme="@style/Theme.StarWars">
<activity android:name=".presentation.ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package br.com.example.starwars.data.entities


import com.google.gson.annotations.SerializedName

data class ApiListPeopleResponse(
@SerializedName("count")
val count: Int? = null,
@SerializedName("results")
val people: List<ApiPeople>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package br.com.example.starwars.data.entities


import androidx.room.Entity
import androidx.room.PrimaryKey
import br.com.example.starwars.domain.entities.People
import com.google.gson.annotations.SerializedName

@Entity(tableName = "people")
data class ApiPeople(
@PrimaryKey(autoGenerate = true)
val id: Int?,
@SerializedName("gender")
val gender: String? = null,
@SerializedName("height")
val height: String? = null,
@SerializedName("mass")
val mass: String? = null,
@SerializedName("name")
val name: String? = null,
@SerializedName("url")
val url: String? = null,
@SerializedName("hair_color")
val hairColor: String? = null,
@SerializedName("skin_color")
val skinColor: String? = null,
@SerializedName("eye_color")
val eyeColor: String? = null,
@SerializedName("birth_year")
val birthYear: String? = null,
@SerializedName("homeworld")
val homeWorld: String? = null,
@SerializedName("species")
val species: List<String>? = null,
val favorite: Boolean = false
) {

fun apiPeopleToPeople(apiPeople: ApiPeople): People {
return People(
id = apiPeople.id,
name = apiPeople.name,
height = apiPeople.height,
gender = apiPeople.gender,
mass = apiPeople.mass,
url = apiPeople.url,
hairColor = apiPeople.hairColor,
skinColor = apiPeople.skinColor,
eyeColor = apiPeople.eyeColor,
birthYear = apiPeople.birthYear,
homeWorld = apiPeople.homeWorld,
species = apiPeople.species,
favorite = apiPeople.favorite
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package br.com.example.starwars.data.entities

import br.com.example.starwars.domain.entities.Planet
import com.google.gson.annotations.SerializedName

data class ApiPlanet(
@SerializedName("name")
val name: String? = null
) {
fun apiPlanetToPlanet(apiPlanet: ApiPlanet): Planet {
return Planet(
name = apiPlanet.name
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package br.com.example.starwars.data.entities

import br.com.example.starwars.domain.entities.Specie
import com.google.gson.annotations.SerializedName

data class ApiSpecie(
@SerializedName("name")
val name: String? = null
) {
fun apiSpecieToSpecie(apiSpecie: ApiSpecie): Specie {
return Specie(
name = apiSpecie.name
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package br.com.example.starwars.data.entities

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "remote_keys")
data class RemoteKeys(
@PrimaryKey(autoGenerate = true)
val repoId: Long? = 0,
val prevKey: Int?,
val nextKey: Int?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package br.com.example.starwars.data.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import br.com.example.starwars.data.entities.ApiPeople
import br.com.example.starwars.data.entities.RemoteKeys
import br.com.example.starwars.data.util.StringListConverter

@Database(entities = [ApiPeople::class, RemoteKeys::class], version = 1, exportSchema = false)
@TypeConverters(StringListConverter::class)
abstract class AppDataBase : RoomDatabase() {

abstract fun peopleDao(): PeopleDao
abstract fun remoteKeysDao(): RemoteKeysDao

companion object {
private const val DATABASE_NAME = "star-wars-db"

fun build(context: Context): AppDataBase {
return Room.databaseBuilder(
context,
AppDataBase::class.java, DATABASE_NAME
).build()
}
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/br/com/example/starwars/data/local/PeopleDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package br.com.example.starwars.data.local

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import br.com.example.starwars.data.entities.ApiPeople

@Dao
interface PeopleDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(apiPeople: List<ApiPeople>)

@Query("SELECT * FROM people")
fun getListPeople(): PagingSource<Int, ApiPeople>

@Query("UPDATE people SET favorite = :favorite WHERE id = :id")
suspend fun updatePerson(favorite: Boolean, id: Int)

@Query("DELETE FROM people")
suspend fun clearPeople()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package br.com.example.starwars.data.local

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import br.com.example.starwars.data.entities.RemoteKeys

@Dao
interface RemoteKeysDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(remoteKey: RemoteKeys)

@Query("SELECT * FROM remote_keys WHERE repoId = :repoId")
suspend fun remoteKeysRepoId(repoId: Long): RemoteKeys?

@Query("DELETE FROM remote_keys")
suspend fun clearRemoteKeys()
}
Loading