Replaced glide by Coil
This commit is contained in:
parent
7f63de9e1b
commit
0c085ed0b5
5 changed files with 58 additions and 93 deletions
|
@ -229,9 +229,11 @@ dependencies {
|
||||||
implementation 'androidx.emoji:emoji:1.1.0'
|
implementation 'androidx.emoji:emoji:1.1.0'
|
||||||
implementation 'androidx.emoji:emoji-bundled:1.1.0'
|
implementation 'androidx.emoji:emoji-bundled:1.1.0'
|
||||||
|
|
||||||
// https://github.com/bumptech/glide/blob/master/LICENSE, BSD / Apache v2
|
// https://github.com/coil-kt/coil/blob/main/LICENSE.txt Apache v2.0
|
||||||
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
def coil_version = "2.0.0-rc03"
|
||||||
kapt 'com.github.bumptech.glide:compiler:4.12.0'
|
implementation("io.coil-kt:coil:$coil_version")
|
||||||
|
implementation("io.coil-kt:coil-gif:$coil_version")
|
||||||
|
implementation("io.coil-kt:coil-svg:$coil_version")
|
||||||
|
|
||||||
// https://github.com/Baseflow/PhotoView/blob/master/LICENSE Apache v2.0
|
// https://github.com/Baseflow/PhotoView/blob/master/LICENSE Apache v2.0
|
||||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||||
|
|
|
@ -22,10 +22,18 @@ package org.linphone
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import coil.ImageLoader
|
||||||
|
import coil.ImageLoaderFactory
|
||||||
|
import coil.decode.GifDecoder
|
||||||
|
import coil.decode.ImageDecoderDecoder
|
||||||
|
import coil.decode.SvgDecoder
|
||||||
|
import coil.disk.DiskCache
|
||||||
|
import coil.memory.MemoryCache
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
import org.linphone.mediastream.Version
|
||||||
|
|
||||||
class LinphoneApplication : Application() {
|
class LinphoneApplication : Application(), ImageLoaderFactory {
|
||||||
companion object {
|
companion object {
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
lateinit var corePreferences: CorePreferences
|
lateinit var corePreferences: CorePreferences
|
||||||
|
@ -74,4 +82,28 @@ class LinphoneApplication : Application() {
|
||||||
ensureCoreExists(applicationContext)
|
ensureCoreExists(applicationContext)
|
||||||
Log.i("[Application] Created")
|
Log.i("[Application] Created")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun newImageLoader(): ImageLoader {
|
||||||
|
return ImageLoader.Builder(this)
|
||||||
|
.components {
|
||||||
|
add(SvgDecoder.Factory())
|
||||||
|
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
|
||||||
|
add(ImageDecoderDecoder.Factory())
|
||||||
|
} else {
|
||||||
|
add(GifDecoder.Factory())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.memoryCache {
|
||||||
|
MemoryCache.Builder(this)
|
||||||
|
.maxSizePercent(0.25)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
.diskCache {
|
||||||
|
DiskCache.Builder()
|
||||||
|
.directory(cacheDir.resolve("image_cache"))
|
||||||
|
.maxSizePercent(0.02)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavDestination
|
import androidx.navigation.NavDestination
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.window.layout.FoldingFeature
|
import androidx.window.layout.FoldingFeature
|
||||||
|
import coil.imageLoader
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import java.io.UnsupportedEncodingException
|
import java.io.UnsupportedEncodingException
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
|
@ -63,7 +64,6 @@ import org.linphone.databinding.MainActivityBinding
|
||||||
import org.linphone.utils.AppUtils
|
import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.FileUtils
|
import org.linphone.utils.FileUtils
|
||||||
import org.linphone.utils.GlideApp
|
|
||||||
|
|
||||||
class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestinationChangedListener {
|
class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestinationChangedListener {
|
||||||
private lateinit var binding: MainActivityBinding
|
private lateinit var binding: MainActivityBinding
|
||||||
|
@ -99,7 +99,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
||||||
|
|
||||||
override fun onTrimMemory(level: Int) {
|
override fun onTrimMemory(level: Int) {
|
||||||
Log.w("[Main Activity] onTrimMemory called with level $level !")
|
Log.w("[Main Activity] onTrimMemory called with level $level !")
|
||||||
GlideApp.get(this@MainActivity).clearMemory()
|
applicationContext.imageLoader.memoryCache?.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
|
@ -39,16 +38,11 @@ import android.widget.SeekBar.OnSeekBarChangeListener
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.constraintlayout.widget.Guideline
|
import androidx.constraintlayout.widget.Guideline
|
||||||
import androidx.databinding.*
|
import androidx.databinding.*
|
||||||
import com.bumptech.glide.load.DataSource
|
import coil.load
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import coil.request.CachePolicy
|
||||||
import com.bumptech.glide.load.engine.GlideException
|
import coil.transform.CircleCropTransformation
|
||||||
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 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
|
||||||
|
@ -313,18 +307,8 @@ fun setImageViewScaleType(imageView: ImageView, scaleType: ImageView.ScaleType)
|
||||||
@BindingAdapter("glideRoundPath")
|
@BindingAdapter("glideRoundPath")
|
||||||
fun loadRoundImageWithGlide(imageView: ImageView, path: String?) {
|
fun loadRoundImageWithGlide(imageView: ImageView, path: String?) {
|
||||||
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
|
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
|
||||||
if (corePreferences.vfsEnabled && path.endsWith(FileUtils.VFS_PLAIN_FILE_EXTENSION)) {
|
imageView.load(path) {
|
||||||
GlideApp.with(imageView)
|
transformations(CircleCropTransformation())
|
||||||
.load(path)
|
|
||||||
.signature(ObjectKey(coreContext.contactsManager.latestContactFetch))
|
|
||||||
.apply(RequestOptions.circleCropTransform())
|
|
||||||
.into(imageView)
|
|
||||||
} else {
|
|
||||||
GlideApp
|
|
||||||
.with(imageView)
|
|
||||||
.load(path)
|
|
||||||
.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")
|
||||||
|
@ -335,13 +319,11 @@ fun loadRoundImageWithGlide(imageView: ImageView, path: String?) {
|
||||||
fun loadImageWithGlide(imageView: ImageView, path: String?) {
|
fun loadImageWithGlide(imageView: ImageView, path: String?) {
|
||||||
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
|
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
|
||||||
if (corePreferences.vfsEnabled && path.endsWith(FileUtils.VFS_PLAIN_FILE_EXTENSION)) {
|
if (corePreferences.vfsEnabled && path.endsWith(FileUtils.VFS_PLAIN_FILE_EXTENSION)) {
|
||||||
GlideApp.with(imageView)
|
imageView.load(path) {
|
||||||
.load(path)
|
diskCachePolicy(CachePolicy.DISABLED)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
}
|
||||||
.skipMemoryCache(true)
|
|
||||||
.into(imageView)
|
|
||||||
} else {
|
} else {
|
||||||
GlideApp.with(imageView).load(path).into(imageView)
|
imageView.load(path)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w("[Data Binding] [Glide] Can't load $path")
|
Log.w("[Data Binding] [Glide] Can't load $path")
|
||||||
|
@ -357,35 +339,18 @@ fun loadAvatarWithGlide(imageView: ImageView, path: Uri?) {
|
||||||
fun loadAvatarWithGlide(imageView: ImageView, path: String?) {
|
fun loadAvatarWithGlide(imageView: ImageView, path: String?) {
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
imageView.visibility = View.VISIBLE
|
imageView.visibility = View.VISIBLE
|
||||||
GlideApp
|
imageView.load(path) {
|
||||||
.with(imageView)
|
transformations(CircleCropTransformation())
|
||||||
.load(path)
|
listener(
|
||||||
.signature(ObjectKey(coreContext.contactsManager.latestContactFetch))
|
onError = { _, _ ->
|
||||||
.apply(RequestOptions.circleCropTransform())
|
Log.w("[Data Binding] [Coil] Can't load $path")
|
||||||
.listener(object : RequestListener<Drawable?> {
|
|
||||||
override fun onLoadFailed(
|
|
||||||
e: GlideException?,
|
|
||||||
model: Any?,
|
|
||||||
target: Target<Drawable?>?,
|
|
||||||
isFirstResource: Boolean
|
|
||||||
): Boolean {
|
|
||||||
Log.w("[Data Binding] [Glide] Can't load $path")
|
|
||||||
imageView.visibility = View.GONE
|
imageView.visibility = View.GONE
|
||||||
return false
|
},
|
||||||
}
|
onSuccess = { _, _ ->
|
||||||
|
|
||||||
override fun onResourceReady(
|
|
||||||
resource: Drawable?,
|
|
||||||
model: Any?,
|
|
||||||
target: Target<Drawable?>?,
|
|
||||||
dataSource: DataSource?,
|
|
||||||
isFirstResource: Boolean
|
|
||||||
): Boolean {
|
|
||||||
imageView.visibility = View.VISIBLE
|
imageView.visibility = View.VISIBLE
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
.into(imageView)
|
}
|
||||||
} else {
|
} else {
|
||||||
imageView.visibility = View.GONE
|
imageView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010-2020 Belledonne Communications SARL.
|
|
||||||
*
|
|
||||||
* This file is part of linphone-android
|
|
||||||
* (see https://www.linphone.org).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.linphone.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
|
||||||
import com.bumptech.glide.GlideBuilder
|
|
||||||
import com.bumptech.glide.annotation.GlideModule
|
|
||||||
import com.bumptech.glide.module.AppGlideModule
|
|
||||||
|
|
||||||
@GlideModule
|
|
||||||
class LinphoneGlideModule : AppGlideModule() {
|
|
||||||
override fun applyOptions(context: Context, builder: GlideBuilder) {
|
|
||||||
// Tells Glide to only log errors, prevents warnings because contact doesn't have a picture
|
|
||||||
builder.setLogLevel(Log.ERROR)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue