[RU]NewManga optional show paid chapters (#13324)

This commit is contained in:
Yjin 2022-09-02 23:48:27 +05:00 committed by GitHub
parent 5a90cbf361
commit 2821450458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 8 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'NewManga(Newbie)' extName = 'NewManga(Newbie)'
pkgNameSuffix = 'ru.newbie' pkgNameSuffix = 'ru.newbie'
extClass = '.Newbie' extClass = '.Newbie'
extVersionCode = 10 extVersionCode = 11
} }
dependencies { dependencies {

View File

@ -12,10 +12,13 @@ import SeriesWrapperDto
import SubSearchDto import SubSearchDto
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.Application
import android.content.SharedPreferences
import android.os.Build import android.os.Build
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.network.asObservableSuccess 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.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.MangasPage
@ -36,13 +39,15 @@ import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody import okhttp3.ResponseBody.Companion.toResponseBody
import org.jsoup.Jsoup import org.jsoup.Jsoup
import rx.Observable import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
class Newbie : HttpSource() { class Newbie : ConfigurableSource, HttpSource() {
override val name = "NewManga(Newbie)" override val name = "NewManga(Newbie)"
override val id: Long = 8033757373676218584 override val id: Long = 8033757373676218584
@ -51,6 +56,10 @@ class Newbie : HttpSource() {
override val lang = "ru" override val lang = "ru"
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val supportsLatest = true override val supportsLatest = true
private var branches = mutableMapOf<String, List<BranchesDto>>() private var branches = mutableMapOf<String, List<BranchesDto>>()
@ -278,6 +287,8 @@ class Newbie : HttpSource() {
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
private fun chapterName(book: BookDto): String { private fun chapterName(book: BookDto): String {
var chapterName = "${book.tom}. Глава ${DecimalFormat("#,###.##").format(book.number).replace(",", ".")}" var chapterName = "${book.tom}. Глава ${DecimalFormat("#,###.##").format(book.number).replace(",", ".")}"
if (!book.is_available)
chapterName += " \uD83D\uDCB2 "
if (book.name?.isNotBlank() == true) { if (book.name?.isNotBlank() == true) {
chapterName += " ${book.name.capitalize()}" chapterName += " ${book.name.capitalize()}"
} }
@ -313,10 +324,11 @@ class Newbie : HttpSource() {
} }
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val body = response.body!!.string() var chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(response.body!!.string()).items
val chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(body) if (!preferences.getBoolean(PAID_PREF, false)) {
chapters = chapters.filter { it.is_available }
return chapters.items.filter { it.is_available }.map { chapter -> }
return chapters.map { chapter ->
SChapter.create().apply { SChapter.create().apply {
chapter_number = chapter.number chapter_number = chapter.number
name = chapterName(chapter) name = chapterName(chapter)
@ -340,8 +352,7 @@ class Newbie : HttpSource() {
} }
private fun pageListParse(response: Response, chapter: SChapter): List<Page> { private fun pageListParse(response: Response, chapter: SChapter): List<Page> {
val body = response.body?.string()!! val pages = json.decodeFromString<List<PageDto>>(response.body?.string()!!)
val pages = json.decodeFromString<List<PageDto>>(body)
val result = mutableListOf<Page>() val result = mutableListOf<Page>()
pages.forEach { page -> pages.forEach { page ->
(1..page.slices!!).map { i -> (1..page.slices!!).map { i ->
@ -607,9 +618,27 @@ class Newbie : HttpSource() {
CheckFilter("18+", "ADULT_18") CheckFilter("18+", "ADULT_18")
) )
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
val paidChapterShow = androidx.preference.CheckBoxPreference(screen.context).apply {
key = PAID_PREF
title = PAID_PREF_Title
summary = "Показывает не купленные\uD83D\uDCB2 главы(может вызвать ошибки при обновлении/автозагрузке)"
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
val checkValue = newValue as Boolean
preferences.edit().putBoolean(key, checkValue).commit()
}
}
screen.addPreference(paidChapterShow)
}
companion object { companion object {
private const val API_URL = "https://api.newmanga.org/v2" private const val API_URL = "https://api.newmanga.org/v2"
private const val IMAGE_URL = "https://storage.newmanga.org" private const val IMAGE_URL = "https://storage.newmanga.org"
private const val PAID_PREF = "PaidChapter"
private const val PAID_PREF_Title = "Показывать платные главы"
} }
private val json: Json by injectLazy() private val json: Json by injectLazy()