fix_: add custom glide module
This commit is contained in:
parent
a360a28b0f
commit
093a3ca4ad
|
@ -299,6 +299,8 @@ dependencies {
|
||||||
implementation("com.squareup.okhttp3:okhttp-tls:4.11.0")
|
implementation("com.squareup.okhttp3:okhttp-tls:4.11.0")
|
||||||
implementation("com.google.prefab:cli:2.0.0")
|
implementation("com.google.prefab:cli:2.0.0")
|
||||||
implementation("com.android.tools.build:aapt2:8.1.1-10154469")
|
implementation("com.android.tools.build:aapt2:8.1.1-10154469")
|
||||||
|
implementation "com.github.bumptech.glide:okhttp3-integration:4.12.0"
|
||||||
|
annotationProcessor "com.github.bumptech.glide:compiler:4.12.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@
|
||||||
<!-- After upgrading Android Gradle Plugin to 4.2.0 and above we must get rid of `extractNativeLibs="true"`
|
<!-- After upgrading Android Gradle Plugin to 4.2.0 and above we must get rid of `extractNativeLibs="true"`
|
||||||
and use`useLegacyPackaging` flag in our app's `build.gradle`-->
|
and use`useLegacyPackaging` flag in our app's `build.gradle`-->
|
||||||
<meta-data android:name="commitHash" android:value="${commitHash}"/>
|
<meta-data android:name="commitHash" android:value="${commitHash}"/>
|
||||||
|
<meta-data
|
||||||
|
android:name="im.status.ethereum.CustomGlideModule"
|
||||||
|
android:value="GlideModule" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package im.status.ethereum
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.Registry
|
||||||
|
import com.bumptech.glide.module.GlideModule
|
||||||
|
import com.bumptech.glide.GlideBuilder
|
||||||
|
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
|
||||||
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
|
class CustomGlideModule : GlideModule {
|
||||||
|
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
|
||||||
|
// Create a single thread executor for background operations
|
||||||
|
val executor = Executors.newSingleThreadExecutor()
|
||||||
|
val mainHandler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
// Execute network operation in background
|
||||||
|
executor.execute {
|
||||||
|
val client = StatusOkHttpClientFactory().createNewNetworkModuleClient()
|
||||||
|
|
||||||
|
// Post results back to main thread
|
||||||
|
mainHandler.post {
|
||||||
|
client?.let {
|
||||||
|
val factory = OkHttpUrlLoader.Factory(it)
|
||||||
|
registry.replace(
|
||||||
|
GlideUrl::class.java,
|
||||||
|
InputStream::class.java,
|
||||||
|
factory
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up executor
|
||||||
|
executor.shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyOptions(context: Context, builder: GlideBuilder) {
|
||||||
|
// No additional options needed
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue