-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Louiixx-h/improvement/replace-xml-for-jet…
…pack-compose [IMPROVEMENT] - Replace xml for jetpack compose
- Loading branch information
Showing
57 changed files
with
765 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,91 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
id "com.android.application" | ||
id "kotlin-android" | ||
} | ||
|
||
android { | ||
compileSdk 33 | ||
|
||
viewBinding { | ||
enabled = true | ||
} | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
applicationId "com.luishenrique.cutecatsgallery" | ||
minSdk 21 | ||
targetSdkVersion 33 | ||
minSdkVersion 21 | ||
targetSdkVersion 34 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
debug { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
debuggable = true | ||
buildConfigField "String", "API_URL", "\"https://api.imgur.com/3/\"" | ||
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" | ||
} | ||
release { | ||
minifyEnabled true | ||
buildConfigField "String", "API_URL", "\"https://api.imgur.com/3/\"" | ||
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_17 | ||
targetCompatibility JavaVersion.VERSION_17 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '17' | ||
jvmTarget = "17" | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = compose_compiler_version | ||
} | ||
namespace "com.luishenrique.cutecatsgallery" | ||
|
||
buildFeatures { | ||
compose = true | ||
} | ||
namespace 'com.luishenrique.cutecatsgallery' | ||
} | ||
|
||
dependencies { | ||
|
||
api project(path: ':domain') | ||
// Retrofit | ||
implementation "com.squareup.retrofit2:retrofit:2.9.0" | ||
implementation "com.squareup.retrofit2:converter-gson:2.9.0" | ||
|
||
// Compose | ||
implementation platform("androidx.compose:compose-bom:2023.10.00") | ||
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" | ||
implementation "androidx.activity:activity-compose:1.8.0" | ||
implementation "androidx.compose.material3:material3:1.1.2" | ||
implementation "androidx.compose.material:material-android:1.5.3" | ||
implementation "io.coil-kt:coil-compose:2.4.0" | ||
implementation "androidx.navigation:navigation-compose:2.7.4" | ||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" | ||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" | ||
androidTestImplementation platform("androidx.compose:compose-bom:2023.10.00") | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" | ||
|
||
implementation 'com.google.accompanist:accompanist-swiperefresh:0.32.0' | ||
|
||
// progressbar cat | ||
implementation 'com.roger.catloadinglibrary:catloadinglibrary:1.0.9' | ||
implementation "com.roger.catloadinglibrary:catloadinglibrary:1.0.9" | ||
|
||
// glide | ||
implementation 'com.github.bumptech.glide:glide:4.12.0' | ||
implementation "com.github.bumptech.glide:glide:4.15.1" | ||
|
||
// coroutines | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-RC' | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3" | ||
|
||
// koin | ||
implementation 'org.koin:koin-android-viewmodel:2.1.6' | ||
implementation "io.insert-koin:koin-android:$koin_version" | ||
|
||
// viewmodel | ||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0' | ||
// viewModel | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2" | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.4.0' | ||
implementation 'com.google.android.material:material:1.4.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.2' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
implementation "androidx.core:core-ktx:1.12.0" | ||
implementation "com.google.android.material:material:1.10.0" | ||
implementation "androidx.appcompat:appcompat:1.6.1" | ||
testImplementation "junit:junit:4.13.2" | ||
androidTestImplementation "androidx.test.ext:junit:1.1.5" | ||
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/kotlin/com/luishenrique/cutecatsgallery/base/BaseViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.luishenrique.cutecatsgallery.base | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
abstract class BaseViewModel : ViewModel() { | ||
protected fun <T> request( | ||
block: suspend () -> T, | ||
onStartRequest: () -> Unit = {}, | ||
onSuccess: (T) -> Unit, | ||
onError: (ErrorContent) -> Unit, | ||
onFinally: () -> Unit = {} | ||
) : Job { | ||
return viewModelScope.launch { | ||
onStartRequest.invoke() | ||
runCatching { | ||
val response = withContext(Dispatchers.IO) { block.invoke() } | ||
onSuccess.invoke(response) | ||
}.onFailure { | ||
onError.invoke(ErrorContent(it.message.toString(), it)) | ||
} | ||
onFinally.invoke() | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/kotlin/com/luishenrique/cutecatsgallery/base/ErrorContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.luishenrique.cutecatsgallery.base | ||
|
||
data class ErrorContent( | ||
val message: String, | ||
val throwable: Throwable | ||
) |
25 changes: 25 additions & 0 deletions
25
app/src/main/kotlin/com/luishenrique/cutecatsgallery/commonComponents/Toolbar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.luishenrique.cutecatsgallery.commonComponents | ||
|
||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.material3.TopAppBarColors | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.runtime.Composable | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun Toolbar( | ||
colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors( | ||
containerColor = MaterialTheme.colorScheme.primaryContainer, | ||
titleContentColor = MaterialTheme.colorScheme.primary, | ||
), | ||
title: @Composable () -> Unit | ||
) { | ||
TopAppBar( | ||
colors = colors, | ||
title = { | ||
title.invoke() | ||
} | ||
) | ||
} |
9 changes: 0 additions & 9 deletions
9
app/src/main/kotlin/com/luishenrique/cutecatsgallery/di/AppModule.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
app/src/main/kotlin/com/luishenrique/cutecatsgallery/di/DependencyInjection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.luishenrique.cutecatsgallery.di | ||
|
||
import com.luishenrique.cutecatsgallery.home.di.HomeModule | ||
|
||
object DependencyInjection { | ||
val modules = listOf( | ||
RetrofitModule.instance, | ||
HomeModule.instance | ||
) | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/kotlin/com/luishenrique/cutecatsgallery/di/RetrofitModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.luishenrique.cutecatsgallery.di | ||
|
||
import com.luishenrique.cutecatsgallery.BuildConfig | ||
import com.luishenrique.cutecatsgallery.network.CuteCatsInterceptor | ||
import okhttp3.OkHttpClient | ||
import org.koin.core.module.dsl.factoryOf | ||
import org.koin.core.module.dsl.singleOf | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitModule { | ||
val instance = module { | ||
factoryOf(::CuteCatsInterceptor) | ||
factoryOf(::provideOkHttpClient) | ||
singleOf(::provideRetrofit) | ||
} | ||
|
||
private fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(BuildConfig.API_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(GsonConverterFactory.create()).build() | ||
} | ||
|
||
private fun provideOkHttpClient(interceptor: CuteCatsInterceptor): OkHttpClient { | ||
return OkHttpClient().newBuilder().addInterceptor(interceptor).build() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...rc/main/kotlin/com/luishenrique/cutecatsgallery/home/data/dataSource/GalleryDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.luishenrique.cutecatsgallery.home.data.dataSource | ||
|
||
import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse | ||
|
||
interface GalleryDataSource { | ||
suspend fun finAllCats(page: Int): GalleryResponse | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...ain/kotlin/com/luishenrique/cutecatsgallery/home/data/dataSource/GalleryDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.luishenrique.cutecatsgallery.home.data.dataSource | ||
|
||
import com.luishenrique.cutecatsgallery.home.data.network.HomeApiService | ||
import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse | ||
|
||
class GalleryDataSourceImpl(private val service: HomeApiService) : GalleryDataSource { | ||
|
||
override suspend fun finAllCats(page: Int): GalleryResponse { | ||
return service.finAllCats(page = page) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/kotlin/com/luishenrique/cutecatsgallery/home/data/mapper/GalleryMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.luishenrique.cutecatsgallery.home.data.mapper | ||
|
||
import com.luishenrique.cutecatsgallery.home.data.network.response.CardImageInfoResponse | ||
import com.luishenrique.cutecatsgallery.home.data.network.response.CardImageResponse | ||
import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse | ||
import com.luishenrique.cutecatsgallery.home.domain.model.CardImage | ||
import com.luishenrique.cutecatsgallery.home.domain.model.CardImageInfo | ||
import com.luishenrique.cutecatsgallery.home.domain.model.Gallery | ||
|
||
object GalleryMapper { | ||
|
||
fun mapToModel(response: GalleryResponse) : Gallery { | ||
return Gallery( | ||
data = getCards(response.data) | ||
) | ||
} | ||
|
||
private fun getCards(data: List<CardImageResponse?>?): List<CardImage> { | ||
return data?.map { getCardImage(it) }.orEmpty() | ||
} | ||
|
||
private fun getCardImage(cardImage: CardImageResponse?) : CardImage { | ||
return CardImage( | ||
title = cardImage?.title.orEmpty(), | ||
username = cardImage?.username.orEmpty(), | ||
score = cardImage?.score ?: 0, | ||
images = getImages(cardImage?.images).orEmpty() | ||
) | ||
} | ||
|
||
private fun getImages(images: List<CardImageInfoResponse>?): List<CardImageInfo>? { | ||
return images?.map { getCardImageInfo(it) } | ||
} | ||
|
||
private fun getCardImageInfo(cardImageInfo: CardImageInfoResponse?) : CardImageInfo { | ||
return CardImageInfo( | ||
type = cardImageInfo?.type.orEmpty(), | ||
link = cardImageInfo?.link.orEmpty(), | ||
gifv = cardImageInfo?.gifv.orEmpty(), | ||
mp4 = cardImageInfo?.mp4.orEmpty() | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/kotlin/com/luishenrique/cutecatsgallery/home/data/network/HomeApiService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.luishenrique.cutecatsgallery.home.data.network | ||
|
||
import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Query | ||
|
||
interface HomeApiService { | ||
|
||
@GET("gallery/search/?q=cats") | ||
suspend fun finAllCats( | ||
@Header("Authorization") authHeader: String = "Client-ID 1ceddedc03a5d71", | ||
@Query("sort") sort: String = "viral", | ||
@Query("q_type") type: String = "jpg", | ||
@Query("q_size_px") size: String = "big", | ||
@Query("page") page: Int = 1 | ||
): GalleryResponse | ||
} |
Oops, something went wrong.