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