Skip to content

Commit

Permalink
Fix RegionBitmapDecode usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Oct 23, 2024
1 parent c15a0ec commit 681c80d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
6 changes: 1 addition & 5 deletions app/src/main/kotlin/org/koitharu/kotatsu/core/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.browser.cloudflare.CaptchaNotifier
import org.koitharu.kotatsu.core.db.MangaDatabase
import org.koitharu.kotatsu.core.image.AvifImageDecoder
import org.koitharu.kotatsu.core.image.RegionBitmapDecoder
import org.koitharu.kotatsu.core.network.MangaHttpClient
import org.koitharu.kotatsu.core.network.imageproxy.ImageProxyInterceptor
import org.koitharu.kotatsu.core.os.AppShortcutManager
Expand Down Expand Up @@ -82,9 +81,7 @@ interface AppModule {
@Singleton
fun provideMangaDatabase(
@ApplicationContext context: Context,
): MangaDatabase {
return MangaDatabase(context)
}
): MangaDatabase = MangaDatabase(context)

@Provides
@Singleton
Expand Down Expand Up @@ -122,7 +119,6 @@ interface AppModule {
.add(SvgDecoder.Factory())
.add(CbzFetcher.Factory())
.add(AvifImageDecoder.Factory())
.add(RegionBitmapDecoder.Factory())
.add(FaviconFetcher.Factory(context, okHttpClientLazy, mangaRepositoryFactory))
.add(MangaPageKeyer())
.add(pageFetcherFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,15 @@ class RegionBitmapDecoder(
inPreferredConfig = config
}

class Factory : Decoder.Factory {
object Factory : Decoder.Factory {

private val parallelismLock = Semaphore(DEFAULT_PARALLELISM)

override fun create(
result: SourceResult,
options: Options,
imageLoader: ImageLoader
): Decoder? = if (options.parameters.value<Boolean>(PARAM_REGION) == true) {
RegionBitmapDecoder(result.source, options, parallelismLock)
} else {
null
}
): Decoder = RegionBitmapDecoder(result.source, options, parallelismLock)

override fun equals(other: Any?) = other is Factory

Expand All @@ -151,7 +147,6 @@ class RegionBitmapDecoder(
companion object {

const val PARAM_SCROLL = "scroll"
const val PARAM_REGION = "region"
const val SCROLL_UNDEFINED = -1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun ImageRequest.Builder.indicator(indicators: List<BaseProgressIndicator<*>>):

fun ImageRequest.Builder.decodeRegion(
scroll: Int = RegionBitmapDecoder.SCROLL_UNDEFINED,
): ImageRequest.Builder = setParameter(RegionBitmapDecoder.PARAM_REGION, true)
): ImageRequest.Builder = decoderFactory(RegionBitmapDecoder.Factory)
.setParameter(RegionBitmapDecoder.PARAM_SCROLL, scroll)

@Suppress("SpellCheckingInspection")
Expand Down

0 comments on commit 681c80d

Please sign in to comment.