Commit 186f131e authored by Marius Volkhart's avatar Marius Volkhart

Change ImagePipelineConfig initialization in Dagger graph

Rather than creating a new, unsized HashSet, use idiomatic Kotlin to create the set of RequestListeners for the ImagePipelineConfig. Under the hood a SingletonSet will be used which is optimized for the current use case, but if additional Listeners are added, the collections will automatically be sized appropriately. This leads to better memory utilization and reduced CPU usage.
parent 32e8e70f
...@@ -38,7 +38,6 @@ import chat.rocket.core.internal.ReactionsAdapter ...@@ -38,7 +38,6 @@ import chat.rocket.core.internal.ReactionsAdapter
import com.facebook.drawee.backends.pipeline.DraweeConfig import com.facebook.drawee.backends.pipeline.DraweeConfig
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
import com.facebook.imagepipeline.core.ImagePipelineConfig import com.facebook.imagepipeline.core.ImagePipelineConfig
import com.facebook.imagepipeline.listener.RequestListener
import com.facebook.imagepipeline.listener.RequestLoggingListener import com.facebook.imagepipeline.listener.RequestLoggingListener
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import dagger.Module import dagger.Module
...@@ -138,8 +137,7 @@ class AppModule { ...@@ -138,8 +137,7 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideImagePipelineConfig(context: Context, @ForFresco okHttpClient: OkHttpClient): ImagePipelineConfig { fun provideImagePipelineConfig(context: Context, @ForFresco okHttpClient: OkHttpClient): ImagePipelineConfig {
val listeners = HashSet<RequestListener>() val listeners = setOf(RequestLoggingListener())
listeners.add(RequestLoggingListener())
return OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient) return OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient)
.setRequestListeners(listeners) .setRequestListeners(listeners)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment