├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── drawable │ │ │ │ ├── placeholder.jpg │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── nopalsoft │ │ │ │ └── simple │ │ │ │ └── rest │ │ │ │ ├── model │ │ │ │ ├── UserPicture.kt │ │ │ │ ├── UserLocation.kt │ │ │ │ ├── UserName.kt │ │ │ │ ├── ApiResponse.kt │ │ │ │ └── User.kt │ │ │ │ ├── MyApplication.kt │ │ │ │ ├── ui │ │ │ │ └── theme │ │ │ │ │ ├── Color.kt │ │ │ │ │ ├── Shape.kt │ │ │ │ │ ├── Type.kt │ │ │ │ │ └── Theme.kt │ │ │ │ ├── datasource │ │ │ │ ├── DbDataSource.kt │ │ │ │ └── RestDataSource.kt │ │ │ │ ├── di │ │ │ │ ├── RepositoryModule.kt │ │ │ │ └── DataSourceModule.kt │ │ │ │ ├── repository │ │ │ │ └── UserRepository.kt │ │ │ │ ├── UserViewModel.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ ├── resources │ │ │ ├── api_name.json │ │ │ ├── api_picture.json │ │ │ └── api_location.json │ │ └── java │ │ │ └── com │ │ │ └── nopalsoft │ │ │ └── simple │ │ │ └── rest │ │ │ └── UserRepositoryTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── nopalsoft │ │ └── simple │ │ └── rest │ │ ├── utils │ │ ├── CustomTestRunner.kt │ │ └── FakeRepositoryModule.kt │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── .idea ├── .gitignore ├── compiler.xml ├── vcs.xml ├── deploymentTargetDropDown.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml └── misc.xml ├── screenshots ├── image1.png └── youtube1.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /screenshots/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/screenshots/image1.png -------------------------------------------------------------------------------- /screenshots/youtube1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/screenshots/youtube1.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | JetpackComposeSimpreRestApi 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/placeholder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/drawable/placeholder.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/model/UserPicture.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.model 2 | 3 | data class UserPicture( 4 | val thumbnail: String, 5 | ) -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yayo-Arellano/JetpackComposeSimpleRestApi/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/model/UserLocation.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.model 2 | 3 | data class UserLocation( 4 | val city: String, 5 | val state: String, 6 | ) -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/model/UserName.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.model 2 | 3 | data class UserName( 4 | val title: String, 5 | val first: String, 6 | val last: String, 7 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/MyApplication.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class MyApplication : Application() -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Oct 18 21:49:09 CST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val Purple200 = Color(0xFFBB86FC) 6 | val Purple500 = Color(0xFF6200EE) 7 | val Purple700 = Color(0xFF3700B3) 8 | val Teal200 = Color(0xFF03DAC5) -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/model/ApiResponse.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.model 2 | 3 | data class ApiResponse( 4 | val results: List = emptyList(), 5 | ) 6 | 7 | data class Results( 8 | val name: UserName?, 9 | val location: UserLocation?, 10 | val picture: UserPicture?, 11 | ) -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/test/resources/api_name.json: -------------------------------------------------------------------------------- 1 | { 2 | "results": [ 3 | { 4 | "name": { 5 | "title": "Mr", 6 | "first": "Wayne", 7 | "last": "Collins" 8 | } 9 | } 10 | ], 11 | "info": { 12 | "seed": "630efe079ab07323", 13 | "results": 1, 14 | "page": 1, 15 | "version": "1.3" 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | dependencyResolutionManagement { 2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 3 | repositories { 4 | google() 5 | mavenCentral() 6 | jcenter() // Warning: this repository is going to shut down soon 7 | } 8 | } 9 | rootProject.name = "JetpackComposeSimpreRestApi" 10 | include ':app' 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/ui/theme/Shape.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.ui.theme 2 | 3 | import androidx.compose.foundation.shape.RoundedCornerShape 4 | import androidx.compose.material.Shapes 5 | import androidx.compose.ui.unit.dp 6 | 7 | val Shapes = Shapes( 8 | small = RoundedCornerShape(4.dp), 9 | medium = RoundedCornerShape(4.dp), 10 | large = RoundedCornerShape(0.dp) 11 | ) -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/datasource/DbDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.datasource 2 | 3 | import androidx.room.Database 4 | import androidx.room.RoomDatabase 5 | import com.nopalsoft.simple.rest.model.User 6 | import com.nopalsoft.simple.rest.model.UserDao 7 | 8 | @Database(entities = [User::class], version = 1) 9 | abstract class DbDataSource : RoomDatabase() { 10 | 11 | abstract fun userDao(): UserDao 12 | } -------------------------------------------------------------------------------- /app/src/test/resources/api_picture.json: -------------------------------------------------------------------------------- 1 | { 2 | "results": [ 3 | { 4 | "picture": { 5 | "large": "https://randomuser.me/api/portraits/women/78.jpg", 6 | "medium": "https://randomuser.me/api/portraits/med/women/78.jpg", 7 | "thumbnail": "https://randomuser.me/api/portraits/thumb/women/78.jpg" 8 | } 9 | } 10 | ], 11 | "info": { 12 | "seed": "a3b73d39488b4875", 13 | "results": 1, 14 | "page": 1, 15 | "version": "1.3" 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/datasource/RestDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.datasource 2 | 3 | import com.nopalsoft.simple.rest.model.ApiResponse 4 | import retrofit2.http.GET 5 | 6 | 7 | interface RestDataSource { 8 | 9 | @GET("?inc=name") 10 | suspend fun getUserName(): ApiResponse 11 | 12 | @GET("?inc=location") 13 | suspend fun getUserLocation(): ApiResponse 14 | 15 | @GET("?inc=picture") 16 | suspend fun getUserPicture(): ApiResponse 17 | } 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/nopalsoft/simple/rest/utils/CustomTestRunner.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.utils 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import androidx.test.runner.AndroidJUnitRunner 6 | import dagger.hilt.android.testing.HiltTestApplication 7 | 8 | class CustomTestRunner : AndroidJUnitRunner() { 9 | 10 | override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { 11 | return super.newApplication(cl, HiltTestApplication::class.java.name, context) 12 | } 13 | } -------------------------------------------------------------------------------- /.idea/deploymentTargetDropDown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple REST API 2 | 3 | Learn how to make an Android App that will call a REST API using Retrofit to retrieve some data that will be 4 | stored in SQLite using Room library. Build the user interface with Jetpack Compose. 5 | 6 | Learn MVVM, dependency injection with Hilt and also add unit and instrumentation tests 7 | 8 | Watch the video in youtube (in spanish) 9 | 10 | # Video 11 | [![Youtube](https://github.com/Yayo-Arellano/JetpackComposeSimpleRestApi/blob/master/screenshots/youtube1.png?raw=true)](https://youtu.be/Td4wHh_ZivE) 12 | 13 | 14 | # Screenshots 15 | ![Screenshot1](https://github.com/Yayo-Arellano/JetpackComposeSimpleRestApi/blob/master/screenshots/image1.png?raw=true) 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/di/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.di 2 | 3 | import com.nopalsoft.simple.rest.repository.UserRepository 4 | import com.nopalsoft.simple.rest.repository.UserRepositoryImp 5 | import dagger.Binds 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.components.SingletonComponent 10 | import javax.inject.Singleton 11 | 12 | @Module 13 | @InstallIn(SingletonComponent::class) 14 | abstract class RepositoryModule { 15 | 16 | @Binds 17 | @Singleton 18 | abstract fun userRepository(repo: UserRepositoryImp): UserRepository 19 | } 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/test/resources/api_location.json: -------------------------------------------------------------------------------- 1 | { 2 | "results": [ 3 | { 4 | "location": { 5 | "street": { 6 | "number": 2159, 7 | "name": "Mcclellan Rd" 8 | }, 9 | "city": "Cairns", 10 | "state": "Victoria", 11 | "country": "Australia", 12 | "postcode": 8641, 13 | "coordinates": { 14 | "latitude": "-84.4848", 15 | "longitude": "96.7122" 16 | }, 17 | "timezone": { 18 | "offset": "+4:30", 19 | "description": "Kabul" 20 | } 21 | } 22 | } 23 | ], 24 | "info": { 25 | "seed": "c5720106ec49ba1f", 26 | "results": 1, 27 | "page": 1, 28 | "version": "1.3" 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/model/User.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.model 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.room.* 5 | 6 | @Entity(tableName = "user") 7 | data class User( 8 | @ColumnInfo(name = "name") val name: String, 9 | @ColumnInfo(name = "lastName") val lastName: String, 10 | @ColumnInfo(name = "city") val city: String, 11 | @ColumnInfo(name = "thumbnail") val thumbnail: String, 12 | @PrimaryKey(autoGenerate = true) var id: Int = 0 13 | ) 14 | 15 | @Dao 16 | interface UserDao { 17 | @Insert(onConflict = OnConflictStrategy.REPLACE) 18 | fun insert(user: User) 19 | 20 | @Query("SELECT * FROM user ORDER BY id DESC") 21 | fun getAll(): LiveData> 22 | 23 | @Delete 24 | fun delete(user: User) 25 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.ui.theme 2 | 3 | import androidx.compose.material.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | body1 = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp 15 | ) 16 | /* Other default text styles to override 17 | button = TextStyle( 18 | fontFamily = FontFamily.Default, 19 | fontWeight = FontWeight.W500, 20 | fontSize = 14.sp 21 | ), 22 | caption = TextStyle( 23 | fontFamily = FontFamily.Default, 24 | fontWeight = FontWeight.Normal, 25 | fontSize = 12.sp 26 | ) 27 | */ 28 | ) -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /app/src/main/java/com/nopalsoft/simple/rest/repository/UserRepository.kt: -------------------------------------------------------------------------------- 1 | package com.nopalsoft.simple.rest.repository 2 | 3 | import androidx.lifecycle.LiveData 4 | import com.nopalsoft.simple.rest.datasource.RestDataSource 5 | import com.nopalsoft.simple.rest.model.User 6 | import com.nopalsoft.simple.rest.model.UserDao 7 | import kotlinx.coroutines.delay 8 | import javax.inject.Inject 9 | 10 | interface UserRepository { 11 | suspend fun getNewUser(): User 12 | suspend fun deleteUser(toDelete: User) 13 | fun getAllUsers(): LiveData> 14 | 15 | } 16 | 17 | class UserRepositoryImp @Inject constructor( 18 | private val dataSource: RestDataSource, 19 | private val userDao: UserDao 20 | ) : UserRepository { 21 | 22 | override suspend fun getNewUser(): User { 23 | delay(3000) 24 | val name = dataSource.getUserName().results[0].name!! 25 | val location = dataSource.getUserLocation().results[0].location!! 26 | val picture = dataSource.getUserPicture().results[0].picture!! 27 | val user = User(name.first, name.last, location.city, picture.thumbnail) 28 | userDao.insert(user) 29 | return user 30 | } 31 | 32 | override fun getAllUsers() = userDao.getAll() 33 | 34 | override suspend fun deleteUser(toDelete: User) = userDao.delete(toDelete) 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 21 | 22 |