diff --git a/src/es/tumangaonline/build.gradle b/src/es/tumangaonline/build.gradle index da5f4800d..beeb5b6c5 100755 --- a/src/es/tumangaonline/build.gradle +++ b/src/es/tumangaonline/build.gradle @@ -5,12 +5,14 @@ ext { appName = 'Tachiyomi: TuMangaOnline' pkgNameSuffix = 'es.tumangaonline' extClass = '.TuMangaOnline' - extVersionCode = 10 + extVersionCode = 11 libVersion = '1.2' } dependencies { implementation project(':lib-ratelimit') + compileOnly project(':preference-stub') + compileOnly 'com.github.inorichi.injekt:injekt-core:65b0440' } apply from: "$rootDir/common.gradle" diff --git a/src/es/tumangaonline/src/eu/kanade/tachiyomi/extension/es/tumangaonline/TuMangaOnline.kt b/src/es/tumangaonline/src/eu/kanade/tachiyomi/extension/es/tumangaonline/TuMangaOnline.kt index 9dd40d92d..363a4c588 100755 --- a/src/es/tumangaonline/src/eu/kanade/tachiyomi/extension/es/tumangaonline/TuMangaOnline.kt +++ b/src/es/tumangaonline/src/eu/kanade/tachiyomi/extension/es/tumangaonline/TuMangaOnline.kt @@ -1,5 +1,9 @@ package eu.kanade.tachiyomi.extension.es.tumangaonline +import android.app.Application +import android.content.SharedPreferences +import android.support.v7.preference.ListPreference +import android.support.v7.preference.PreferenceScreen import okhttp3.* import java.util.* import org.jsoup.nodes.Element @@ -11,8 +15,11 @@ import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor +import eu.kanade.tachiyomi.source.ConfigurableSource +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get -class TuMangaOnline : ParsedHttpSource() { +class TuMangaOnline : ConfigurableSource, ParsedHttpSource() { override val name = "TuMangaOnline" @@ -52,6 +59,10 @@ class TuMangaOnline : ParsedHttpSource() { .toString() } + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + override fun popularMangaSelector() = "div.element" override fun latestUpdatesSelector() = "div.upload-file-row" @@ -195,7 +206,14 @@ class TuMangaOnline : ParsedHttpSource() { document.select(regularChapterListSelector()).forEach { chapelement -> val chapternumber = chapelement.select("a.btn-collapse").text().substringBefore(":").substringAfter("CapĂ­tulo").trim().toFloat() val chaptername = chapelement.select("div.col-10.text-truncate").text() - chapelement.select("ul.chapter-list > li").forEach { chapters.add(regularChapterFromElement(it, chaptername, chapternumber)) } + val scanelement = chapelement.select("ul.chapter-list > li") + val dupselect = getduppref()!! + if (dupselect=="one") { + scanelement.first { chapters.add(regularChapterFromElement(it, chaptername, chapternumber)) } + } + else { + scanelement.forEach { chapters.add(regularChapterFromElement(it, chaptername, chapternumber)) } + } } return chapters } @@ -364,4 +382,30 @@ class TuMangaOnline : ParsedHttpSource() { Filter.Select(displayName, vals.map { it.first }.toTypedArray()) { fun toUriPart() = vals[state].second } + + // Preferences Code + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val deduppref = ListPreference(screen.context).apply { + key = DEDUP_PREF_Title + title = DEDUP_PREF_Title + entries = arrayOf("All scanlators", "One scanlator per chapter") + entryValues = arrayOf("all", "one") + summary = "%s" + + setOnPreferenceChangeListener { _, newValue -> + val selected = newValue as String + val index = this.findIndexOfValue(selected) + val entry = entryValues.get(index) as String + preferences.edit().putString(DEDUP_PREF, entry).commit() + } + } + screen.addPreference(deduppref) + } + + private fun getduppref() = preferences.getString(DEDUP_PREF, "all") + + companion object { + private const val DEDUP_PREF_Title = "Chapter List Scanlator Preference" + private const val DEDUP_PREF = "deduppref" + } }