T
T
Tsuzukeru2021-05-29 19:10:44
Android
Tsuzukeru, 2021-05-29 19:10:44

Why is Glide not loading imageView?

There is an application consisting of two fragments. The first fragment is a RecyclerView whose ViewHolder is an ImageView and text containing some description. When you click on the ViewHolder - the second fragment will open where the ImageView should load in full screen.

Previously, the application used Picasso and images were loaded in both fragments, but since Glide loads images faster in RecyclerView - I decided to switch to it and it helped. Now the ViewHolder looks like this:

inner class ImageMediaPreviewViewHolder(view: View) : RecyclerView.ViewHolder(view) {

        fun bind(mediaPreview: MediaPreview) {

            val circularProgressDrawable = CircularProgressDrawable(itemView.context)
            circularProgressDrawable.strokeWidth = 5f
            circularProgressDrawable.centerRadius = 30f
            circularProgressDrawable.setColorSchemeColors(Color.WHITE)
            circularProgressDrawable.start()

            GlideApp.with(itemView.context)
                .load(mediaPreview.previewUrl)
                .placeholder(circularProgressDrawable)
                .into(itemView.media_preview_recycler_view_image)

                itemView.setOnClickListener {
                    navController?.navigate(
                        PreviewMediaFragmentDirections.actionMediaFragmentToImageDetailFragment(
                            mediaPreview.nasaId,
                            mediaPreview.mediaType
                        )
                    )
                }

            itemView.description_text_view.text = mediaPreview.description
            itemView.date_created_text_view.text = mediaPreview.dateCreated

            }
    }


But when replacing Picasso with Glide inside the Detail fragment, the image is not loaded.
That is, this code works:

override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
...
        viewModel.mediaDetails.observe(viewLifecycleOwner, { mediaDetailResponse ->
            picasso
                .load("https://images-assets.nasa.gov/image/201210220003HQ/201210220003HQ~thumb.jpg")
                .into(imageView) })
}


And the following code no longer works, although the parameters are the same:

override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
...
        viewModel.mediaDetails.observe(viewLifecycleOwner, { mediaDetailResponse ->
           Glide.with(requireContext())
                .load("https://images-assets.nasa.gov/image/201210220003HQ/201210220003HQ~thumb.jpg")
                .into(imageView)
}


The following message comes to the log:
W/Glide: Failed to find GeneratedAppGlideModule.

You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored Found the following solution:
Add a new class.
@GlideModule
class AppNameGlideModule : AppGlideModule() {

    override fun applyOptions(context: Context, builder: GlideBuilder) {
        super.applyOptions(context, builder)
        builder.apply { RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).signature(ObjectKey(System.currentTimeMillis().toShort())) }
    }

}


and load the ImageView with it.
GlideApp.with(context)
            .load(url)
            .into(imageView)


The message is no longer logged, but Glide still doesn't load the ImageView in the Detail fragment. What else could be the reason?

I’m analyzing application examples and almost all of them have a simple call:
Glide.with(context)
    .load(url)
    .into(imageView);

In both the ViewHolder and the Detail fragment, only the context changes. For some reason this doesn't work for me.

Here is my build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.nasa.app"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    dataBinding {
        enabled true
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'

    implementation 'com.google.android.material:material:1.2.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    testImplementation "com.google.truth:truth:1.0.1"

    //ViewModel and LiveData
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'

    //Recyclerview
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
    implementation 'androidx.cardview:cardview:1.0.0'

    //Retrofit
    def retrofit_version = "2.9.0"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    // Gson
    implementation "com.google.code.gson:gson:2.8.5"

    // Paging
    implementation "androidx.paging:paging-runtime:2.1.0"

    //Rx
    implementation 'io.reactivex.rxjava2:rxjava:2.2.7'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

    //Picasso
    implementation 'com.squareup.picasso:picasso:2.71828'

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    //ExoPlayer
    implementation 'com.google.android.exoplayer:exoplayer:2.13.1'

    //FlexBoxLayout
    implementation 'com.google.android:flexbox:2.0.1'

    //Dagger
    def dagger_version = "2.33"
    implementation "com.google.dagger:dagger:$dagger_version"
    kapt "com.google.dagger:dagger-compiler:$dagger_version"

    //LeakCanary
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question