Merge pull request #128 from esensar/fix/scroll-performance

Convert all drawables into bitmap drawables for faster loading
This commit is contained in:
Tibor Kaputa 2023-09-17 18:06:29 +02:00 committed by GitHub
commit 43b016fa2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View File

@ -29,6 +29,7 @@ import android.view.accessibility.AccessibilityNodeInfo
import android.view.animation.DecelerateInterpolator
import android.widget.PopupMenu
import androidx.core.graphics.drawable.toBitmap
import androidx.core.graphics.drawable.toDrawable
import androidx.core.view.GestureDetectorCompat
import androidx.core.view.WindowCompat
import androidx.core.view.isVisible
@ -845,13 +846,13 @@ class MainActivity : SimpleActivity(), FlingListener {
val label = info.loadLabel(packageManager).toString()
val drawable = info.loadIcon(packageManager) ?: getDrawableForPackageName(packageName) ?: continue
val placeholderColor = calculateAverageColor(drawable.toBitmap())
allApps.add(AppLauncher(null, label, packageName, activityName, 0, placeholderColor, drawable))
allApps.add(AppLauncher(null, label, packageName, activityName, 0, placeholderColor, drawable.toBitmap().toDrawable(resources)))
}
// add Simple Launchers settings as an app
val drawable = getDrawableForPackageName(packageName)
val placeholderColor = calculateAverageColor(drawable!!.toBitmap())
val launcherSettings = AppLauncher(null, getString(R.string.launcher_settings), packageName, "", 0, placeholderColor, drawable)
val launcherSettings = AppLauncher(null, getString(R.string.launcher_settings), packageName, "", 0, placeholderColor, drawable.toBitmap().toDrawable(resources))
allApps.add(launcherSettings)
launchersDB.insertAll(allApps)
return allApps

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.launcher.adapters
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -7,7 +8,9 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.target.DrawableImageViewTarget
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory
import com.bumptech.glide.request.transition.Transition
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.getProperTextColor
@ -109,15 +112,26 @@ class LaunchersAdapter(
binding.launcherLabel.setTextColor(textColor)
binding.launcherIcon.setPadding(iconPadding, iconPadding, iconPadding, 0)
val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build()
val placeholderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.placeholder_drawable, launcher.thumbnailColor)
// Once all images are loaded and crossfades are done, directly set drawables
if (launcher.drawable != null && binding.launcherIcon.tag == true) {
binding.launcherIcon.setImageDrawable(launcher.drawable)
} else {
val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build()
val placeholderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.placeholder_drawable, launcher.thumbnailColor)
Glide.with(activity)
.load(launcher.drawable)
.placeholder(placeholderDrawable)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.transition(DrawableTransitionOptions.withCrossFade(factory))
.into(binding.launcherIcon)
Glide.with(activity)
.load(launcher.drawable)
.placeholder(placeholderDrawable)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.transition(DrawableTransitionOptions.withCrossFade(factory))
.into(object : DrawableImageViewTarget(binding.launcherIcon) {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
super.onResourceReady(resource, transition)
// Set tag to true to mark that crossfade was already done on this view
view.tag = true
}
})
}
setOnClickListener { itemClick(launcher) }
setOnLongClickListener { view ->