From cf304c46198a026f017f7007403d6ac2d9fab4bd Mon Sep 17 00:00:00 2001 From: myofficework000 Date: Wed, 8 May 2024 03:45:47 +0530 Subject: [PATCH] Added some changes in clean code impl --- .../clean_code/data/dto/DogEntityCleanCode.kt | 2 +- .../clean_code/data/mapper/DogMapperCleanCode.kt | 4 ++-- .../usecases/{GetDogUsecase.kt => GetDogUseCase.kt} | 2 +- .../clean_code/presentation/ui/DogApiMainPage.kt | 3 +-- .../presentation/viewmodel/DogViewModelCleanCode.kt | 8 +++----- .../android_architectures/mvi/view/RandomDogView.kt | 3 +-- .../example/jetpack_compose_all_in_one/ui/theme/Theme.kt | 6 ++++-- 7 files changed, 13 insertions(+), 15 deletions(-) rename app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/{GetDogUsecase.kt => GetDogUseCase.kt} (89%) diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/dto/DogEntityCleanCode.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/dto/DogEntityCleanCode.kt index 68084e9d..1589d68e 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/dto/DogEntityCleanCode.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/dto/DogEntityCleanCode.kt @@ -1,6 +1,6 @@ package com.example.jetpack_compose_all_in_one.android_architectures.clean_code.data.dto data class DogEntityCleanCode( - val message: String, + val dogUrl: String, val status: String ) diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/mapper/DogMapperCleanCode.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/mapper/DogMapperCleanCode.kt index ff273570..d1421d7a 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/mapper/DogMapperCleanCode.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/data/mapper/DogMapperCleanCode.kt @@ -5,12 +5,12 @@ import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.d object DogMapperCleanCode: Mapper { override fun mapFromEntity(type: DogEntityCleanCode) = DogResponseCleanCode( - message = type.message, + message = type.dogUrl, status = type.status ) override fun mapToEntity(type: DogResponseCleanCode) = DogEntityCleanCode( - message = type.message, + dogUrl = type.message, status = type.status ) } \ No newline at end of file diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/GetDogUsecase.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/GetDogUseCase.kt similarity index 89% rename from app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/GetDogUsecase.kt rename to app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/GetDogUseCase.kt index 134603c1..44d96eb4 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/GetDogUsecase.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/domain/usecases/GetDogUseCase.kt @@ -3,7 +3,7 @@ package com.example.jetpack_compose_all_in_one.android_architectures.clean_code. import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.domain.repositories.DogRepositoryCleanCode import javax.inject.Inject -class GetDogUsecase @Inject constructor( +class GetDogUseCase @Inject constructor( private val repo: DogRepositoryCleanCode ) { suspend operator fun invoke() = repo.getRandomDog() diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/ui/DogApiMainPage.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/ui/DogApiMainPage.kt index d55dab82..13179684 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/ui/DogApiMainPage.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/ui/DogApiMainPage.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -50,7 +49,7 @@ fun DogApiMainPage( } GlideImage( - model = it.message, + model = it.dogUrl, contentDescription = "woof", modifier = Modifier.size(400.dp) ) { it2 -> diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/viewmodel/DogViewModelCleanCode.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/viewmodel/DogViewModelCleanCode.kt index b1b6306c..d4fa4e70 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/viewmodel/DogViewModelCleanCode.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code/presentation/viewmodel/DogViewModelCleanCode.kt @@ -6,9 +6,7 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.data.dto.DogEntityCleanCode -import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.data.dto.DogResponseCleanCode -import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.domain.repositories.DogRepositoryCleanCode -import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.domain.usecases.GetDogUsecase +import com.example.jetpack_compose_all_in_one.android_architectures.clean_code.domain.usecases.GetDogUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -16,7 +14,7 @@ import javax.inject.Inject @HiltViewModel class DogViewModelCleanCode @Inject constructor( - private val getRandomDogUsecase: GetDogUsecase + private val getRandomDogUseCase: GetDogUseCase ): ViewModel() { init { getRandomDog() } @@ -25,7 +23,7 @@ class DogViewModelCleanCode @Inject constructor( fun getRandomDog() { viewModelScope.launch(Dispatchers.IO) { - dogResponse = getRandomDogUsecase() + dogResponse = getRandomDogUseCase() } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/mvi/view/RandomDogView.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/mvi/view/RandomDogView.kt index 3e4f580a..119eb9fb 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/mvi/view/RandomDogView.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/mvi/view/RandomDogView.kt @@ -22,8 +22,7 @@ import com.example.jetpack_compose_all_in_one.utils.showLongToast import com.example.jetpack_compose_all_in_one.R @Composable -fun RandomDogView( -) { +fun RandomDogView() { val viewModel: RandomDogViewModel = hiltViewModel() val state by viewModel.viewState.collectAsState() diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/theme/Theme.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/theme/Theme.kt index bd853da4..e923ca16 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/ui/theme/Theme.kt @@ -24,7 +24,8 @@ private val DarkColorScheme = darkColorScheme( secondary = PurpleGrey80, tertiary = Pink80, surface = LightBlue, - onSurface = Color.White + onSurface = Color.White, + onSecondary = Color.Gray ) private val LightColorScheme = lightColorScheme( @@ -33,7 +34,8 @@ private val LightColorScheme = lightColorScheme( secondary = PurpleGrey40, tertiary = Pink40, surface = Color(0xFF154C79), - onSurface = Color.White + onSurface = Color.White, + onSecondary = Color.White /* Other default colors to override background = Color(0xFFFFFBFE),