mirror of https://github.com/readrops/Readrops.git
Fix image loading indefinitely when getting feed colors
This commit is contained in:
parent
07b6059921
commit
116a1b9722
|
@ -33,7 +33,7 @@ val apiModule = module {
|
||||||
single {
|
single {
|
||||||
OkHttpClient.Builder()
|
OkHttpClient.Builder()
|
||||||
.callTimeout(1, TimeUnit.MINUTES)
|
.callTimeout(1, TimeUnit.MINUTES)
|
||||||
.readTimeout(1, TimeUnit.HOURS)
|
.readTimeout(1, TimeUnit.MINUTES)
|
||||||
.addInterceptor(get<AuthInterceptor>())
|
.addInterceptor(get<AuthInterceptor>())
|
||||||
.addInterceptor(get<ErrorInterceptor>())
|
.addInterceptor(get<ErrorInterceptor>())
|
||||||
//.addInterceptor(NiddlerOkHttpInterceptor(get(), "niddler"))
|
//.addInterceptor(NiddlerOkHttpInterceptor(get(), "niddler"))
|
||||||
|
|
|
@ -87,14 +87,12 @@ class SyncWorker(
|
||||||
.setProgress(syncResult.newFeedIds.size, index + 1, false)
|
.setProgress(syncResult.newFeedIds.size, index + 1, false)
|
||||||
notificationManager.notify(SYNC_NOTIFICATION_ID, notificationBuilder.build())
|
notificationManager.notify(SYNC_NOTIFICATION_ID, notificationBuilder.build())
|
||||||
|
|
||||||
val color = try {
|
try {
|
||||||
FeedColors.getFeedColor(syncResult.feeds.first { it.id == feedId.toInt() }.iconUrl!!)
|
val color = FeedColors.getFeedColor(syncResult.feeds.first { it.id == feedId.toInt() }.iconUrl!!)
|
||||||
|
database.newFeedDao().updateFeedColor(feedId.toInt(), color)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "${e.message}")
|
Log.e(TAG, "$feedName: ${e.message}")
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
database.newFeedDao().updateFeedColor(feedId.toInt(), color)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,30 @@
|
||||||
package com.readrops.app.compose.util
|
package com.readrops.app.compose.util
|
||||||
|
|
||||||
import android.content.Context
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.drawable.BitmapDrawable
|
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.palette.graphics.Palette
|
import androidx.palette.graphics.Palette
|
||||||
import coil.imageLoader
|
import okhttp3.OkHttpClient
|
||||||
import coil.request.ImageRequest
|
import okhttp3.Request
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
|
|
||||||
object FeedColors : KoinComponent {
|
object FeedColors : KoinComponent {
|
||||||
|
|
||||||
suspend fun getFeedColor(feedUrl: String): Int {
|
suspend fun getFeedColor(feedUrl: String): Int {
|
||||||
val context = get<Context>() // TODO maybe call imageLoader directly ? may require some DI changes
|
// use OkHttp directly instead of Coil as Coil doesn't respect OkHttp timeout
|
||||||
|
val response = get<OkHttpClient>().newCall(
|
||||||
|
Request.Builder()
|
||||||
|
.url(feedUrl)
|
||||||
|
.build()
|
||||||
|
).execute()
|
||||||
|
|
||||||
val result = context.imageLoader
|
val bitmap = BitmapFactory.decodeStream(response.body?.byteStream()) ?: return 0
|
||||||
.execute(
|
val palette = Palette.from(bitmap).generate()
|
||||||
ImageRequest.Builder(context)
|
|
||||||
.data(feedUrl)
|
|
||||||
.allowHardware(false)
|
|
||||||
.build()
|
|
||||||
).drawable as BitmapDrawable
|
|
||||||
|
|
||||||
val palette = Palette.from(result.bitmap).generate()
|
|
||||||
|
|
||||||
val dominantSwatch = palette.dominantSwatch
|
val dominantSwatch = palette.dominantSwatch
|
||||||
return if (dominantSwatch != null && !isColorTooBright(dominantSwatch.rgb)
|
return if (dominantSwatch != null && !isColorTooBright(dominantSwatch.rgb)
|
||||||
&& !isColorTooDark(dominantSwatch.rgb)) {
|
&& !isColorTooDark(dominantSwatch.rgb)
|
||||||
|
) {
|
||||||
dominantSwatch.rgb
|
dominantSwatch.rgb
|
||||||
} else 0
|
} else 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue