Tapas - filter future releases (#3090)

Tapas - filter future releases
This commit is contained in:
Mike 2020-05-09 21:40:53 -04:00 committed by GitHub
parent 4285114a03
commit 806227b5bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 10 deletions

View File

@ -5,13 +5,14 @@ ext {
appName = 'Tachiyomi: Tapas'
pkgNameSuffix = 'en.tapastic'
extClass = '.Tapastic'
extVersionCode = 7
extVersionCode = 8
libVersion = '1.2'
}
dependencies {
compileOnly 'com.google.code.gson:gson:2.8.2'
compileOnly 'com.github.salomonbrys.kotson:kotson:2.5.0'
compileOnly 'com.github.inorichi.injekt:injekt-core:65b0440'
}
apply from: "$rootDir/common.gradle"

View File

@ -1,7 +1,12 @@
package eu.kanade.tachiyomi.extension.en.tapastic
import android.app.Application
import android.content.SharedPreferences
import android.net.Uri
import android.support.v7.preference.ListPreference
import android.support.v7.preference.PreferenceScreen
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.Page
@ -15,14 +20,68 @@ 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
class Tapastic : ParsedHttpSource() {
class Tapastic : ConfigurableSource, ParsedHttpSource() {
// Preferences Code
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
val chapterListPref = androidx.preference.ListPreference(screen.context).apply {
key = SHOW_LOCKED_CHAPTERS_Title
title = SHOW_LOCKED_CHAPTERS_Title
entries = prefsEntries
entryValues = prefsEntryValues
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = this.findIndexOfValue(selected)
val entry = entryValues.get(index) as String
preferences.edit().putString(SHOW_LOCKED_CHAPTERS, entry).commit()
}
}
screen.addPreference(chapterListPref)
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val chapterListPref = ListPreference(screen.context).apply {
key = SHOW_LOCKED_CHAPTERS_Title
title = SHOW_LOCKED_CHAPTERS_Title
entries = prefsEntries
entryValues = prefsEntryValues
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = this.findIndexOfValue(selected)
val entry = entryValues.get(index) as String
preferences.edit().putString(SHOW_LOCKED_CHAPTERS, entry).commit()
}
}
screen.addPreference(chapterListPref)
}
private fun chapterListPref() = preferences.getString(SHOW_LOCKED_CHAPTERS, "free")
companion object {
private const val SHOW_LOCKED_CHAPTERS_Title = "Show or don't show future/locked chapters"
private const val SHOW_LOCKED_CHAPTERS = "tapas_locked_chapters"
private val prefsEntries = arrayOf("Show All", "Show free/currently available")
private val prefsEntryValues = arrayOf("all", "free")
}
// Info
override val lang = "en"
override val supportsLatest = true
override val name = "Tapastic"
override val name = "Tapas" // originally Tapastic
override val baseUrl = "https://tapas.io"
override val id = 3825434541981130345
// Popular
@ -76,12 +135,7 @@ class Tapastic : ParsedHttpSource() {
override fun searchMangaSelector() = "${popularMangaSelector()}, .search-item-wrap"
override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply {
url = element.select(".item__thumb a, .title-section .title a").attr("href")
val browseTitle = element.select(".item__thumb img")
title = if (browseTitle != null) {
browseTitle.attr("alt")
} else {
element.select(".title-section .title a").text()
}
title = element.select(".item__thumb img").firstOrNull()?.attr("alt") ?: element.select(".title-section .title a").text()
thumbnail_url = element.select(".item__thumb img, .thumb-wrap img").attr("src")
}
@ -117,7 +171,8 @@ class Tapastic : ParsedHttpSource() {
return chapters
}
override fun chapterListSelector() = "li.content__item"
// filter future releases based on user's configuration
override fun chapterListSelector() = "li.content__item" + if (chapterListPref() == "free") ":not(:has(.info__tag):contains(release date))" else ""
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
val lock = !element.select(".sp-ico-episode-lock, .sp-ico-schedule-white").isNullOrEmpty()
name = if (lock) {