diff --git a/twidere/build.gradle b/twidere/build.gradle index 36f328467..ebf5eaf6d 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -34,8 +34,8 @@ android { applicationId "org.mariotaku.twidere" minSdkVersion 14 targetSdkVersion 25 - versionCode 294 - versionName '3.4.32' + versionCode 295 + versionName '3.4.33' multiDexEnabled true buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")' diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/glide/OkHttpGlideModule.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/glide/OkHttpGlideModule.kt index f47a18461..ab4ef0caa 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/glide/OkHttpGlideModule.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/glide/OkHttpGlideModule.kt @@ -20,7 +20,6 @@ package org.mariotaku.twidere.util.glide import android.content.Context - import com.bumptech.glide.Glide import com.bumptech.glide.GlideBuilder import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader @@ -29,7 +28,7 @@ import com.bumptech.glide.module.GlideModule import okhttp3.OkHttpClient import org.mariotaku.twidere.util.HttpClientFactory import org.mariotaku.twidere.util.dagger.DependencyHolder - +import org.mariotaku.twidere.util.media.ThumborInterceptor import java.io.InputStream class OkHttpGlideModule : GlideModule { @@ -43,15 +42,8 @@ class OkHttpGlideModule : GlideModule { val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences) val thumbor = holder.thumbor HttpClientFactory.initOkHttpClient(conf, builder, holder.dns, holder.connectionPool, holder.cache) - builder.addInterceptor { chain -> - val request = chain.request() - if (!thumbor.available) { - return@addInterceptor chain.proceed(request) - } - val rb = request.newBuilder() - rb.url(thumbor.buildUri(request.url().toString())) - return@addInterceptor chain.proceed(rb.build()) - } + builder.addInterceptor(ThumborInterceptor(thumbor)) glide.register(GlideUrl::class.java, InputStream::class.java, OkHttpUrlLoader.Factory(builder.build())) } + } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/media/ThumborInterceptor.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/media/ThumborInterceptor.kt new file mode 100644 index 000000000..776e9d61d --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/media/ThumborInterceptor.kt @@ -0,0 +1,40 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.util.media + +import android.os.Build +import okhttp3.Interceptor +import okhttp3.Response + +class ThumborInterceptor(val thumbor: ThumborWrapper) : Interceptor { + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + if (!thumbor.available) { + return chain.proceed(request) + } + val rb = request.newBuilder() + rb.url(thumbor.buildUri(request.url().toString())) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + rb.header("Accept", "image/webp, */*") + } + return chain.proceed(rb.build()) + } + +} \ No newline at end of file