nsfw true added in query param (#4051)

* nsfw fix

* nsfw preference added

* extension version changed from 5 to 6
This commit is contained in:
balagurusurendar 2020-08-09 00:54:26 +05:30 committed by GitHub
parent 2824b6c2cf
commit 980a8d2162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 9 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'ReadManhwa'
pkgNameSuffix = 'en.readmanhwa'
extClass = '.ReadManhwa'
extVersionCode = 5
extVersionCode = 6
libVersion = '1.2'
}

View File

@ -1,5 +1,9 @@
package eu.kanade.tachiyomi.extension.en.readmanhwa
import android.app.Application
import android.content.SharedPreferences
import android.support.v7.preference.CheckBoxPreference
import android.support.v7.preference.PreferenceScreen
import com.github.salomonbrys.kotson.fromJson
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int
@ -10,6 +14,7 @@ import com.google.gson.JsonArray
import com.google.gson.JsonObject
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
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.MangasPage
@ -26,8 +31,10 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class ReadManhwa : HttpSource() {
class ReadManhwa : ConfigurableSource, HttpSource() {
override val name = "ReadManhwa"
@ -43,6 +50,10 @@ class ReadManhwa : HttpSource() {
.add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")
.add("X-NSFW", enableNsfw.toString())
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val client: OkHttpClient = network.cloudflareClient
private val gson = Gson()
@ -60,11 +71,15 @@ class ReadManhwa : HttpSource() {
return MangasPage(mangas, jsonObject["current_page"].int < jsonObject["last_page"].int)
}
private fun getMangaUrl(url: String): String {
return HttpUrl.parse(url)!!.newBuilder()
.setQueryParameter("nsfw", isNSFWEnabledInPref().toString()).toString()
}
// Popular
override fun popularMangaRequest(page: Int): Request {
return GET("$baseUrl/api/comics?page=$page&q=&sort=popularity&order=desc&duration=week", headers)
return GET(getMangaUrl("$baseUrl/api/comics?page=$page&q=&sort=popularity&order=desc&duration=week"), headers)
}
override fun popularMangaParse(response: Response): MangasPage = parseMangaFromJson(response)
@ -72,7 +87,7 @@ class ReadManhwa : HttpSource() {
// Latest
override fun latestUpdatesRequest(page: Int): Request {
return GET("$baseUrl/api/comics?page=$page&q=&sort=uploaded_at&order=desc&duration=day", headers)
return GET(getMangaUrl("$baseUrl/api/comics?page=$page&q=&sort=uploaded_at&order=desc&duration=day"), headers)
}
override fun latestUpdatesParse(response: Response): MangasPage = parseMangaFromJson(response)
@ -87,6 +102,7 @@ class ReadManhwa : HttpSource() {
.addQueryParameter("page", page.toString())
.addQueryParameter("order", "desc")
.addQueryParameter("q", query)
.addQueryParameter("nsfw", enableNsfw.toString())
filters.forEach { filter ->
when (filter) {
@ -108,10 +124,10 @@ class ReadManhwa : HttpSource() {
.map { mangaDetailsParse(it).apply { initialized = true } }
// Return the real URL for "Open in browser"
override fun mangaDetailsRequest(manga: SManga) = GET("$baseUrl/en/webtoon/${manga.url}", headers)
override fun mangaDetailsRequest(manga: SManga) = GET(getMangaUrl("$baseUrl/en/webtoon/${manga.url}"), headers)
private fun apiMangaDetailsRequest(manga: SManga): Request {
return GET("$baseUrl/api/comics/${manga.url}", headers)
return GET(getMangaUrl("$baseUrl/api/comics/${manga.url}"), headers)
}
override fun mangaDetailsParse(response: Response): SManga {
@ -145,7 +161,7 @@ class ReadManhwa : HttpSource() {
}
override fun chapterListRequest(manga: SManga): Request {
return GET("$baseUrl/api/comics/${manga.url}/chapters", headers)
return GET(getMangaUrl("$baseUrl/api/comics/${manga.url}/chapters"), headers)
}
private fun chapterListParse(response: Response, titleSlug: String): List<SChapter> {
@ -177,7 +193,7 @@ class ReadManhwa : HttpSource() {
// Pages
override fun pageListRequest(chapter: SChapter): Request {
return GET("$baseUrl/api/comics/${chapter.url}/images", headers)
return GET(getMangaUrl("$baseUrl/api/comics/${chapter.url}/images"), headers)
}
override fun pageListParse(response: Response): List<Page> {
@ -191,7 +207,7 @@ class ReadManhwa : HttpSource() {
// Filters
override fun getFilterList() = FilterList(
NSFWFilter(),
NSFWFilter().apply { state = isNSFWEnabledInPref() },
GenreFilter(getGenreList()),
DurationFilter(getDurationList()),
SortFilter(getSortList())
@ -279,4 +295,42 @@ class ReadManhwa : HttpSource() {
Pair("Popularity", "popularity"),
Pair("Date", "uploaded_at")
)
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val nsfw = CheckBoxPreference(screen.context).apply {
key = NSFW
title = NSFW_TITLE
setDefaultValue(NSFW_DEFAULT)
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as Boolean
preferences.edit().putBoolean(NSFW, selected).commit()
}
}
screen.addPreference(nsfw)
}
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
val nsfw = androidx.preference.CheckBoxPreference(screen.context).apply {
key = NSFW
title = NSFW_TITLE
setDefaultValue(NSFW_DEFAULT)
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as Boolean
preferences.edit().putBoolean(NSFW, selected).commit()
}
}
screen.addPreference(nsfw)
}
private fun isNSFWEnabledInPref(): Boolean {
return preferences.getBoolean(NSFW, NSFW_DEFAULT)
}
companion object {
private const val NSFW = "NSFW"
private const val NSFW_TITLE = "Show NSFW"
private const val NSFW_DEFAULT = true
}
}