├── .github └── workflows │ ├── ci.yml │ └── testing.yml ├── .gitignore ├── .gradle ├── 7.4 │ ├── checksums │ │ └── checksums.lock │ ├── dependencies-accessors │ │ ├── dependencies-accessors.lock │ │ └── gc.properties │ ├── executionHistory │ │ ├── executionHistory.bin │ │ └── executionHistory.lock │ ├── fileChanges │ │ └── last-build.bin │ ├── fileHashes │ │ ├── fileHashes.bin │ │ ├── fileHashes.lock │ │ └── resourceHashesCache.bin │ └── gc.properties └── file-system.probe ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cursokotlin │ │ └── mvvmexample │ │ └── QuoteViewModelInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cursokotlin │ │ │ └── mvvmexample │ │ │ ├── MvvmExampleApp.kt │ │ │ ├── core │ │ │ └── RetrofitHelper.kt │ │ │ ├── data │ │ │ ├── QuoteRepository.kt │ │ │ ├── database │ │ │ │ ├── QuoteDatabase.kt │ │ │ │ ├── dao │ │ │ │ │ └── QuoteDao.kt │ │ │ │ └── entities │ │ │ │ │ └── QuoteEntity.kt │ │ │ ├── model │ │ │ │ └── QuoteModel.kt │ │ │ └── network │ │ │ │ ├── QuoteApiClient.kt │ │ │ │ └── QuoteService.kt │ │ │ ├── di │ │ │ ├── NetworkModule.kt │ │ │ └── RoomModule.kt │ │ │ ├── domain │ │ │ ├── GetQuotesUseCase.kt │ │ │ ├── GetRandomQuoteUseCase.kt │ │ │ └── model │ │ │ │ └── Quote.kt │ │ │ └── ui │ │ │ ├── view │ │ │ └── MainActivity.kt │ │ │ └── viewmodel │ │ │ └── QuoteViewModel.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── cursokotlin │ └── mvvmexample │ ├── QuoteViewModelUnitTest.kt │ └── domain │ ├── GetQuotesUseCaseTest.kt │ └── GetRandomQuoteUseCaseTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── local.properties ├── settings.gradle └── thumbnailMVVM.jpeg /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: 4 | push: 5 | branches: [ "ci/cd", "master" ] 6 | pull_request: 7 | branches: [ "ci/cd", "master" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: set up JDK 11 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '11' 20 | distribution: 'temurin' 21 | cache: gradle 22 | 23 | - name: Setup Gradle 24 | uses: gradle/gradle-build-action@v2 25 | - name: Build app 26 | run: ./gradlew assemble -------------------------------------------------------------------------------- /.github/workflows/testing.yml: -------------------------------------------------------------------------------- 1 | name: Android Testing CI 2 | on: [push] 3 | 4 | jobs: 5 | test: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v3 9 | - name: set up JDK 11 10 | uses: actions/setup-java@v3 11 | with: 12 | java-version: '11' 13 | distribution: 'temurin' 14 | cache: gradle 15 | 16 | - name: Unit Test 17 | run: ./gradlew testDebugUnitTest 18 | 19 | - name: Android Test Report 20 | uses: asadmansr/android-test-report-action@v1.2.0 21 | if: ${{ always() }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/.name 2 | /.gradle/buildOutputCleanup/buildOutputCleanup.lock 3 | /.gradle/buildOutputCleanup/cache.properties 4 | /.gradle/checksums/checksums.lock 5 | /.idea/compiler.xml 6 | /.gradle/6.8/executionHistory/executionHistory.bin 7 | /.gradle/6.8/executionHistory/executionHistory.lock 8 | /.gradle/6.8/fileHashes/fileHashes.bin 9 | /.gradle/6.8/fileHashes/fileHashes.lock 10 | /.gradle/6.8/gc.properties 11 | /.gradle/configuration-cache/gc.properties 12 | /.gradle/vcs-1/gc.properties 13 | /.idea/gradle.xml 14 | /gradlew.bat 15 | /.idea/jarRepositories.xml 16 | /.gradle/6.8/fileChanges/last-build.bin 17 | /.idea/misc.xml 18 | /.idea/modules/app/MVVM_Example.app.iml 19 | /.gradle/buildOutputCleanup/outputFiles.bin 20 | /.gradle/checksums/sha1-checksums.bin 21 | /.idea/vcs.xml 22 | /.idea/workspace.xml 23 | -------------------------------------------------------------------------------- /.gradle/7.4/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/checksums/checksums.lock -------------------------------------------------------------------------------- /.gradle/7.4/dependencies-accessors/dependencies-accessors.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock -------------------------------------------------------------------------------- /.gradle/7.4/dependencies-accessors/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/dependencies-accessors/gc.properties -------------------------------------------------------------------------------- /.gradle/7.4/executionHistory/executionHistory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/executionHistory/executionHistory.bin -------------------------------------------------------------------------------- /.gradle/7.4/executionHistory/executionHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/executionHistory/executionHistory.lock -------------------------------------------------------------------------------- /.gradle/7.4/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gradle/7.4/fileHashes/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/fileHashes/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/7.4/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /.gradle/7.4/fileHashes/resourceHashesCache.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/fileHashes/resourceHashesCache.bin -------------------------------------------------------------------------------- /.gradle/7.4/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/7.4/gc.properties -------------------------------------------------------------------------------- /.gradle/file-system.probe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/.gradle/file-system.probe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleAndroidMVVM - [CursoKotlin.com](https://cursokotlin.com) 2 | 3 |

4 | Android MVVM 5 |

6 | 7 | En este proyecto encontrarás un proyecto MVVM para Android en Kotlin que podrás seguir con los capítulos de CursoKollin.com 8 | Cada capítulo tendrá una rama con los conocimientos explicados y en **Master** tendrás la última versión. 9 | 10 | - [MVVM básico](https://cursokotlin.com/mvvm-en-android-con-kotlin-livedata-y-view-binding-android-architecture-components) - Primera versión de MVVM, lo encontrarás en la rama [**simpleMVVM**](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/simpleMVVM) 11 | 12 | - [Clean Architecture + Retrofit y corrutinas](https://cursokotlin.com/mvvm-en-android-con-kotlin-implementando-retrofit-corrutinas-y-clean-architecture/) - Segunda versión de MVVM, donde hemos añadido peticiones en red consumiendo un API con Retrofit 2 y corrutinas. También hemos añadido clean architecture. [**CleanRetrofit**](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/CleanRetrofit) 13 | 14 | - [Dagger Hilt - Inyección de dependencias](https://cursokotlin.com/dagger-hilt-inyeccion-de-dependencias-mvvm/) - En esta tercera iteración se ha añadido inyección de dependencias en todo el proyecto con Dagger Hilt [**DaggerHilt**](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/DaggerHilt) 15 | 16 | - [Persistencia de datos con ROOM](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/Room) - En esta cuarta parte vamos a implementar persistencia de datos con el OMR de Google Room. 17 | 18 | - [Testing en Android con MVVM (Unit test)](https://cursokotlin.com/testing-en-android---test-unitarios/) - Quinta entrega dónde implementaremos testing unitario desde cero. Puedes encontrar la rama específica aquí [**UnitTesting**](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/UnitTests) 19 | 20 | - [Integración continua básica](https://youtu.be/Zfaev5IOBmI) - Empezamos a preparar la integración continua del proyecto con Github Actions. La rama correspondiente es [**CI/CD**](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/ci/cd) 21 | 22 | - [Testing en CI](https://youtu.be/JYeYvEUq8Yw) - Corre los tests directamente en tu workflow y crea reglas personalizadas para las Pull Request, tienes todo el código en la rama [**CiTesting**](https://github.com/ArisGuimera/SimpleAndroidMVVM/tree/ciTesting) 23 | 24 | Recuerda que también puedes ver los capítulos en vídeo [en mi canal de Youtube](https://youtube.com/c/aristidevs) 25 | 26 | --- 27 | 28 | ## COLABORA. 29 | 30 | Este proyecto es totalmente GRATUITO por lo que puedes aportar tu grano de arena de múltiples formas. 31 | 32 | - Dale a FAV al proyecto (Star) 33 | - Sígueme en mis [redes sociales](https://aristi.dev) 34 | - Nomíname a [GITHUB STAR](https://stars.github.com/nominate/) 35 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | id 'dagger.hilt.android.plugin' 6 | } 7 | 8 | android { 9 | compileSdkVersion 31 10 | buildToolsVersion "30.0.3" 11 | 12 | defaultConfig { 13 | applicationId "com.cursokotlin.mvvmexample" 14 | minSdkVersion 21 15 | targetSdkVersion 31 16 | versionCode 1 17 | versionName "1.0" 18 | 19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | 33 | kotlinOptions { 34 | jvmTarget = '1.8' 35 | } 36 | 37 | buildFeatures{ 38 | viewBinding = true 39 | } 40 | } 41 | 42 | dependencies { 43 | 44 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 45 | implementation 'androidx.core:core-ktx:1.7.0' 46 | implementation 'androidx.appcompat:appcompat:1.4.1' 47 | implementation 'com.google.android.material:material:1.3.0' 48 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 49 | 50 | // Fragment 51 | implementation "androidx.fragment:fragment-ktx:1.3.2" 52 | // Activity 53 | implementation "androidx.activity:activity-ktx:1.2.2" 54 | // ViewModel 55 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" 56 | // LiveData 57 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1" 58 | // Retrofit 59 | implementation "com.squareup.retrofit2:retrofit:2.9.0" 60 | implementation "com.squareup.retrofit2:converter-gson:2.9.0" 61 | //Corrutinas 62 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0' 63 | //dagger hilt 64 | implementation "com.google.dagger:hilt-android:$hilt_version" 65 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 66 | //Room 67 | implementation "androidx.room:room-ktx:2.4.0" 68 | kapt "androidx.room:room-compiler:2.4.0" 69 | 70 | testImplementation 'junit:junit:4.+' 71 | testImplementation "io.mockk:mockk:1.12.2" 72 | testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0" 73 | testImplementation "androidx.arch.core:core-testing:2.1.0" 74 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 75 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 76 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/cursokotlin/mvvmexample/QuoteViewModelInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class QuoteViewModelInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.cursokotlin.mvvmexample", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/MvvmExampleApp.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class MvvmExampleApp:Application() -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/core/RetrofitHelper.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.core 2 | 3 | import retrofit2.Retrofit 4 | import retrofit2.converter.gson.GsonConverterFactory 5 | 6 | object RetrofitHelper { 7 | fun getRetrofit(): Retrofit { 8 | return Retrofit.Builder() 9 | .baseUrl("https://drawsomething-59328-default-rtdb.europe-west1.firebasedatabase.app/") 10 | .addConverterFactory(GsonConverterFactory.create()) 11 | .build() 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/QuoteRepository.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data 2 | 3 | import com.cursokotlin.mvvmexample.data.database.dao.QuoteDao 4 | import com.cursokotlin.mvvmexample.data.database.entities.QuoteEntity 5 | import com.cursokotlin.mvvmexample.data.model.QuoteModel 6 | import com.cursokotlin.mvvmexample.data.network.QuoteService 7 | import com.cursokotlin.mvvmexample.domain.model.Quote 8 | import com.cursokotlin.mvvmexample.domain.model.toDomain 9 | import javax.inject.Inject 10 | 11 | class QuoteRepository @Inject constructor( 12 | private val api: QuoteService, 13 | private val quoteDao: QuoteDao 14 | ) { 15 | 16 | suspend fun getAllQuotesFromApi(): List { 17 | val response: List = api.getQuotes() 18 | return response.map { it.toDomain() } 19 | } 20 | 21 | suspend fun getAllQuotesFromDatabase():List{ 22 | val response: List = quoteDao.getAllQuotes() 23 | return response.map { it.toDomain() } 24 | } 25 | 26 | suspend fun insertQuotes(quotes:List){ 27 | quoteDao.insertAll(quotes) 28 | } 29 | 30 | suspend fun clearQuotes(){ 31 | quoteDao.deleteAllQuotes() 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/database/QuoteDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data.database 2 | 3 | import androidx.room.Database 4 | import androidx.room.RoomDatabase 5 | import com.cursokotlin.mvvmexample.data.database.dao.QuoteDao 6 | import com.cursokotlin.mvvmexample.data.database.entities.QuoteEntity 7 | 8 | @Database(entities = [QuoteEntity::class], version = 1) 9 | abstract class QuoteDatabase: RoomDatabase() { 10 | 11 | abstract fun getQuoteDao():QuoteDao 12 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/database/dao/QuoteDao.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data.database.dao 2 | 3 | import androidx.room.Dao 4 | import androidx.room.Insert 5 | import androidx.room.OnConflictStrategy 6 | import androidx.room.Query 7 | import com.cursokotlin.mvvmexample.data.database.entities.QuoteEntity 8 | 9 | @Dao 10 | interface QuoteDao { 11 | 12 | @Query("SELECT * FROM quote_table ORDER BY author DESC") 13 | suspend fun getAllQuotes():List 14 | 15 | @Insert(onConflict = OnConflictStrategy.REPLACE) 16 | suspend fun insertAll(quotes:List) 17 | 18 | @Query("DELETE FROM quote_table") 19 | suspend fun deleteAllQuotes() 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/database/entities/QuoteEntity.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data.database.entities 2 | 3 | import androidx.room.ColumnInfo 4 | import androidx.room.Entity 5 | import androidx.room.PrimaryKey 6 | import com.cursokotlin.mvvmexample.domain.model.Quote 7 | 8 | @Entity(tableName = "quote_table") 9 | data class QuoteEntity( 10 | @PrimaryKey(autoGenerate = true) 11 | @ColumnInfo(name = "id") val id: Int = 0, 12 | @ColumnInfo(name = "quote") val quote: String, 13 | @ColumnInfo(name = "author") val author: String 14 | ) 15 | 16 | 17 | fun Quote.toDatabase() = QuoteEntity(quote = quote, author = author) -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/model/QuoteModel.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data.model 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | data class QuoteModel( 6 | @SerializedName("quote") val quote: String, 7 | @SerializedName("author") val author: String 8 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/network/QuoteApiClient.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data.network 2 | 3 | import com.cursokotlin.mvvmexample.data.model.QuoteModel 4 | import retrofit2.Response 5 | import retrofit2.http.GET 6 | 7 | interface QuoteApiClient { 8 | @GET("/.json") 9 | suspend fun getAllQuotes(): Response> 10 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/data/network/QuoteService.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.data.network 2 | 3 | import com.cursokotlin.mvvmexample.core.RetrofitHelper 4 | import com.cursokotlin.mvvmexample.data.model.QuoteModel 5 | import kotlinx.coroutines.Dispatchers 6 | import kotlinx.coroutines.withContext 7 | import javax.inject.Inject 8 | 9 | class QuoteService @Inject constructor(private val api:QuoteApiClient) { 10 | 11 | suspend fun getQuotes(): List { 12 | return withContext(Dispatchers.IO) { 13 | val response = api.getAllQuotes() 14 | response.body() ?: emptyList() 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/di/NetworkModule.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.di 2 | 3 | import com.cursokotlin.mvvmexample.data.network.QuoteApiClient 4 | import dagger.Module 5 | import dagger.Provides 6 | import dagger.hilt.InstallIn 7 | import dagger.hilt.components.SingletonComponent 8 | import retrofit2.Retrofit 9 | import retrofit2.converter.gson.GsonConverterFactory 10 | import javax.inject.Singleton 11 | 12 | @Module 13 | @InstallIn(SingletonComponent::class) 14 | object NetworkModule { 15 | 16 | @Singleton 17 | @Provides 18 | fun provideRetrofit():Retrofit{ 19 | return Retrofit.Builder() 20 | .baseUrl("https://drawsomething-59328-default-rtdb.europe-west1.firebasedatabase.app/") 21 | .addConverterFactory(GsonConverterFactory.create()) 22 | .build() 23 | } 24 | 25 | @Singleton 26 | @Provides 27 | fun provideQuoteApiClient(retrofit: Retrofit):QuoteApiClient{ 28 | return retrofit.create(QuoteApiClient::class.java) 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/di/RoomModule.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.di 2 | 3 | import android.content.Context 4 | import androidx.room.Room 5 | import com.cursokotlin.mvvmexample.data.database.QuoteDatabase 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.android.qualifiers.ApplicationContext 10 | import dagger.hilt.components.SingletonComponent 11 | import javax.inject.Singleton 12 | 13 | @Module 14 | @InstallIn(SingletonComponent::class) 15 | object RoomModule { 16 | 17 | private const val QUOTE_DATABASE_NAME = "quote_database" 18 | 19 | @Singleton 20 | @Provides 21 | fun provideRoom(@ApplicationContext context: Context) = 22 | Room.databaseBuilder(context, QuoteDatabase::class.java, QUOTE_DATABASE_NAME).build() 23 | 24 | @Singleton 25 | @Provides 26 | fun provideQuoteDao(db: QuoteDatabase) = db.getQuoteDao() 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/domain/GetQuotesUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.domain 2 | 3 | import com.cursokotlin.mvvmexample.data.QuoteRepository 4 | import com.cursokotlin.mvvmexample.data.database.entities.toDatabase 5 | import com.cursokotlin.mvvmexample.domain.model.Quote 6 | import javax.inject.Inject 7 | 8 | class GetQuotesUseCase @Inject constructor(private val repository: QuoteRepository) { 9 | suspend operator fun invoke():List{ 10 | val quotes = repository.getAllQuotesFromApi() 11 | 12 | return if(quotes.isNotEmpty()){ 13 | repository.clearQuotes() 14 | repository.insertQuotes(quotes.map { it.toDatabase() }) 15 | quotes 16 | }else{ 17 | repository.getAllQuotesFromDatabase() 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/domain/GetRandomQuoteUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.domain 2 | 3 | import com.cursokotlin.mvvmexample.data.QuoteRepository 4 | import com.cursokotlin.mvvmexample.data.model.QuoteModel 5 | import com.cursokotlin.mvvmexample.domain.model.Quote 6 | import javax.inject.Inject 7 | 8 | class GetRandomQuoteUseCase @Inject constructor(private val repository: QuoteRepository) { 9 | 10 | suspend operator fun invoke(): Quote? { 11 | val quotes = repository.getAllQuotesFromDatabase() 12 | if (!quotes.isNullOrEmpty()) { 13 | val randomNumber = (quotes.indices).random() 14 | return quotes[randomNumber] 15 | } 16 | return null 17 | } 18 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/domain/model/Quote.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.domain.model 2 | 3 | import com.cursokotlin.mvvmexample.data.database.entities.QuoteEntity 4 | import com.cursokotlin.mvvmexample.data.model.QuoteModel 5 | 6 | data class Quote (val quote:String, val author:String) 7 | 8 | fun QuoteModel.toDomain() = Quote(quote, author) 9 | fun QuoteEntity.toDomain() = Quote(quote, author) -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/ui/view/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.ui.view 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import androidx.activity.viewModels 6 | import androidx.core.view.isVisible 7 | import androidx.lifecycle.Observer 8 | import com.cursokotlin.mvvmexample.databinding.ActivityMainBinding 9 | import com.cursokotlin.mvvmexample.ui.viewmodel.QuoteViewModel 10 | import dagger.hilt.android.AndroidEntryPoint 11 | import javax.inject.Inject 12 | 13 | @AndroidEntryPoint 14 | class MainActivity : AppCompatActivity() { 15 | 16 | private lateinit var binding: ActivityMainBinding 17 | 18 | private val quoteViewModel: QuoteViewModel by viewModels() 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | binding = ActivityMainBinding.inflate(layoutInflater) 23 | setContentView(binding.root) 24 | 25 | quoteViewModel.onCreate() 26 | 27 | quoteViewModel.quoteModel.observe(this, Observer { 28 | binding.tvQuote.text = it.quote 29 | binding.tvAuthor.text = it.author 30 | }) 31 | quoteViewModel.isLoading.observe(this, Observer { 32 | binding.loading.isVisible = it 33 | }) 34 | 35 | binding.viewContainer.setOnClickListener { quoteViewModel.randomQuote() } 36 | 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/mvvmexample/ui/viewmodel/QuoteViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.ui.viewmodel 2 | 3 | import androidx.lifecycle.MutableLiveData 4 | import androidx.lifecycle.ViewModel 5 | import androidx.lifecycle.viewModelScope 6 | import com.cursokotlin.mvvmexample.domain.GetQuotesUseCase 7 | import com.cursokotlin.mvvmexample.domain.GetRandomQuoteUseCase 8 | import com.cursokotlin.mvvmexample.domain.model.Quote 9 | import dagger.hilt.android.lifecycle.HiltViewModel 10 | import kotlinx.coroutines.launch 11 | import javax.inject.Inject 12 | 13 | @HiltViewModel 14 | class QuoteViewModel @Inject constructor( 15 | private val getQuotesUseCase: GetQuotesUseCase, 16 | private val getRandomQuoteUseCase: GetRandomQuoteUseCase 17 | ) : ViewModel() { 18 | 19 | val quoteModel = MutableLiveData() 20 | val isLoading = MutableLiveData() 21 | 22 | fun onCreate() { 23 | viewModelScope.launch { 24 | isLoading.postValue(true) 25 | val result = getQuotesUseCase() 26 | 27 | if (!result.isNullOrEmpty()) { 28 | quoteModel.postValue(result[0]) 29 | isLoading.postValue(false) 30 | } 31 | } 32 | } 33 | 34 | fun randomQuote() { 35 | viewModelScope.launch { 36 | isLoading.postValue(true) 37 | val quote = getRandomQuoteUseCase() 38 | quote?.let { 39 | quoteModel.value = it 40 | } 41 | isLoading.postValue(false) 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 24 | 25 | 37 | 38 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | 10 | #FFFFFFFF 11 | #4F1497 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MVVM Example 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/cursokotlin/mvvmexample/QuoteViewModelUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample 2 | 3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule 4 | import com.cursokotlin.mvvmexample.domain.GetQuotesUseCase 5 | import com.cursokotlin.mvvmexample.domain.GetRandomQuoteUseCase 6 | import com.cursokotlin.mvvmexample.domain.model.Quote 7 | import com.cursokotlin.mvvmexample.ui.viewmodel.QuoteViewModel 8 | import io.mockk.MockKAnnotations 9 | import io.mockk.coEvery 10 | import io.mockk.impl.annotations.RelaxedMockK 11 | import kotlinx.coroutines.Dispatchers 12 | import kotlinx.coroutines.ExperimentalCoroutinesApi 13 | import kotlinx.coroutines.test.* 14 | import org.junit.After 15 | import org.junit.Before 16 | import org.junit.Rule 17 | import org.junit.Test 18 | 19 | @ExperimentalCoroutinesApi 20 | class QuoteViewModelUnitTest { 21 | 22 | @RelaxedMockK 23 | private lateinit var getQuotesUseCase: GetQuotesUseCase 24 | 25 | @RelaxedMockK 26 | private lateinit var getRandomQuoteUseCase: GetRandomQuoteUseCase 27 | 28 | private lateinit var quoteViewModel: QuoteViewModel 29 | 30 | @get:Rule 31 | var rule: InstantTaskExecutorRule = InstantTaskExecutorRule() 32 | 33 | @Before 34 | fun onBefore() { 35 | MockKAnnotations.init(this) 36 | quoteViewModel = QuoteViewModel(getQuotesUseCase, getRandomQuoteUseCase) 37 | Dispatchers.setMain(Dispatchers.Unconfined) 38 | } 39 | 40 | @After 41 | fun onAfter() { 42 | Dispatchers.resetMain() 43 | } 44 | 45 | @Test 46 | fun `when randomQuoteUseCase return a quote set on the livedata`() = runTest { 47 | //Given 48 | val quote = Quote("Holi", "Aris") 49 | coEvery { getRandomQuoteUseCase() } returns quote 50 | 51 | //When 52 | quoteViewModel.randomQuote() 53 | 54 | //Then 55 | assert(quoteViewModel.quoteModel.value == quote) 56 | } 57 | 58 | @Test 59 | fun `if randomQuoteUseCase return null keep the last value`() = runTest{ 60 | //Given 61 | val quote = Quote("Aris", "Aris") 62 | quoteViewModel.quoteModel.value = quote 63 | coEvery { getRandomQuoteUseCase() } returns null 64 | 65 | //When 66 | quoteViewModel.randomQuote() 67 | 68 | //Then 69 | assert(quoteViewModel.quoteModel.value == quote) 70 | } 71 | 72 | @Test 73 | fun `when viewmodel is created at the first time, get all quotes and set the first value`() = runTest{ 74 | //Given 75 | val quote = listOf(Quote("Holi", "Aris"), Quote("Dame un like", "Otro Aris ")) 76 | coEvery { getQuotesUseCase() } returns quote 77 | 78 | //When 79 | quoteViewModel.onCreate() 80 | 81 | //Then 82 | assert(quoteViewModel.quoteModel.value == quote.first()) 83 | } 84 | } -------------------------------------------------------------------------------- /app/src/test/java/com/cursokotlin/mvvmexample/domain/GetQuotesUseCaseTest.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.domain 2 | 3 | import com.cursokotlin.mvvmexample.data.QuoteRepository 4 | import com.cursokotlin.mvvmexample.domain.model.Quote 5 | import io.mockk.MockKAnnotations 6 | import io.mockk.coEvery 7 | import io.mockk.coVerify 8 | import io.mockk.impl.annotations.RelaxedMockK 9 | import kotlinx.coroutines.runBlocking 10 | import org.junit.Before 11 | import org.junit.Test 12 | 13 | class GetQuotesUseCaseTest { 14 | 15 | @RelaxedMockK 16 | private lateinit var quoteRepository: QuoteRepository 17 | 18 | lateinit var getQuotesUseCase: GetQuotesUseCase 19 | 20 | @Before 21 | fun onBefore() { 22 | MockKAnnotations.init(this) 23 | getQuotesUseCase = GetQuotesUseCase(quoteRepository) 24 | } 25 | 26 | @Test 27 | fun `when the api doesnt return anything then get values from database`() = runBlocking { 28 | //Given 29 | coEvery { quoteRepository.getAllQuotesFromApi() } returns emptyList() 30 | 31 | //When 32 | getQuotesUseCase() 33 | 34 | //Then 35 | coVerify(exactly = 1) { quoteRepository.getAllQuotesFromDatabase() } 36 | } 37 | 38 | @Test 39 | fun `when the api return something then get values from api`() = runBlocking { 40 | //Given 41 | val myList = listOf(Quote("Déjame un comentario", "AristiDevs")) 42 | coEvery { quoteRepository.getAllQuotesFromApi() } returns myList 43 | 44 | //When 45 | val response = getQuotesUseCase() 46 | 47 | //Then 48 | coVerify(exactly = 1) { quoteRepository.clearQuotes() } 49 | coVerify(exactly = 1) { quoteRepository.insertQuotes(any()) } 50 | coVerify(exactly = 0) { quoteRepository.getAllQuotesFromDatabase() } 51 | assert(response == myList) 52 | } 53 | } -------------------------------------------------------------------------------- /app/src/test/java/com/cursokotlin/mvvmexample/domain/GetRandomQuoteUseCaseTest.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.mvvmexample.domain 2 | 3 | import com.cursokotlin.mvvmexample.data.QuoteRepository 4 | import com.cursokotlin.mvvmexample.domain.model.Quote 5 | import io.mockk.MockKAnnotations 6 | import io.mockk.coEvery 7 | import io.mockk.impl.annotations.RelaxedMockK 8 | import kotlinx.coroutines.runBlocking 9 | import org.junit.Before 10 | import org.junit.Test 11 | 12 | 13 | class GetRandomQuoteUseCaseTest { 14 | @RelaxedMockK 15 | private lateinit var quoteRepository: QuoteRepository 16 | 17 | lateinit var getRandomQuoteUseCase: GetRandomQuoteUseCase 18 | 19 | @Before 20 | fun onBefore() { 21 | MockKAnnotations.init(this) 22 | getRandomQuoteUseCase = GetRandomQuoteUseCase(quoteRepository) 23 | } 24 | 25 | @Test 26 | fun `when database is empty then return null`() = runBlocking { 27 | coEvery { quoteRepository.getAllQuotesFromDatabase() } returns emptyList() 28 | 29 | val response = getRandomQuoteUseCase() 30 | 31 | assert(response == null) 32 | } 33 | 34 | @Test 35 | fun `when database is not empty then return quote`() = runBlocking { 36 | val quoteList = listOf(Quote("Holi", "AristiDevs")) 37 | 38 | coEvery { quoteRepository.getAllQuotesFromDatabase() } returns quoteList 39 | 40 | val response = getRandomQuoteUseCase() 41 | 42 | assert(response == quoteList.first()) 43 | } 44 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext.kotlin_version = "1.6.10" 4 | ext.hilt_version = '2.35' 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath "com.android.tools.build:gradle:4.1.3" 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | mavenCentral() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Thu Feb 17 16:19:51 WET 2022 8 | sdk.dir=/Users/aris/Library/Android/sdk 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "MVVM Example" -------------------------------------------------------------------------------- /thumbnailMVVM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArisGuimera/SimpleAndroidMVVM/14d06399b5497a0cc2ca82e630e26c8dc645c19c/thumbnailMVVM.jpeg --------------------------------------------------------------------------------