[RU]Remanga User's mangalist (#10428)

* [RU]Remanga User's mangalist

* worked filter

* Exception
This commit is contained in:
e-shl 2022-01-11 17:53:37 +05:00 committed by GitHub
parent 4851bad1d6
commit 3614bfb738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 9 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Remanga' extName = 'Remanga'
pkgNameSuffix = 'ru.remanga' pkgNameSuffix = 'ru.remanga'
extClass = '.Remanga' extClass = '.Remanga'
extVersionCode = 41 extVersionCode = 42
} }
dependencies { dependencies {

View File

@ -5,6 +5,7 @@ import BranchesDto
import ChunksPageDto import ChunksPageDto
import LibraryDto import LibraryDto
import MangaDetDto import MangaDetDto
import MyLibraryDto
import PageDto import PageDto
import PageWrapperDto import PageWrapperDto
import SeriesWrapperDto import SeriesWrapperDto
@ -115,10 +116,11 @@ class Remanga : ConfigurableSource, HttpSource() {
val body = jsonObject.toString().toRequestBody(MEDIA_TYPE) val body = jsonObject.toString().toRequestBody(MEDIA_TYPE)
val response = chain.proceed(POST("$baseUrl/api/users/login/", headers, body)) val response = chain.proceed(POST("$baseUrl/api/users/login/", headers, body))
if (response.code >= 400) { if (response.code >= 400) {
throw Exception("Failed to login") throw Exception("Не удалось войти")
} }
val user = json.decodeFromString<SeriesWrapperDto<UserDto>>(response.body!!.string()) val user = json.decodeFromString<SeriesWrapperDto<UserDto>>(response.body!!.string()).content
return user.content.access_token USER_ID = user.id.toString()
return user.access_token
} }
override fun popularMangaRequest(page: Int) = GET("$baseUrl/api/search/catalog/?ordering=-rating&count=$count&page=$page", headers) override fun popularMangaRequest(page: Int) = GET("$baseUrl/api/search/catalog/?ordering=-rating&count=$count&page=$page", headers)
@ -130,12 +132,20 @@ class Remanga : ConfigurableSource, HttpSource() {
override fun latestUpdatesParse(response: Response): MangasPage = searchMangaParse(response) override fun latestUpdatesParse(response: Response): MangasPage = searchMangaParse(response)
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
if (response.request.url.toString().contains("bookmarks")) {
val page = json.decodeFromString<PageWrapperDto<MyLibraryDto>>(response.body!!.string())
val mangas = page.content.map {
it.title.toSManga()
}
return MangasPage(mangas, page.props.page < page.props.total_pages)
} else {
val page = json.decodeFromString<PageWrapperDto<LibraryDto>>(response.body!!.string()) val page = json.decodeFromString<PageWrapperDto<LibraryDto>>(response.body!!.string())
val mangas = page.content.map { val mangas = page.content.map {
it.toSManga() it.toSManga()
} }
return MangasPage(mangas, page.props.page < page.props.total_pages) return MangasPage(mangas, page.props.page < page.props.total_pages)
} }
}
private fun LibraryDto.toSManga(): SManga = private fun LibraryDto.toSManga(): SManga =
SManga.create().apply { SManga.create().apply {
@ -195,6 +205,16 @@ class Remanga : ConfigurableSource, HttpSource() {
url.addQueryParameter(if (genre.isIncluded()) "genres" else "exclude_genres", genre.id) url.addQueryParameter(if (genre.isIncluded()) "genres" else "exclude_genres", genre.id)
} }
} }
is MyList -> {
if (filter.state > 0) {
if (USER_ID == "") {
throw Exception("Пользователь не найден")
}
val TypeQ = getMyList()[filter.state].id
val UserProfileUrl = "$baseUrl/api/users/$USER_ID/bookmarks/?type=$TypeQ&page=$page".toHttpUrlOrNull()!!.newBuilder()
return GET(UserProfileUrl.toString(), headers)
}
}
} }
} }
return GET(url.toString(), headers) return GET(url.toString(), headers)
@ -427,7 +447,8 @@ class Remanga : ConfigurableSource, HttpSource() {
CategoryList(getCategoryList()), CategoryList(getCategoryList()),
TypeList(getTypeList()), TypeList(getTypeList()),
StatusList(getStatusList()), StatusList(getStatusList()),
AgeList(getAgeList()) AgeList(getAgeList()),
MyList(MyStatus)
) )
private class OrderBy : Filter.Sort( private class OrderBy : Filter.Sort(
@ -607,6 +628,21 @@ class Remanga : ConfigurableSource, HttpSource() {
SearchFilter("юри", "41"), SearchFilter("юри", "41"),
SearchFilter("яой", "43") SearchFilter("яой", "43")
) )
private class MyList(favorites: Array<String>) : Filter.Select<String>("Мои списки (только)", favorites)
private data class MyListUnit(val name: String, val id: String)
private val MyStatus = getMyList().map {
it.name
}.toTypedArray()
private fun getMyList() = listOf(
MyListUnit("Каталог", "-"),
MyListUnit("Читаю", "0"),
MyListUnit("Буду читать", "1"),
MyListUnit("Прочитано", "2"),
MyListUnit("Отложено", "4"),
MyListUnit("Брошено ", "3"),
MyListUnit("Не интересно ", "5")
)
private fun androidx.preference.PreferenceScreen.editTextPreference(title: String, default: String, value: String, isPassword: Boolean = false): androidx.preference.EditTextPreference { private fun androidx.preference.PreferenceScreen.editTextPreference(title: String, default: String, value: String, isPassword: Boolean = false): androidx.preference.EditTextPreference {
return androidx.preference.EditTextPreference(context).apply { return androidx.preference.EditTextPreference(context).apply {
@ -679,6 +715,8 @@ class Remanga : ConfigurableSource, HttpSource() {
private val password by lazy { getPrefPassword() } private val password by lazy { getPrefPassword() }
companion object { companion object {
private var USER_ID = ""
private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull() private val MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull()
private const val USERNAME_TITLE = "Username" private const val USERNAME_TITLE = "Username"

View File

@ -27,6 +27,10 @@ data class LibraryDto(
val dir: String, val dir: String,
val img: ImgDto val img: ImgDto
) )
@Serializable
data class MyLibraryDto(
val title: LibraryDto
)
@Serializable @Serializable
data class StatusDto( data class StatusDto(
@ -109,5 +113,6 @@ data class ChunksPageDto(
@Serializable @Serializable
data class UserDto( data class UserDto(
val id: Long,
val access_token: String val access_token: String
) )