better sorting filter; let user adjust description
This commit is contained in:
parent
95a9c98d31
commit
d70fe1af45
2 changed files with 66 additions and 29 deletions
|
@ -5,6 +5,7 @@ import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
|
import androidx.preference.MultiSelectListPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
||||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||||
|
@ -31,7 +32,7 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
private const val SEARCH_PAGE_SIZE = 20
|
private const val PAGE_SIZE = 20
|
||||||
private val MOVIE_ID_PATTERN = Pattern.compile("""data-movie-id=\\"(\d+)\\"""", Pattern.MULTILINE)
|
private val MOVIE_ID_PATTERN = Pattern.compile("""data-movie-id=\\"(\d+)\\"""", Pattern.MULTILINE)
|
||||||
|
|
||||||
class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
|
@ -63,7 +64,7 @@ class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
private val latestSection = preferences.getString("LATEST", PREF_SECTIONS["Latest"])!!
|
private val latestSection = preferences.getString("LATEST", PREF_SECTIONS["Latest"])!!
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int): Request {
|
override fun latestUpdatesRequest(page: Int): Request {
|
||||||
val offset = (page - 1) * SEARCH_PAGE_SIZE
|
val offset = (page - 1) * PAGE_SIZE
|
||||||
return GET("$baseUrl/$latestSection?offset=$offset", headers)
|
return GET("$baseUrl/$latestSection?offset=$offset", headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
private val popularSection = preferences.getString("POPULAR", PREF_SECTIONS["Popular"])!!
|
private val popularSection = preferences.getString("POPULAR", PREF_SECTIONS["Popular"])!!
|
||||||
|
|
||||||
override fun popularAnimeRequest(page: Int): Request {
|
override fun popularAnimeRequest(page: Int): Request {
|
||||||
val offset = (page - 1) * SEARCH_PAGE_SIZE
|
val offset = (page - 1) * PAGE_SIZE
|
||||||
return GET("$baseUrl/$popularSection?offset=$offset", headers)
|
return GET("$baseUrl/$popularSection?offset=$offset", headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,11 +147,15 @@ class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
?.findInstance<BeforeDateFilter>().ifFilterSet {
|
?.findInstance<BeforeDateFilter>().ifFilterSet {
|
||||||
searchUrl.addQueryParameter("before", it.state)
|
searchUrl.addQueryParameter("before", it.state)
|
||||||
}
|
}
|
||||||
// filters.findInstance<RatingFilter>().ifFilterSet {
|
|
||||||
// searchUrl.addQueryParameter("", "")
|
|
||||||
// }
|
|
||||||
filters.findInstance<SortingFilter>().ifFilterSet {
|
filters.findInstance<SortingFilter>().ifFilterSet {
|
||||||
searchUrl.addQueryParameter("sort", SORTING.values.elementAt(it.state))
|
if (it.state?.index != 0) {
|
||||||
|
val sortOption = SORTING.values.elementAt(it.state?.index ?: return@ifFilterSet)
|
||||||
|
val direction = if (it.state?.ascending == true) "asc" else "desc"
|
||||||
|
searchUrl.addQueryParameter(
|
||||||
|
"sort",
|
||||||
|
"$sortOption-$direction",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
filters.findInstance<TagsFilter>().ifFilterSet {
|
filters.findInstance<TagsFilter>().ifFilterSet {
|
||||||
searchUrl.addQueryParameter("tags", it.state)
|
searchUrl.addQueryParameter("tags", it.state)
|
||||||
|
@ -203,13 +208,34 @@ class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
return "👀 $views | ❤️ $faves | 👍 $votes"
|
return "👀 $views | ❤️ $faves | 👍 $votes"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun prepareDescription(): String {
|
||||||
|
val descriptionElements = preferences.getStringSet("DESCRIPTION_ELEMENTS", setOf("short"))
|
||||||
|
?: return ""
|
||||||
|
|
||||||
|
val shortDescription = document.selectFirst("meta[itemprop=\"description\"]")?.attr("content")
|
||||||
|
val longDescription = document.selectFirst("#author_comments")?.wholeText()
|
||||||
|
val statsSummary = "${getAdultRating()} | ${getStarRating()} | ${getStats()}"
|
||||||
|
|
||||||
|
val description = StringBuilder()
|
||||||
|
|
||||||
|
if (descriptionElements.contains("short")) {
|
||||||
|
description.append(shortDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptionElements.contains("long")) {
|
||||||
|
description.append("\n\n" + longDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptionElements.contains("stats") || preferences.getBoolean("STATS_SUMMARY", false)) {
|
||||||
|
description.append("\n\n" + statsSummary)
|
||||||
|
}
|
||||||
|
|
||||||
|
return description.toString()
|
||||||
|
}
|
||||||
|
|
||||||
return SAnime.create().apply {
|
return SAnime.create().apply {
|
||||||
title = document.selectFirst("h2[itemprop=\"name\"]")!!.text()
|
title = document.selectFirst("h2[itemprop=\"name\"]")!!.text()
|
||||||
description = """
|
description = prepareDescription()
|
||||||
${document.selectFirst("meta[itemprop=\"description\"]")?.attr("content")}
|
|
||||||
|
|
||||||
${getAdultRating()} | ${getStarRating()} | ${getStats()}
|
|
||||||
""".trimIndent()
|
|
||||||
author = document.selectFirst(".authorlinks > div:first-of-type .item-details-main")?.text()
|
author = document.selectFirst(".authorlinks > div:first-of-type .item-details-main")?.text()
|
||||||
artist = document.select(".authorlinks > div:not(:first-of-type) .item-details-main").joinToString {
|
artist = document.select(".authorlinks > div:not(:first-of-type) .item-details-main").joinToString {
|
||||||
it.text()
|
it.text()
|
||||||
|
@ -290,16 +316,17 @@ class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
// ============================== Filters ===============================
|
// ============================== Filters ===============================
|
||||||
|
|
||||||
override fun getFilterList(): AnimeFilterList = AnimeFilterList(
|
override fun getFilterList(): AnimeFilterList = AnimeFilterList(
|
||||||
|
SortingFilter(),
|
||||||
MatchAgainstFilter(),
|
MatchAgainstFilter(),
|
||||||
TuningFilterGroup(),
|
TuningFilterGroup(),
|
||||||
AuthorFilter(),
|
|
||||||
GenreFilter(),
|
GenreFilter(),
|
||||||
LengthFilterGroup(),
|
AuthorFilter(),
|
||||||
FrontpagedFilter(),
|
|
||||||
DateFilterGroup(),
|
|
||||||
TagsFilter(),
|
TagsFilter(),
|
||||||
// RatingFilter(),
|
LengthFilterGroup(),
|
||||||
SortingFilter(),
|
DateFilterGroup(),
|
||||||
|
FrontpagedFilter(),
|
||||||
|
AnimeFilter.Separator(),
|
||||||
|
AnimeFilter.Header("Age rating: to change age rating open WebView and in Movies tab click on 🟩🟦🟪🟥 icons on the right. Then refresh search."), // uses ng_user0 cookie
|
||||||
)
|
)
|
||||||
|
|
||||||
// ============================ Preferences =============================
|
// ============================ Preferences =============================
|
||||||
|
@ -342,6 +369,21 @@ class NewGrounds : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
preferences.edit().putString(key, selected).commit()
|
preferences.edit().putString(key, selected).commit()
|
||||||
}
|
}
|
||||||
}.also(screen::addPreference)
|
}.also(screen::addPreference)
|
||||||
|
|
||||||
|
MultiSelectListPreference(screen.context).apply {
|
||||||
|
key = "DESCRIPTION_ELEMENTS"
|
||||||
|
title = "Description elements"
|
||||||
|
entries = arrayOf("Short description", "Long description (author comments)", "Stats (score, favs, views)")
|
||||||
|
entryValues = arrayOf("short", "long", "stats")
|
||||||
|
setDefaultValue(setOf("short", "stats"))
|
||||||
|
summary = "Elements to be included in description"
|
||||||
|
|
||||||
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
val selectedItems = newValue as Set<*>
|
||||||
|
preferences.edit().putStringSet(key, selectedItems as Set<String>).apply()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}.also(screen::addPreference)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================== Helper Functions ==========================
|
// ========================== Helper Functions ==========================
|
||||||
|
|
|
@ -40,9 +40,8 @@ class DateFilterGroup : AnimeFilter.Group<AnimeFilter.Text>(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
// class RatingFilter() : AnimeFilter.Select<String>("Ratings (unused)", arrayOf("Everyone", "Ages 13+", "Ages 17+", "Adults Only"), 0)
|
// class SortingFilter() : AnimeFilter.Select<String>("Sort by", SORTING.keys.toTypedArray())
|
||||||
|
class SortingFilter() : AnimeFilter.Sort("Sort by", SORTING.keys.toTypedArray(), Selection(0, true))
|
||||||
class SortingFilter() : AnimeFilter.Select<String>("Sort by", SORTING.keys.toTypedArray())
|
|
||||||
|
|
||||||
class TagsFilter() : AnimeFilter.Text("Tags (comma separated)")
|
class TagsFilter() : AnimeFilter.Text("Tags (comma separated)")
|
||||||
|
|
||||||
|
@ -70,12 +69,8 @@ val GENRE = mapOf(
|
||||||
)
|
)
|
||||||
|
|
||||||
val SORTING = mapOf(
|
val SORTING = mapOf(
|
||||||
"Default" to "",
|
"Default (Relevance)" to "relevance",
|
||||||
"Relevance" to "relevance",
|
"Date" to "date",
|
||||||
"Date (Descending)" to "date-desc",
|
"Score" to "score",
|
||||||
"Date (Ascending)" to "date-asc",
|
"Views" to "views",
|
||||||
"Score (Descending)" to "score-desc",
|
|
||||||
"Score (Ascending)" to "score-asc",
|
|
||||||
"Views (Descending)" to "views-desc",
|
|
||||||
"Views (Ascending)" to "views-asc",
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue