Add Mangadex blocked groups and uploaders extension preference support
This commit is contained in:
parent
ffcb5f6954
commit
2eef81c468
@ -95,6 +95,8 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
|
|
||||||
private fun dataSaver() = sourcePreferences.getBoolean(getDataSaverPreferenceKey(mdLang.lang), false)
|
private fun dataSaver() = sourcePreferences.getBoolean(getDataSaverPreferenceKey(mdLang.lang), false)
|
||||||
private fun usePort443Only() = sourcePreferences.getBoolean(getStandardHttpsPreferenceKey(mdLang.lang), false)
|
private fun usePort443Only() = sourcePreferences.getBoolean(getStandardHttpsPreferenceKey(mdLang.lang), false)
|
||||||
|
private fun blockedGroups() = sourcePreferences.getString(getBlockedGroupsPrefKey(mdLang.lang), "").orEmpty()
|
||||||
|
private fun blockedUploaders() = sourcePreferences.getString(getBlockedGroupsPrefKey(mdLang.lang), "").orEmpty()
|
||||||
|
|
||||||
private val mangadexService by lazy {
|
private val mangadexService by lazy {
|
||||||
MangaDexService(client)
|
MangaDexService(client)
|
||||||
@ -187,11 +189,11 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
||||||
return mangaHandler.fetchChapterListObservable(manga)
|
return mangaHandler.fetchChapterListObservable(manga, blockedGroups(), blockedUploaders())
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
|
override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
|
||||||
return mangaHandler.getChapterList(manga)
|
return mangaHandler.getChapterList(manga, blockedGroups(), blockedUploaders())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
||||||
@ -316,5 +318,17 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
fun getStandardHttpsPreferenceKey(dexLang: String): String {
|
fun getStandardHttpsPreferenceKey(dexLang: String): String {
|
||||||
return "${standardHttpsPortPref}_$dexLang"
|
return "${standardHttpsPortPref}_$dexLang"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val blockedGroupsPref = "blockedGroups"
|
||||||
|
|
||||||
|
fun getBlockedGroupsPrefKey(dexLang: String): String {
|
||||||
|
return "${blockedGroupsPref}_$dexLang"
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val blockedUploaderPref = "blockedUploader"
|
||||||
|
|
||||||
|
fun getBlockedUploaderPrefKey(dexLang: String): String {
|
||||||
|
return "${blockedUploaderPref}_$dexLang"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,20 @@ class MangaHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchChapterListObservable(manga: SManga): Observable<List<SChapter>> = runAsObservable {
|
fun fetchChapterListObservable(manga: SManga, blockedGroups: String, blockedUploaders: String): Observable<List<SChapter>> = runAsObservable {
|
||||||
getChapterList(manga.toMangaInfo()).map { it.toSChapter() }
|
getChapterList(manga.toMangaInfo(), blockedGroups, blockedUploaders).map { it.toSChapter() }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
|
suspend fun getChapterList(manga: MangaInfo, blockedGroups: String, blockedUploaders: String): List<ChapterInfo> {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val results = mdListCall {
|
val results = mdListCall {
|
||||||
service.viewChapters(MdUtil.getMangaId(manga.key), lang, it)
|
service.viewChapters(
|
||||||
|
MdUtil.getMangaId(manga.key),
|
||||||
|
lang,
|
||||||
|
it,
|
||||||
|
blockedGroups,
|
||||||
|
blockedUploaders
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val groupMap = getGroupMap(results)
|
val groupMap = getGroupMap(results)
|
||||||
|
@ -17,6 +17,8 @@ import exh.md.dto.StatisticsDto
|
|||||||
import exh.md.utils.MdApi
|
import exh.md.utils.MdApi
|
||||||
import exh.md.utils.MdConstants
|
import exh.md.utils.MdConstants
|
||||||
import exh.md.utils.MdUtil
|
import exh.md.utils.MdUtil
|
||||||
|
import exh.util.dropEmpty
|
||||||
|
import exh.util.trimAll
|
||||||
import okhttp3.CacheControl
|
import okhttp3.CacheControl
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
@ -106,10 +108,14 @@ class MangaDexService(
|
|||||||
).await().parseAs(MdUtil.jsonParser)
|
).await().parseAs(MdUtil.jsonParser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.splitString() = replace("\n", "").split(',').trimAll().dropEmpty()
|
||||||
|
|
||||||
suspend fun viewChapters(
|
suspend fun viewChapters(
|
||||||
id: String,
|
id: String,
|
||||||
translatedLanguage: String,
|
translatedLanguage: String,
|
||||||
offset: Int,
|
offset: Int,
|
||||||
|
blockedGroups: String,
|
||||||
|
blockedUploaders: String
|
||||||
): ChapterListDto {
|
): ChapterListDto {
|
||||||
val url = MdApi.manga.toHttpUrl()
|
val url = MdApi.manga.toHttpUrl()
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
@ -126,6 +132,12 @@ class MangaDexService(
|
|||||||
addQueryParameter("contentRating[]", "pornographic")
|
addQueryParameter("contentRating[]", "pornographic")
|
||||||
addQueryParameter("translatedLanguage[]", translatedLanguage)
|
addQueryParameter("translatedLanguage[]", translatedLanguage)
|
||||||
addQueryParameter("offset", offset.toString())
|
addQueryParameter("offset", offset.toString())
|
||||||
|
blockedGroups.splitString().forEach {
|
||||||
|
addQueryParameter("excludedGroups[]", it)
|
||||||
|
}
|
||||||
|
blockedUploaders.splitString().forEach {
|
||||||
|
addQueryParameter("excludedUploaders[]", it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
.toString()
|
.toString()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user