Created
July 30, 2017 17:40
-
-
Save wakim/86eab73ccb03cebb093fb1ed45d77000 to your computer and use it in GitHub Desktop.
My Glide usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.net.ConnectivityManager | |
import com.bumptech.glide.GlideBuilder | |
import com.bumptech.glide.Registry | |
import com.bumptech.glide.annotation.GlideModule | |
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader | |
import com.bumptech.glide.load.model.GlideUrl | |
import com.bumptech.glide.module.AppGlideModule | |
import okhttp3.OkHttpClient | |
import java.io.InputStream | |
@GlideModule | |
class CustomGlideModule : AppGlideModule() { | |
override fun applyOptions(context: Context?, builder: GlideBuilder?) {} | |
override fun registerComponents(context: Context?, registry: Registry?) { | |
val ctx = context ?: return | |
val okhttp = OkHttpClient.Builder() | |
.addInterceptor(NetworkExceptionInterceptor(ctx.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)) | |
.build() | |
val factory = OkHttpUrlLoader.Factory(okhttp) | |
registry?.replace(GlideUrl::class.java, InputStream::class.java, factory) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bumptech.glide; | |
import android.content.Context; | |
import android.util.Log; | |
import com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule; | |
import java.lang.Class; | |
import java.lang.Override; | |
import java.lang.SuppressWarnings; | |
import java.util.Collections; | |
import java.util.Set; | |
@SuppressWarnings("deprecation") | |
final class GeneratedAppGlideModuleImpl extends GeneratedAppGlideModule { | |
private final CustomGlideModule appGlideModule; | |
GeneratedAppGlideModuleImpl() { | |
appGlideModule = new CustomGlideModule(); | |
if (Log.isLoggable("Glide", Log.DEBUG)) { | |
Log.d("Glide", "Discovered AppGlideModule from annotation: br.com.egasosa.data.CustomGlideModule"); | |
Log.d("Glide", "Discovered LibraryGlideModule from annotation: com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule"); | |
} | |
} | |
@Override | |
public void applyOptions(Context context, GlideBuilder builder) { | |
appGlideModule.applyOptions(context, builder); | |
} | |
@Override | |
public void registerComponents(Context context, Registry registry) { | |
new OkHttpLibraryGlideModule().registerComponents(context, registry); | |
appGlideModule.registerComponents(context, registry); | |
} | |
@Override | |
public boolean isManifestParsingEnabled() { | |
return appGlideModule.isManifestParsingEnabled(); | |
} | |
@Override | |
public Set<Class<?>> getExcludedModuleClasses() { | |
return Collections.emptySet(); | |
} | |
@Override | |
GeneratedRequestManagerFactory getRequestManagerFactory() { | |
return new GeneratedRequestManagerFactory(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment