From 9f04fd005925ffc39c3e103e9e88a1a85977bee0 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Fri, 1 Jul 2022 18:24:28 -0700 Subject: [PATCH] Use KSP in the gallery sample, remove references to generated API. This helps verify that the ksp process works and shows the changes required when the generated API is not available. --- samples/gallery/build.gradle | 4 ++-- .../com/bumptech/glide/samples/gallery/GalleryModule.kt | 9 ++++++++- .../glide/samples/gallery/HorizontalGalleryFragment.kt | 3 ++- .../com/bumptech/glide/samples/gallery/MainActivity.kt | 3 ++- .../bumptech/glide/samples/gallery/RecyclerAdapter.kt | 5 +++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/samples/gallery/build.gradle b/samples/gallery/build.gradle index 778ce33558..5ef74a01ef 100644 --- a/samples/gallery/build.gradle +++ b/samples/gallery/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' apply plugin: "org.jetbrains.kotlin.plugin.parcelize" +apply plugin: 'com.google.devtools.ksp' dependencies { implementation project(':library') @@ -18,7 +18,7 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$JETBRAINS_KOTLINX_COROUTINES_VERSION" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$JETBRAINS_KOTLIN_VERSION" - kapt project(':annotation:compiler') + ksp project(':annotation:ksp') } kotlin { diff --git a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/GalleryModule.kt b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/GalleryModule.kt index 2ccd368f87..10ffc439d4 100644 --- a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/GalleryModule.kt +++ b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/GalleryModule.kt @@ -1,8 +1,15 @@ package com.bumptech.glide.samples.gallery +import android.content.Context +import com.bumptech.glide.GlideBuilder import com.bumptech.glide.annotation.GlideModule import com.bumptech.glide.module.AppGlideModule /** Ensures that Glide's generated API is created for the Gallery sample. */ @GlideModule -class GalleryModule : AppGlideModule() \ No newline at end of file +class GalleryModule : AppGlideModule() { + override fun applyOptions(context: Context, builder: GlideBuilder) { + super.applyOptions(context, builder) + builder.setIsActiveResourceRetentionAllowed(true) + } +} diff --git a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/HorizontalGalleryFragment.kt b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/HorizontalGalleryFragment.kt index 484d497c51..1173f1131c 100644 --- a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/HorizontalGalleryFragment.kt +++ b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/HorizontalGalleryFragment.kt @@ -11,6 +11,7 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader import kotlinx.coroutines.launch @@ -40,7 +41,7 @@ class HorizontalGalleryFragment : Fragment() { recyclerView.layoutManager = layoutManager recyclerView.setHasFixedSize(true) - val glideRequests = GlideApp.with(this) + val glideRequests = Glide.with(this) adapter = RecyclerAdapter(requireContext(), glideRequests) val preloader = RecyclerViewPreloader(glideRequests, adapter, adapter, 3) recyclerView.addOnScrollListener(preloader) diff --git a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.kt b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.kt index b8cbaa8e3f..9aeca681fb 100644 --- a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.kt +++ b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.kt @@ -8,6 +8,7 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity +import com.bumptech.glide.Glide import com.bumptech.glide.MemoryCategory /** Displays a [HorizontalGalleryFragment]. */ @@ -15,7 +16,7 @@ class MainActivity : FragmentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.main_activity) - GlideApp.get(this).setMemoryCategory(MemoryCategory.HIGH) + Glide.get(this).setMemoryCategory(MemoryCategory.HIGH) if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) { diff --git a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/RecyclerAdapter.kt b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/RecyclerAdapter.kt index e48eccffe8..fd7c8c79f7 100644 --- a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/RecyclerAdapter.kt +++ b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/RecyclerAdapter.kt @@ -15,6 +15,7 @@ import com.bumptech.glide.samples.gallery.RecyclerAdapter.ListViewHolder import com.bumptech.glide.ListPreloader.PreloadSizeProvider import com.bumptech.glide.ListPreloader.PreloadModelProvider import com.bumptech.glide.RequestBuilder +import com.bumptech.glide.RequestManager import com.bumptech.glide.load.Key import com.bumptech.glide.signature.MediaStoreSignature import com.bumptech.glide.util.Preconditions @@ -22,12 +23,12 @@ import com.bumptech.glide.util.Preconditions /** Displays [com.bumptech.glide.samples.gallery.MediaStoreData] in a recycler view. */ internal class RecyclerAdapter( context: Context, - glideRequests: GlideRequests, + glideRequests: RequestManager, ) : RecyclerView.Adapter(), PreloadSizeProvider, PreloadModelProvider { private var data: List = emptyList() private val screenWidth: Int - private val requestBuilder: GlideRequest + private val requestBuilder: RequestBuilder private var actualDimensions: IntArray? = null override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ListViewHolder {