├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── drawable │ │ │ │ ├── unicorn.png │ │ │ │ └── ic_launcher_background.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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── anncode │ │ │ │ └── jetpackcomposecleanarchitecture │ │ │ │ ├── ComposeCleanArchitectureApp.kt │ │ │ │ ├── presentation │ │ │ │ ├── ui │ │ │ │ │ ├── Color.kt │ │ │ │ │ ├── Shape.kt │ │ │ │ │ ├── composables │ │ │ │ │ │ ├── CatFactButton.kt │ │ │ │ │ │ ├── CatFactText.kt │ │ │ │ │ │ └── CatFactCard.kt │ │ │ │ │ ├── Type.kt │ │ │ │ │ ├── screens │ │ │ │ │ │ └── CatFactScreen.kt │ │ │ │ │ └── Theme.kt │ │ │ │ └── main │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ └── MainViewModel.kt │ │ │ │ ├── domain │ │ │ │ └── catfacts │ │ │ │ │ ├── model │ │ │ │ │ ├── Fact.kt │ │ │ │ │ └── CatFactStates.kt │ │ │ │ │ ├── usecases │ │ │ │ │ ├── GetCatRandomFact.kt │ │ │ │ │ └── GetCatRandomFactImpl.kt │ │ │ │ │ └── repository │ │ │ │ │ └── CatFactRepository.kt │ │ │ │ ├── data │ │ │ │ └── network │ │ │ │ │ ├── CatFactsService.kt │ │ │ │ │ └── repository │ │ │ │ │ └── CatFactRepositoryImpl.kt │ │ │ │ └── di │ │ │ │ ├── ViewModelModule.kt │ │ │ │ ├── UseCaseModule.kt │ │ │ │ ├── RepositoryModule.kt │ │ │ │ └── NetworkModule.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── anncode │ │ │ └── jetpackcomposecleanarchitecture │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── anncode │ │ └── jetpackcomposecleanarchitecture │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── .idea ├── .gitignore ├── compiler.xml ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── misc.xml ├── gradle.xml └── jarRepositories.xml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "JetpackComposeCleanArchitecture" 2 | include ':app' 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | JetpackComposeCleanArchitecture 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/unicorn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/drawable/unicorn.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anncode1/JetpackComposeCleanArchitecture/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 20 22:27:01 CDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-rc-4-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/anncode/jetpackcomposecleanarchitecture/ComposeCleanArchitectureApp.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class ComposeCleanArchitectureApp: Application() 8 | -------------------------------------------------------------------------------- /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/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/Color.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui 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) 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/domain/catfacts/model/Fact.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | /** 6 | * Created by anahi.salgado on 28/07/2020 7 | */ 8 | data class Fact( 9 | @SerializedName("_id") val id: String, 10 | @SerializedName("text") val text: String 11 | ) 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/domain/catfacts/model/CatFactStates.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model 2 | 3 | /** 4 | * Created by anahi.salgado on 28/07/2020 5 | */ 6 | sealed class CatFactStates { 7 | object Loading: CatFactStates() 8 | class CatFactData(val fact: Fact): CatFactStates() 9 | class Error(val error: Throwable): CatFactStates() 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/domain/catfacts/usecases/GetCatRandomFact.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.usecases 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model.CatFactStates 4 | 5 | /** 6 | * Created by anahi.salgado on 28/07/2020 7 | */ 8 | interface GetCatRandomFact { 9 | suspend operator fun invoke(): CatFactStates 10 | } 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/anncode/jetpackcomposecleanarchitecture/domain/catfacts/repository/CatFactRepository.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.repository 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model.CatFactStates 4 | 5 | /** 6 | * Created by anahi.salgado on 28/07/2020 7 | */ 8 | interface CatFactRepository { 9 | suspend fun getCatRandomFact(): CatFactStates 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/Shape.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui 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 | ) 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/composables/CatFactButton.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui.composables 2 | 3 | import androidx.compose.foundation.Text 4 | import androidx.compose.material.Button 5 | import androidx.compose.runtime.Composable 6 | 7 | @Composable 8 | fun CatFactButton(onClick: () -> Unit){ 9 | Button(onClick = onClick) { 10 | Text(text = "Get a Cat Fact!") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/data/network/CatFactsService.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.data.network 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model.Fact 4 | import retrofit2.Response 5 | import retrofit2.http.GET 6 | 7 | /** 8 | * Created by anahi.salgado on 28/07/2020 9 | */ 10 | interface CatFactsService { 11 | @GET("/facts/random") 12 | suspend fun getCatRandomFact(): Response 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/composables/CatFactText.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui.composables 2 | 3 | import androidx.compose.foundation.Text 4 | import androidx.compose.runtime.Composable 5 | import com.anncode.jetpackcomposecleanarchitecture.presentation.ui.typography 6 | 7 | @Composable 8 | fun CatFactText(text: String) { 9 | Text( 10 | text = text, 11 | style = typography.h6 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /app/src/test/java/com/anncode/jetpackcomposecleanarchitecture/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/domain/catfacts/usecases/GetCatRandomFactImpl.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.usecases 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model.CatFactStates 4 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.repository.CatFactRepository 5 | 6 | /** 7 | * Created by anahi.salgado on 28/07/2020 8 | */ 9 | class GetCatRandomFactImpl( 10 | private val catFactRepository: CatFactRepository 11 | ): GetCatRandomFact { 12 | override suspend fun invoke(): CatFactStates = catFactRepository.getCatRandomFact() 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/di/ViewModelModule.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.di 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.usecases.GetCatRandomFact 4 | import com.anncode.jetpackcomposecleanarchitecture.presentation.main.MainViewModel 5 | import dagger.Module 6 | import dagger.Provides 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.android.components.ActivityRetainedComponent 9 | 10 | /** 11 | * Created by anahi.salgado on 17-Oct-20. 12 | */ 13 | @Module 14 | @InstallIn(ActivityRetainedComponent::class) 15 | class ViewModelModule { 16 | 17 | @Provides 18 | fun provideMainViewModel( 19 | getCatRandomFact: GetCatRandomFact 20 | ): MainViewModel = MainViewModel(getCatRandomFact) 21 | } 22 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /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/anncode/jetpackcomposecleanarchitecture/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture 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 ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.jetpackcomposecleanarchitecture", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.main 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.compose.ui.platform.setContent 6 | import com.anncode.jetpackcomposecleanarchitecture.presentation.ui.screens.CatFactScreen 7 | import dagger.hilt.android.AndroidEntryPoint 8 | import javax.inject.Inject 9 | 10 | @AndroidEntryPoint 11 | class MainActivity : AppCompatActivity() { 12 | 13 | @Inject lateinit var mainViewModel: MainViewModel 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContent { 17 | CatFactScreen(catFact = mainViewModel.catFact) { 18 | mainViewModel.getCatFact() 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/di/UseCaseModule.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.di 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.repository.CatFactRepository 4 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.usecases.GetCatRandomFact 5 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.usecases.GetCatRandomFactImpl 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.android.components.ActivityRetainedComponent 10 | 11 | /** 12 | * Created by anahi.salgado on 17-Oct-20. 13 | */ 14 | @Module 15 | @InstallIn(ActivityRetainedComponent::class) 16 | class UseCaseModule { 17 | 18 | @Provides 19 | fun provideGetCatRandomFact( 20 | catFactRepository: CatFactRepository 21 | ): GetCatRandomFact = GetCatRandomFactImpl(catFactRepository) 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/di/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.di 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.data.network.CatFactsService 4 | import com.anncode.jetpackcomposecleanarchitecture.data.network.repository.CatFactRepositoryImpl 5 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.repository.CatFactRepository 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.android.components.ApplicationComponent 10 | import javax.inject.Singleton 11 | 12 | /** 13 | * Created by anahi.salgado on 17-Oct-20. 14 | */ 15 | @Module 16 | @InstallIn(ApplicationComponent::class) 17 | class RepositoryModule { 18 | 19 | @Singleton 20 | @Provides 21 | fun provideCatFactRepository( 22 | catFactsService: CatFactsService 23 | ): CatFactRepository = CatFactRepositoryImpl(catFactsService) 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/Type.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui 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 | ) 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/di/NetworkModule.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.di 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.data.network.CatFactsService 4 | import dagger.Module 5 | import dagger.Provides 6 | import dagger.hilt.InstallIn 7 | import dagger.hilt.android.components.ApplicationComponent 8 | import retrofit2.Retrofit 9 | import retrofit2.converter.gson.GsonConverterFactory 10 | import javax.inject.Singleton 11 | 12 | /** 13 | * Created by anahi.salgado on 17-Oct-20. 14 | */ 15 | @Module 16 | @InstallIn(ApplicationComponent::class) 17 | class NetworkModule { 18 | 19 | @Singleton 20 | @Provides 21 | fun provideCatFactsApi(): CatFactsService { 22 | return Retrofit.Builder() 23 | .baseUrl("https://cat-fact.herokuapp.com") 24 | .addConverterFactory(GsonConverterFactory.create()) 25 | .build() 26 | .create(CatFactsService::class.java) 27 | } 28 | 29 | companion object { 30 | const val BASE_URL = "https://cat-fact.herokuapp.com" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/composables/CatFactCard.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui.composables 2 | 3 | import androidx.compose.foundation.layout.* 4 | import androidx.compose.foundation.shape.RoundedCornerShape 5 | import androidx.compose.material.Surface 6 | import androidx.compose.runtime.Composable 7 | import androidx.compose.ui.Alignment 8 | import androidx.compose.ui.Modifier 9 | import androidx.compose.ui.unit.dp 10 | 11 | @Composable 12 | fun CatFactCard(text: String, onClick: () -> Unit) { 13 | Surface( 14 | shape = RoundedCornerShape(8.dp), 15 | elevation = 8.dp, 16 | modifier = Modifier.padding(8.dp) 17 | ) { 18 | Column( 19 | modifier = Modifier.padding(16.dp) + Modifier.fillMaxWidth(), 20 | horizontalAlignment = Alignment.CenterHorizontally 21 | ) { 22 | CatFactText(text = text) 23 | Spacer(modifier = Modifier.preferredHeight(16.dp)) 24 | CatFactButton(onClick = onClick) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/data/network/repository/CatFactRepositoryImpl.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.data.network.repository 2 | 3 | import com.anncode.jetpackcomposecleanarchitecture.data.network.CatFactsService 4 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model.CatFactStates 5 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.repository.CatFactRepository 6 | import java.io.IOException 7 | 8 | /** 9 | * Created by anahi.salgado on 28/07/2020 10 | */ 11 | class CatFactRepositoryImpl( 12 | private val catFactsService: CatFactsService 13 | ): CatFactRepository { 14 | override suspend fun getCatRandomFact(): CatFactStates { 15 | return try { 16 | val response = catFactsService.getCatRandomFact() 17 | val fact = response.body() 18 | return if (fact != null) CatFactStates.CatFactData(fact) else CatFactStates.Error(IOException("Data is null")) 19 | } catch (exception: Exception) { 20 | CatFactStates.Error(exception) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /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 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/anncode/jetpackcomposecleanarchitecture/presentation/ui/screens/CatFactScreen.kt: -------------------------------------------------------------------------------- 1 | package com.anncode.jetpackcomposecleanarchitecture.presentation.ui.screens 2 | 3 | import androidx.compose.runtime.Composable 4 | import androidx.compose.runtime.getValue 5 | import androidx.compose.runtime.livedata.observeAsState 6 | import androidx.lifecycle.LiveData 7 | import com.anncode.jetpackcomposecleanarchitecture.domain.catfacts.model.CatFactStates 8 | import com.anncode.jetpackcomposecleanarchitecture.presentation.ui.composables.CatFactCard 9 | import com.anncode.jetpackcomposecleanarchitecture.presentation.ui.composables.CatFactText 10 | 11 | 12 | @Composable 13 | fun CatFactScreen( 14 | catFact: LiveData, 15 | onClick: () -> Unit 16 | ) { 17 | val catFact: CatFactStates by catFact.observeAsState(initial = CatFactStates.Loading) 18 | 19 | when (catFact) { 20 | is CatFactStates.Loading -> CatFactCard(text = "Click to Get a Cat Fact!", onClick = onClick) 21 | is CatFactStates.CatFactData -> CatFactCard(text = (catFact as CatFactStates.CatFactData).fact.text, onClick = onClick) 22 | else -> CatFactText(text = "Nothing to show") 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 21 | 22 |