diff --git a/src/en/readcomiconline/build.gradle b/src/en/readcomiconline/build.gradle index 30d90f927..2c98f535a 100644 --- a/src/en/readcomiconline/build.gradle +++ b/src/en/readcomiconline/build.gradle @@ -5,8 +5,13 @@ ext { appName = 'Tachiyomi: ReadComicOnline' pkgNameSuffix = 'en.readcomiconline' extClass = '.Readcomiconline' - extVersionCode = 5 + extVersionCode = 6 libVersion = '1.2' } +dependencies { + compileOnly project(':preference-stub') + compileOnly 'com.github.inorichi.injekt:injekt-core:65b0440' +} + apply from: "$rootDir/common.gradle" diff --git a/src/en/readcomiconline/src/eu/kanade/tachiyomi/extension/en/readcomiconline/Readcomiconline.kt b/src/en/readcomiconline/src/eu/kanade/tachiyomi/extension/en/readcomiconline/Readcomiconline.kt index 5960136cd..be02105f5 100644 --- a/src/en/readcomiconline/src/eu/kanade/tachiyomi/extension/en/readcomiconline/Readcomiconline.kt +++ b/src/en/readcomiconline/src/eu/kanade/tachiyomi/extension/en/readcomiconline/Readcomiconline.kt @@ -1,7 +1,13 @@ package eu.kanade.tachiyomi.extension.en.readcomiconline +import android.app.Application +import android.content.SharedPreferences +import android.support.v7.preference.ListPreference +import android.support.v7.preference.PreferenceScreen +import android.util.Log import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST +import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.FormBody @@ -10,10 +16,12 @@ import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.regex.Pattern -class Readcomiconline : ParsedHttpSource() { +class Readcomiconline : ConfigurableSource, ParsedHttpSource() { override val name = "ReadComicOnline" @@ -25,6 +33,10 @@ class Readcomiconline : ParsedHttpSource() { override val client: OkHttpClient = network.cloudflareClient + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + override fun popularMangaSelector() = "table.listing tr:gt(1)" override fun latestUpdatesSelector() = "table.listing tr:gt(1)" @@ -34,7 +46,7 @@ class Readcomiconline : ParsedHttpSource() { } override fun latestUpdatesRequest(page: Int): Request { - return GET("https://readcomiconline.to/ComicList/LatestUpdate?page=$page", headers) + return GET("$baseUrl/ComicList/LatestUpdate?page=$page", headers) } override fun popularMangaFromElement(element: Element): SManga { @@ -110,7 +122,7 @@ class Readcomiconline : ParsedHttpSource() { return chapter } - override fun pageListRequest(chapter: SChapter) = POST(baseUrl + chapter.url+"&quality=hq", headers) + override fun pageListRequest(chapter: SChapter) = GET(baseUrl + chapter.url + "&quality=${qualitypref()}", headers) override fun pageListParse(response: Response): List { val pages = mutableListOf() @@ -194,4 +206,50 @@ class Readcomiconline : ParsedHttpSource() { Genre("Western"), Genre("Zombies") ) + // Preferences Code + + override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { + val qualitypref = androidx.preference.ListPreference(screen.context).apply { + key = QUALITY_PREF_Title + title = QUALITY_PREF_Title + entries = arrayOf("High Quality", "Low Quality") + entryValues = arrayOf("hq", "lq") + summary = "%s" + + setOnPreferenceChangeListener { _, newValue -> + val selected = newValue as String + val index = this.findIndexOfValue(selected) + val entry = entryValues.get(index) as String + preferences.edit().putString(QUALITY_PREF, entry).commit() + } + } + screen.addPreference(qualitypref) + } + + + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val qualitypref = ListPreference(screen.context).apply { + key = QUALITY_PREF_Title + title = QUALITY_PREF_Title + entries = arrayOf("High Quality", "Low Quality") + entryValues = arrayOf("hq", "lq") + summary = "%s" + + setOnPreferenceChangeListener { _, newValue -> + val selected = newValue as String + val index = this.findIndexOfValue(selected) + val entry = entryValues.get(index) as String + preferences.edit().putString(QUALITY_PREF, entry).commit() + } + } + screen.addPreference(qualitypref) + } + + private fun qualitypref() = preferences.getString(QUALITY_PREF, "hq") + + companion object { + private const val QUALITY_PREF_Title = "Image Quality Selector" + private const val QUALITY_PREF = "qualitypref" + } }