Prevent cleaning whole Glide cache when contacts are loaded
This commit is contained in:
parent
47f0f3ddf4
commit
ce601634f2
3 changed files with 18 additions and 9 deletions
|
@ -23,7 +23,6 @@ import android.content.Context
|
|||
import android.database.Cursor
|
||||
import android.os.AsyncTask
|
||||
import android.provider.ContactsContract
|
||||
import com.bumptech.glide.Glide
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.core.*
|
||||
|
@ -105,9 +104,6 @@ class AsyncContactsLoader(private val context: Context) :
|
|||
}
|
||||
|
||||
if (PermissionHelper.required(context).hasReadContactsPermission()) {
|
||||
// Clear Glide cache to be able to display new contact avatars
|
||||
Glide.get(context).clearDiskCache()
|
||||
|
||||
var selection: String? = null
|
||||
if (corePreferences.fetchContactsFromDefaultDirectory) {
|
||||
Log.i("[Contacts Loader] Only fetching contacts in default directory")
|
||||
|
|
|
@ -84,6 +84,8 @@ class ContactsManager(private val context: Context) {
|
|||
magicSearch
|
||||
}
|
||||
|
||||
var latestContactFetch: String = ""
|
||||
|
||||
private val contactsUpdatedListeners = ArrayList<ContactsUpdatedListener>()
|
||||
|
||||
private var loadContactsTask: AsyncContactsLoader? = null
|
||||
|
@ -138,6 +140,8 @@ class ContactsManager(private val context: Context) {
|
|||
|
||||
@Synchronized
|
||||
fun fetchContactsAsync() {
|
||||
latestContactFetch = System.currentTimeMillis().toString()
|
||||
|
||||
if (loadContactsTask != null) {
|
||||
Log.w("[Contacts Manager] Cancelling existing async task")
|
||||
loadContactsTask?.cancel(true)
|
||||
|
|
|
@ -40,8 +40,10 @@ import com.bumptech.glide.load.engine.GlideException
|
|||
import com.bumptech.glide.request.RequestListener
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.request.target.Target
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||
import org.linphone.BR
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.GenericActivity
|
||||
|
@ -304,9 +306,11 @@ fun <T> setEntries(
|
|||
@BindingAdapter("glideAvatarFallback")
|
||||
fun loadAvatarWithGlideFallback(imageView: ImageView, path: String?) {
|
||||
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
|
||||
GlideApp.with(imageView).load(path).apply(RequestOptions.circleCropTransform()).into(
|
||||
imageView
|
||||
)
|
||||
GlideApp.with(imageView)
|
||||
.load(path)
|
||||
.signature(ObjectKey(coreContext.contactsManager.latestContactFetch))
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(imageView)
|
||||
} else {
|
||||
Log.w("[Data Binding] [Glide] Can't load $path")
|
||||
imageView.setImageResource(R.drawable.avatar)
|
||||
|
@ -330,7 +334,11 @@ fun loadAvatarWithGlide(imageView: ImageView, path: Uri?) {
|
|||
@BindingAdapter("glideAvatar")
|
||||
fun loadAvatarWithGlide(imageView: ImageView, path: String?) {
|
||||
if (path != null) {
|
||||
GlideApp.with(imageView).load(path).apply(RequestOptions.circleCropTransform()).listener(
|
||||
GlideApp
|
||||
.with(imageView)
|
||||
.load(path)
|
||||
.signature(ObjectKey(coreContext.contactsManager.latestContactFetch))
|
||||
.apply(RequestOptions.circleCropTransform()).listener(
|
||||
object :
|
||||
RequestListener<Drawable?> {
|
||||
override fun onLoadFailed(
|
||||
|
@ -354,7 +362,8 @@ fun loadAvatarWithGlide(imageView: ImageView, path: String?) {
|
|||
imageView.visibility = View.VISIBLE
|
||||
return false
|
||||
}
|
||||
}).into(imageView)
|
||||
})
|
||||
.into(imageView)
|
||||
} else {
|
||||
imageView.visibility = View.GONE
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue