Manga parsers unit tests
This commit is contained in:
@@ -4,14 +4,26 @@ import android.content.Context
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
|
||||
class SourceConfig(context: Context, source: MangaSource) {
|
||||
interface SourceConfig {
|
||||
|
||||
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
|
||||
fun getDomain(defaultValue: String): String
|
||||
|
||||
private val keyDomain = context.getString(R.string.key_parser_domain)
|
||||
private class PrefSourceConfig(context: Context, source: MangaSource) : SourceConfig {
|
||||
|
||||
fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue)
|
||||
?.takeUnless(String::isBlank)
|
||||
?: defaultValue
|
||||
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
|
||||
|
||||
private val keyDomain = context.getString(R.string.key_parser_domain)
|
||||
|
||||
override fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue)
|
||||
?.takeUnless(String::isBlank)
|
||||
?: defaultValue
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
operator fun invoke(context: Context, source: MangaSource): SourceConfig =
|
||||
PrefSourceConfig(context, source)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.prefs.SourceConfig
|
||||
import org.koitharu.kotatsu.utils.ext.await
|
||||
|
||||
class MangaLoaderContext : KoinComponent {
|
||||
open class MangaLoaderContext : KoinComponent {
|
||||
|
||||
private val okHttp by inject<OkHttpClient>()
|
||||
|
||||
@@ -43,5 +43,5 @@ class MangaLoaderContext : KoinComponent {
|
||||
return okHttp.newCall(request.build()).await()
|
||||
}
|
||||
|
||||
fun getSettings(source: MangaSource) = SourceConfig(get(), source)
|
||||
open fun getSettings(source: MangaSource) = SourceConfig(get(), source)
|
||||
}
|
||||
Reference in New Issue
Block a user