Commit 7547473f authored by Leonardo Aramaki's avatar Leonardo Aramaki

Properly configure glide lib with kapt

parent 7d61df3b
...@@ -46,7 +46,7 @@ ext { ...@@ -46,7 +46,7 @@ ext {
frescoImageViewer : '0.5.1', frescoImageViewer : '0.5.1',
markwon : '1.0.6', markwon : '1.0.6',
aVLoadingIndicatorView: '2.1.3', aVLoadingIndicatorView: '2.1.3',
glide : '4.7.1', glide : '4.8.0-SNAPSHOT',
// For wearable // For wearable
wear : '2.3.0', wear : '2.3.0',
......
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android { android {
compileSdkVersion versions.compileSdk compileSdkVersion versions.compileSdk
...@@ -35,7 +36,7 @@ dependencies { ...@@ -35,7 +36,7 @@ dependencies {
implementation libraries.recyclerview implementation libraries.recyclerview
implementation libraries.material implementation libraries.material
implementation libraries.glide implementation libraries.glide
annotationProcessor libraries.glideProcessor kapt libraries.glideProcessor
} }
kotlin { kotlin {
......
...@@ -8,6 +8,7 @@ import android.text.SpannableString ...@@ -8,6 +8,7 @@ import android.text.SpannableString
import android.text.Spanned import android.text.Spanned
import android.text.style.ImageSpan import android.text.style.ImageSpan
import android.util.Log import android.util.Log
import chat.rocket.android.emoji.internal.GlideApp
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.gif.GifDrawable import com.bumptech.glide.load.resource.gif.GifDrawable
...@@ -73,7 +74,7 @@ class EmojiParser { ...@@ -73,7 +74,7 @@ class EmojiParser {
val customEmojis = EmojiRepository.getCustomEmojis() val customEmojis = EmojiRepository.getCustomEmojis()
val density = context.resources.displayMetrics.density val density = context.resources.displayMetrics.density
val px = (24 * density).toInt() val px = (22 * density).toInt()
return spannable.also { return spannable.also {
regex.findAll(spannable).iterator().forEach { match -> regex.findAll(spannable).iterator().forEach { match ->
...@@ -81,15 +82,13 @@ class EmojiParser { ...@@ -81,15 +82,13 @@ class EmojiParser {
it.url?.let { url -> it.url?.let { url ->
try { try {
val glideRequest = if (url.endsWith("gif", true)) { val glideRequest = if (url.endsWith("gif", true)) {
Glide.with(context).asGif() GlideApp.with(context).asGif()
} else { } else {
Glide.with(context).asBitmap() GlideApp.with(context).asBitmap()
} }
val futureTarget = glideRequest val futureTarget = glideRequest
.apply(RequestOptions() .diskCacheStrategy(DiskCacheStrategy.ALL)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.onlyRetrieveFromCache(true))
.load(url) .load(url)
.submit(px, px) .submit(px, px)
...@@ -99,7 +98,7 @@ class EmojiParser { ...@@ -99,7 +98,7 @@ class EmojiParser {
spannable.setSpan(ImageSpan(context, image), range.start, spannable.setSpan(ImageSpan(context, image), range.start,
range.endInclusive + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) range.endInclusive + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
} else if (image is GifDrawable) { } else if (image is GifDrawable) {
image.setBounds(0, 0, px, px) image.setBounds(0, 0, image.intrinsicWidth, image.intrinsicHeight)
spannable.setSpan(ImageSpan(image), range.start, spannable.setSpan(ImageSpan(image), range.start,
range.endInclusive + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) range.endInclusive + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
} }
......
package chat.rocket.android.emoji.internal
import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory
import com.bumptech.glide.module.AppGlideModule
@GlideModule
class EmojiGlideModule : AppGlideModule() {
override fun applyOptions(context: Context, builder: GlideBuilder) {
builder.setDiskCache(ExternalPreferredCacheDiskCacheFactory(context))
}
}
...@@ -15,6 +15,8 @@ import chat.rocket.android.emoji.EmojiRepository ...@@ -15,6 +15,8 @@ import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.emoji.Fitzpatrick import chat.rocket.android.emoji.Fitzpatrick
import chat.rocket.android.emoji.R import chat.rocket.android.emoji.R
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import kotlinx.android.synthetic.main.emoji_category_layout.view.* import kotlinx.android.synthetic.main.emoji_category_layout.view.*
import kotlinx.android.synthetic.main.emoji_image_row_item.view.* import kotlinx.android.synthetic.main.emoji_image_row_item.view.*
...@@ -159,8 +161,9 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) : ...@@ -159,8 +161,9 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
parsedUnicode parsedUnicode
} }
} else { } else {
Glide.with(context) GlideApp.with(context)
.load(emoji.url) .load(emoji.url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(emoji_image_view) .into(emoji_image_view)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment