2

Android studio 3.6

build.gradle:

android {

    dataBinding {
        enabled = true
    }
    // Configure only for each module that uses Java 8
    // language features (either in its source code or
    // through dependencies). E.g. lambda expressions.
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.project.client"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 80
        versionName "0.0.80"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }



    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    // use e.g. in my custom RecyclerView.Adapter
    //apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'io.fabric'


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

Here my RecyclerView adaptder:

class GazStationAdapter(newActivity: Activity, private val data: List<String>) :
    RecyclerView.Adapter<GazStationAdapter.ViewHolder>() {
    var activity: Activity? = null

    init {
        this.activity = newActivity
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater = LayoutInflater.from(parent.context)
        val v = inflater.inflate(R.layout.gazstation_item_service_card, parent, false)
        return ViewHolder(v)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val serivceURL = "http://www.gravatar.com/avatar/11111?s=40x40&d=identicon"
        Debug.d("TAG", "onBindViewHolder: serivceURL = $serivceURL")
        Glide.with(holder.itemView.context)
            .load(serivceURL)
            .listener(object : RequestListener<Drawable> {
                override fun onLoadFailed(
                    e: GlideException?,
                    model: Any?,
                    target: Target<Drawable>?,
                    isFirstResource: Boolean
                ): Boolean {
                    Debug.d("TAG", "onBindViewHolder: glide_load_onLoadFailed")
                    return false;
                }

                override fun onResourceReady(
                    resource: Drawable?,
                    model: Any?,
                    target: Target<Drawable>?,
                    dataSource: DataSource?,
                    isFirstResource: Boolean
                ): Boolean {
                    Debug.d("TAG", "onBindViewHolder: glide_load_ready")
                    return false
                }

            })
            .placeholder(R.drawable.profile)
            .into(holder.image)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        val image: ImageView

        init {
            image = itemView.findViewById<View>(R.id.gazStaionServiceimage) as ImageView
        }
    }
}

here gazstation_item_service_card.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_gravity="center"
    android:layout_margin="4dp"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/gazStaionServiceimage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop" />

</LinearLayout>

But image not load by url

Here logcat:

 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 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
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon
 D TAG     : onBindViewHolder: serivceURL = http://www.gravatar.com/avatar/11111?s=40x40&d=identicon

as you can see the methods onLoadFailed or onResourceReady NOT CALLED. The placeholder R.drawable.profilesuccess show.

Alexei
  • 14,350
  • 37
  • 121
  • 240

1 Answers1

1

If you have config apply plugin kotlin-kapt you have to also replace these line to gradle:

annotationProcessor 'com.github.bumptech.glide:compiler:[version]'

should be replaced by

kapt 'com.github.bumptech.glide:compiler:[version]'
B--rian
  • 5,578
  • 10
  • 38
  • 89
Thành Hà Văn
  • 481
  • 2
  • 9
  • I use this implementation 'com.github.bumptech.glide:glide:4.11.0' kapt 'com.github.bumptech.glide:compiler:4.11.0'. But it not help. Image is not load – Alexei Feb 21 '20 at 08:56
  • @a_subscriber do you have any other annotationProcessor inside app gradle? – Thành Hà Văn Feb 21 '20 at 09:07
  • Not. Only kapt. I use only kapt – Alexei Feb 21 '20 at 09:17
  • Alright, try add this but covert to kotlin package com.example.myapp; import com.bumptech.glide.annotation.GlideModule; import com.bumptech.glide.module.AppGlideModule; @GlideModule public final class MyAppGlideModule extends AppGlideModule {} – Thành Hà Văn Feb 21 '20 at 09:46
  • I also try with @GlideModule but it not help. Not load image – Alexei Feb 21 '20 at 11:22