Skip to content

Commit

Permalink
Merge pull request #4857 from sjudd:ksp_in_gallery
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 466144958
  • Loading branch information
glide-copybara-robot committed Aug 8, 2022
2 parents 2012528 + 9f04fd0 commit 2538359
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions samples/gallery/build.gradle
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
class GalleryModule : AppGlideModule() {
override fun applyOptions(context: Context, builder: GlideBuilder) {
super.applyOptions(context, builder)
builder.setIsActiveResourceRetentionAllowed(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ 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]. */
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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ 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

/** Displays [com.bumptech.glide.samples.gallery.MediaStoreData] in a recycler view. */
internal class RecyclerAdapter(
context: Context,
glideRequests: GlideRequests,
glideRequests: RequestManager,
) : RecyclerView.Adapter<ListViewHolder?>(), PreloadSizeProvider<MediaStoreData?>,
PreloadModelProvider<MediaStoreData?> {
private var data: List<MediaStoreData> = emptyList()
private val screenWidth: Int
private val requestBuilder: GlideRequest<Drawable>
private val requestBuilder: RequestBuilder<Drawable>
private var actualDimensions: IntArray? = null

override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ListViewHolder {
Expand Down

0 comments on commit 2538359

Please sign in to comment.