Skip to content

Commit

Permalink
coil added.
Browse files Browse the repository at this point in the history
  • Loading branch information
merttoptas committed Oct 16, 2023
1 parent c6d5080 commit eed3c23
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 32 deletions.
50 changes: 20 additions & 30 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ android {
namespace = "com.loodos.samplecomposeandroid"
}
dependencies {
implementation(libs.accompanist.systemuicontroller)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.android.material)
implementation(libs.compose.ui)
implementation(libs.compose.material)
implementation(libs.androidx.compose.material.iconsExtended)
implementation(libs.compose.ui.tooling)
implementation(libs.square.moshi.kotlin)
implementation(libs.square.retrofit)
implementation(libs.square.retrofit.converter.moshi)
implementation(libs.androidx.core.splashscreen)
implementation(libs.okhttp.logging.interceptor)

implementation(projects.feature.login)
implementation(projects.feature.home)
implementation(projects.feature.category)
Expand All @@ -66,32 +50,38 @@ dependencies {
implementation(projects.core.designsystem)
implementation(projects.core.data)
implementation(projects.core.domain)
implementation(projects.core.ui)

testImplementation(libs.junit4)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.accompanist.systemuicontroller)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.fragment.ktx)
implementation(libs.coil.kt)
implementation(libs.compose.state.events)

testImplementation(libs.junit4)
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
androidTestImplementation(libs.compose.ui.test.junit)
androidTestImplementation(libs.hilt.android.testing)
implementation(libs.androidx.hilt.navigation.compose)


debugImplementation(libs.compose.ui.test.manifest)
debugImplementation(libs.compose.ui.tooling)
androidTestImplementation(libs.androidx.navigation.testing)
debugImplementation(libs.square.leakcanary)
implementation(libs.retrofit.converter.gson)

kapt(libs.square.moshi.kotlin.codegen)

debugImplementation(libs.chucker)
releaseImplementation(libs.chucker.no.op)

implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.compose.state.events)
implementation(libs.androidx.fragment.ktx)
implementation(libs.androidx.navigation.compose)

// Core functions
kaptTest(libs.hilt.compiler)
testImplementation(kotlin("test"))
testImplementation(libs.androidx.navigation.testing)

}
12 changes: 11 additions & 1 deletion app/src/main/java/com/loodos/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package com.loodos

import android.app.Application
import coil.ImageLoader
import coil.ImageLoaderFactory
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import javax.inject.Provider

/**
* Created by mertcantoptas on 07.03.2023
*/
@HiltAndroidApp
class MainApplication : Application()
class MainApplication : Application(), ImageLoaderFactory {

@Inject
lateinit var imageLoader: Provider<ImageLoader>

override fun newImageLoader(): ImageLoader = imageLoader.get()
}
6 changes: 5 additions & 1 deletion core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ secrets {
}

dependencies {
implementation(projects.core.common)

implementation(libs.androidx.core.ktx)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.serialization.json)
Expand All @@ -34,5 +36,7 @@ dependencies {

debugImplementation(libs.chucker)
releaseImplementation(libs.chucker.no.op)
implementation(projects.core.common)

implementation(libs.coil.kt)
implementation(libs.coil.kt.svg)
}
37 changes: 37 additions & 0 deletions core/data/src/main/java/com/loodos/data/di/RemoteDataModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.loodos.data.di

import android.content.Context
import coil.ImageLoader
import coil.decode.SvgDecoder
import coil.util.DebugLogger
import com.chuckerteam.chucker.api.ChuckerCollector
import com.chuckerteam.chucker.api.ChuckerInterceptor
import com.chuckerteam.chucker.api.RetentionManager
Expand All @@ -11,6 +14,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.Call
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
Expand Down Expand Up @@ -90,4 +94,37 @@ object RemoteDataModule {
fun provideLoginService(retrofit: Retrofit): AuthenticationService {
return retrofit.create(AuthenticationService::class.java)
}

@Provides
@Singleton
fun provideOkHttpCallFactory(): Call.Factory = OkHttpClient.Builder()
.addInterceptor(
HttpLoggingInterceptor()
.apply {
if (BuildConfig.DEBUG) {
setLevel(HttpLoggingInterceptor.Level.BODY)
}
},
)
.build()

@Provides
@Singleton
fun provideImageLoader(
okHttpCallFactory: Call.Factory,
@ApplicationContext application: Context,
): ImageLoader = ImageLoader.Builder(application)
.callFactory(okHttpCallFactory)
.components {
add(SvgDecoder.Factory())
}
// Assume most content images are versioned urls
// but some problematic images are fetching each time
.respectCacheHeaders(false)
.apply {
if (BuildConfig.DEBUG) {
logger(DebugLogger())
}
}
.build()
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ androidx-metrics = { group = "androidx.metrics", name = "metrics-performance", v
androidx-room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" }
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso" }
androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxTest" }
androidx-compose-ui-testManifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" }
androidx-compose-material-iconsExtended = { group = "androidx.compose.material", name = "material-icons-extended" }
compose-material = { group = "androidx.compose.material3", name = "material3" }
Expand Down

0 comments on commit eed3c23

Please sign in to comment.