parent
86cac8697b
commit
d37e61728b
|
@ -5,7 +5,7 @@ ext {
|
|||
appName = 'Tachiyomi: MyReadingManga'
|
||||
pkgNameSuffix = 'all.myreadingmanga'
|
||||
extClass = '.MyReadingMangaFactory'
|
||||
extVersionCode = 24
|
||||
extVersionCode = 25
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
package eu.kanade.tachiyomi.extension.all.myreadingmanga
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.source.model.*
|
||||
|
@ -69,11 +68,20 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
|
|||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
|
||||
val query2 = URLEncoder.encode(query, "UTF-8")
|
||||
val uri = Uri.parse("$baseUrl/search/").buildUpon()
|
||||
val uri = if (query.isNotBlank()) {
|
||||
Uri.parse("$baseUrl/search/").buildUpon()
|
||||
.appendEncodedPath(query2)
|
||||
.appendPath("page")
|
||||
.appendPath("$page")
|
||||
return GET(uri.toString())
|
||||
} else {
|
||||
val uri = Uri.parse("$baseUrl/").buildUpon()
|
||||
//Append uri filters
|
||||
filters.forEach {
|
||||
if (it is UriFilter)
|
||||
it.addToUri(uri)
|
||||
}
|
||||
uri
|
||||
}
|
||||
uri.appendPath("page").appendPath("$page")
|
||||
return GET(uri.toString(), headers)
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,4 +190,60 @@ open class MyReadingManga(override val lang: String) : ParsedHttpSource() {
|
|||
override fun imageUrlRequest(page: Page) = throw Exception("Not used")
|
||||
override fun imageUrlParse(document: Document) = throw Exception("Not used")
|
||||
|
||||
//Filter Parsing, grabs home page as document and filters out Genres, Popular Tags, and Catagorys
|
||||
private val filterdoc = OkHttpClient().newCall(GET("$baseUrl", headers)).execute().asJsoup()
|
||||
private val genresarray = filterdoc.select(".tagcloud a[href*=/genre/]").map { Pair(it.attr("href").substringBeforeLast("/").substringAfterLast("/"), it.text())}.toTypedArray()
|
||||
private val poptagarray = filterdoc.select(".tagcloud a[href*=/tag/]").map { Pair(it.attr("href").substringBeforeLast("/").substringAfterLast("/"), it.text())}.toTypedArray()
|
||||
private val cattagarray = filterdoc.select(".level-0").map { Pair(it.attr("value"), it.text())}.toTypedArray()
|
||||
|
||||
//Generates the filter lists for app
|
||||
override fun getFilterList(): FilterList {
|
||||
val filterList = FilterList(
|
||||
//MRM does not support genre filtering and text search at the same time
|
||||
Filter.Header("NOTE: Filters are ignored if using text search."),
|
||||
Filter.Header("Only one filter can be used at a time."),
|
||||
GenreFilter(genresarray),
|
||||
TagFilter(poptagarray),
|
||||
CatFilter(cattagarray)
|
||||
)
|
||||
return filterList
|
||||
}
|
||||
|
||||
private class GenreFilter(GENRES: Array<Pair<String, String>>) : UriSelectFilterPath("Genre", "genre", arrayOf(Pair("","Any"),*GENRES))
|
||||
private class TagFilter(POPTAG: Array<Pair<String, String>>) : UriSelectFilterPath("Popular Tags", "tag", arrayOf(Pair("","Any"),*POPTAG))
|
||||
private class CatFilter(CATID: Array<Pair<String, String>>) : UriSelectFilterQuery("Categories", "cat", arrayOf(Pair("","Any"), *CATID))
|
||||
|
||||
/**
|
||||
* Class that creates a select filter. Each entry in the dropdown has a name and a display name.
|
||||
* If an entry is selected it is appended as a query parameter onto the end of the URI.
|
||||
* If `firstIsUnspecified` is set to true, if the first entry is selected, nothing will be appended on the the URI.
|
||||
*/
|
||||
//vals: <name, display>
|
||||
private open class UriSelectFilterPath(displayName: String, val uriParam: String, val vals: Array<Pair<String, String>>,
|
||||
val firstIsUnspecified: Boolean = true,
|
||||
defaultValue: Int = 0) :
|
||||
Filter.Select<String>(displayName, vals.map { it.second }.toTypedArray(), defaultValue), UriFilter {
|
||||
override fun addToUri(uri: Uri.Builder) {
|
||||
if (state != 0 || !firstIsUnspecified)
|
||||
uri.appendPath(uriParam)
|
||||
.appendPath(vals[state].first)
|
||||
}
|
||||
}
|
||||
private open class UriSelectFilterQuery(displayName: String, val uriParam: String, val vals: Array<Pair<String, String>>,
|
||||
val firstIsUnspecified: Boolean = true,
|
||||
defaultValue: Int = 0) :
|
||||
Filter.Select<String>(displayName, vals.map { it.second }.toTypedArray(), defaultValue), UriFilter {
|
||||
override fun addToUri(uri: Uri.Builder) {
|
||||
if (state != 0 || !firstIsUnspecified)
|
||||
uri.appendQueryParameter(uriParam, vals[state].first)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a filter that is able to modify a URI.
|
||||
*/
|
||||
private interface UriFilter {
|
||||
fun addToUri(uri: Uri.Builder)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue