feat: combined queries
This commit is contained in:
parent
51beac2d03
commit
c0bccc027f
3 changed files with 62 additions and 73 deletions
|
@ -1022,43 +1022,53 @@ query (${"$"}page: Int = 1, ${"$"}id: Int, ${"$"}type: MediaType, ${"$"}isAdult:
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
private fun trendingMovie(): String{
|
private val onListAnime = (if(PrefManager.getVal(PrefName.IncludeAnimeList)) "" else "onList:false").replace("\"", "")
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: ANIME, format: MOVIE){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
private val isAdult = (if (PrefManager.getVal(PrefName.AdultOnly)) "isAdult:true" else "").replace("\"", "")
|
||||||
|
private fun recentAnimeUpdates(): String{
|
||||||
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}airingSchedules(airingAt_greater:0 airingAt_lesser:${System.currentTimeMillis() / 1000 - 10000} sort:TIME_DESC){episode airingAt media{id idMal status chapters episodes nextAiringEpisode{episode} isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large} title{english romaji userPreferred} mediaListEntry{progress private score(format:POINT_100) status}}}}"""
|
||||||
|
}
|
||||||
|
private fun trendingMovies(): String{
|
||||||
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: ANIME, format: MOVIE, $onListAnime, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
private fun topRatedAnime(): String{
|
private fun topRatedAnime(): String{
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort: SCORE_DESC, type: ANIME){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort: SCORE_DESC, type: ANIME, $onListAnime, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
private fun mostFavAnime(): String{
|
private fun mostFavAnime(): String{
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:FAVOURITES_DESC,type: ANIME){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:FAVOURITES_DESC,type: ANIME, $onListAnime, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
suspend fun loadAnimeList(): Query.AnimeList?{
|
suspend fun loadAnimeList(): Query.AnimeList?{
|
||||||
return executeQuery<Query.AnimeList>(
|
return executeQuery<Query.AnimeList>(
|
||||||
"""{
|
"""{
|
||||||
trendingMovie:${trendingMovie()}
|
recentUpdates:${recentAnimeUpdates()}
|
||||||
|
trendingMovies:${trendingMovies()}
|
||||||
topRated:${topRatedAnime()}
|
topRated:${topRatedAnime()}
|
||||||
mostFav:${mostFavAnime()}
|
mostFav:${mostFavAnime()}
|
||||||
}""".trimIndent(), force = true
|
}""".trimIndent(), force = true
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private val onListManga = (if(PrefManager.getVal(PrefName.IncludeMangaList)) "" else "onList:false").replace("\"", "")
|
||||||
private fun trendingManga(): String{
|
private fun trendingManga(): String{
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: MANGA,countryOfOrigin:JP){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: MANGA,countryOfOrigin:JP, $onListManga, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
private fun trendingManhwa(): String{
|
private fun trendingManhwa(): String{
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: MANGA, countryOfOrigin:KR){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: MANGA, countryOfOrigin:KR, $onListManga, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
|
}
|
||||||
|
private fun trendingNovel(): String{
|
||||||
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:POPULARITY_DESC, type: MANGA, format: NOVEL, countryOfOrigin:JP, $onListManga, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
private fun topRatedManga(): String{
|
private fun topRatedManga(): String{
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort: SCORE_DESC, type: MANGA){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort: SCORE_DESC, type: MANGA, $onListManga, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
private fun mostFavManga(): String{
|
private fun mostFavManga(): String{
|
||||||
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:FAVOURITES_DESC,type: MANGA){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
return """Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:FAVOURITES_DESC,type: MANGA, $onListManga, $isAdult){id idMal status chapters episodes nextAiringEpisode{episode}isAdult type meanScore isFavourite format bannerImage countryOfOrigin coverImage{large}title{english romaji userPreferred}mediaListEntry{progress private score(format:POINT_100)status}}}"""
|
||||||
}
|
}
|
||||||
suspend fun loadMangaList(): Query.MangaList?{
|
suspend fun loadMangaList(): Query.MangaList?{
|
||||||
return executeQuery<Query.MangaList>(
|
return executeQuery<Query.MangaList>(
|
||||||
"""{
|
"""{
|
||||||
trendingManga:${trendingManga()}
|
trendingManga:${trendingManga()}
|
||||||
trendingManhwa:${trendingManhwa()}
|
trendingManhwa:${trendingManhwa()}
|
||||||
|
trendingNovel:${trendingNovel()}
|
||||||
topRated:${topRatedManga()}
|
topRated:${topRatedManga()}
|
||||||
mostFav:${mostFavManga()}
|
mostFav:${mostFavManga()}
|
||||||
}""".trimIndent(), force = true
|
}""".trimIndent(), force = true
|
||||||
|
@ -1066,7 +1076,6 @@ query (${"$"}page: Int = 1, ${"$"}id: Int, ${"$"}type: MediaType, ${"$"}isAdult:
|
||||||
|
|
||||||
}
|
}
|
||||||
suspend fun recentlyUpdated(
|
suspend fun recentlyUpdated(
|
||||||
smaller: Boolean = true,
|
|
||||||
greater: Long = 0,
|
greater: Long = 0,
|
||||||
lesser: Long = System.currentTimeMillis() / 1000 - 10000
|
lesser: Long = System.currentTimeMillis() / 1000 - 10000
|
||||||
): MutableList<Media>? {
|
): MutableList<Media>? {
|
||||||
|
@ -1116,21 +1125,6 @@ Page(page:$page,perPage:50) {
|
||||||
}""".replace("\n", " ").replace(""" """, "")
|
}""".replace("\n", " ").replace(""" """, "")
|
||||||
return executeQuery<Query.Page>(query, force = true)?.data?.page
|
return executeQuery<Query.Page>(query, force = true)?.data?.page
|
||||||
}
|
}
|
||||||
if (smaller) {
|
|
||||||
val response = execute()?.airingSchedules ?: return null
|
|
||||||
val idArr = mutableListOf<Int>()
|
|
||||||
val listOnly: Boolean = PrefManager.getVal(PrefName.RecentlyListOnly)
|
|
||||||
return response.mapNotNull { i ->
|
|
||||||
i.media?.let {
|
|
||||||
if (!idArr.contains(it.id))
|
|
||||||
if (!listOnly && (it.countryOfOrigin == "JP" && (if (!Anilist.adult) it.isAdult == false else true)) || (listOnly && it.mediaListEntry != null)) {
|
|
||||||
idArr.add(it.id)
|
|
||||||
Media(it)
|
|
||||||
} else null
|
|
||||||
else null
|
|
||||||
}
|
|
||||||
}.toMutableList()
|
|
||||||
} else {
|
|
||||||
var i = 1
|
var i = 1
|
||||||
val list = mutableListOf<Media>()
|
val list = mutableListOf<Media>()
|
||||||
var res: Page? = null
|
var res: Page? = null
|
||||||
|
@ -1150,7 +1144,6 @@ Page(page:$page,perPage:50) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return list.reversed().toMutableList()
|
return list.reversed().toMutableList()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getCharacterDetails(character: Character): Character {
|
suspend fun getCharacterDetails(character: Character): Character {
|
||||||
|
|
|
@ -149,11 +149,6 @@ class AnilistAnimeViewModel : ViewModel() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val updated: MutableLiveData<MutableList<Media>> =
|
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
|
||||||
|
|
||||||
fun getUpdated(): LiveData<MutableList<Media>> = updated
|
|
||||||
suspend fun loadUpdated() = updated.postValue(Anilist.query.recentlyUpdated())
|
|
||||||
|
|
||||||
private val animePopular = MutableLiveData<SearchResults?>(null)
|
private val animePopular = MutableLiveData<SearchResults?>(null)
|
||||||
|
|
||||||
|
@ -193,29 +188,41 @@ class AnilistAnimeViewModel : ViewModel() {
|
||||||
)
|
)
|
||||||
|
|
||||||
var loaded: Boolean = false
|
var loaded: Boolean = false
|
||||||
|
private val updated: MutableLiveData<MutableList<Media>> =
|
||||||
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
|
fun getUpdated(): LiveData<MutableList<Media>> = updated
|
||||||
|
|
||||||
private val popularMovies: MutableLiveData<MutableList<Media>> =
|
private val popularMovies: MutableLiveData<MutableList<Media>> =
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
fun getMovies(): LiveData<MutableList<Media>> = popularMovies
|
fun getMovies(): LiveData<MutableList<Media>> = popularMovies
|
||||||
|
|
||||||
private val topRated: MutableLiveData<MutableList<Media>> =
|
private val topRatedAnime: MutableLiveData<MutableList<Media>> =
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
fun getTopRated(): LiveData<MutableList<Media>> = topRated
|
fun getTopRated(): LiveData<MutableList<Media>> = topRatedAnime
|
||||||
|
|
||||||
private val mostFav: MutableLiveData<MutableList<Media>> =
|
private val mostFavAnime: MutableLiveData<MutableList<Media>> =
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
fun getMostFav(): LiveData<MutableList<Media>> = mostFav
|
fun getMostFav(): LiveData<MutableList<Media>> = mostFavAnime
|
||||||
suspend fun loadAll() {
|
suspend fun loadAll() {
|
||||||
val response = Anilist.query.loadAnimeList()
|
val res = Anilist.query.loadAnimeList()?.data
|
||||||
|
|
||||||
val trendingMovie = response?.data?.trendingMovie?.media?.map { Media(it) }?.toMutableList()
|
val listOnly: Boolean = PrefManager.getVal(PrefName.RecentlyListOnly)
|
||||||
popularMovies.postValue(trendingMovie ?: arrayListOf())
|
|
||||||
|
|
||||||
val topRatedList = response?.data?.topRated?.media?.map { Media(it) }?.toMutableList()
|
res?.apply{
|
||||||
topRated.postValue(topRatedList ?: arrayListOf())
|
updated.postValue(recentUpdates?.airingSchedules?.mapNotNull {i ->
|
||||||
|
i.media?.let {
|
||||||
|
if (!listOnly && (it.countryOfOrigin == "JP" && (if (!Anilist.adult) it.isAdult == false else true)) || (listOnly && it.mediaListEntry != null)){
|
||||||
|
Media(it)
|
||||||
|
}else{
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}?.toMutableList() ?: arrayListOf())
|
||||||
|
popularMovies.postValue(trendingMovies?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
|
topRatedAnime.postValue(topRated?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
|
mostFavAnime.postValue(mostFav?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
|
}
|
||||||
|
|
||||||
val mostFavList = response?.data?.mostFav?.media?.map { Media(it) }?.toMutableList()
|
|
||||||
mostFav.postValue(mostFavList ?: arrayListOf())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,19 +245,6 @@ class AnilistMangaViewModel : ViewModel() {
|
||||||
)?.results
|
)?.results
|
||||||
)
|
)
|
||||||
|
|
||||||
private val updated: MutableLiveData<MutableList<Media>> =
|
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
|
||||||
|
|
||||||
fun getTrendingNovel(): LiveData<MutableList<Media>> = updated
|
|
||||||
suspend fun loadTrendingNovel() =
|
|
||||||
updated.postValue(
|
|
||||||
Anilist.query.search(
|
|
||||||
type,
|
|
||||||
perPage = 10,
|
|
||||||
sort = Anilist.sortBy[2],
|
|
||||||
format = "NOVEL"
|
|
||||||
)?.results
|
|
||||||
)
|
|
||||||
|
|
||||||
private val mangaPopular = MutableLiveData<SearchResults?>(null)
|
private val mangaPopular = MutableLiveData<SearchResults?>(null)
|
||||||
fun getPopular(): LiveData<SearchResults?> = mangaPopular
|
fun getPopular(): LiveData<SearchResults?> = mangaPopular
|
||||||
|
@ -302,27 +296,27 @@ class AnilistMangaViewModel : ViewModel() {
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
fun getPopularManhwa(): LiveData<MutableList<Media>> = popularManhwa
|
fun getPopularManhwa(): LiveData<MutableList<Media>> = popularManhwa
|
||||||
|
|
||||||
private val topRated: MutableLiveData<MutableList<Media>> =
|
private val popularNovel: MutableLiveData<MutableList<Media>> =
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
fun getTopRated(): LiveData<MutableList<Media>> = topRated
|
fun getPopularNovel(): LiveData<MutableList<Media>> = popularNovel
|
||||||
|
|
||||||
private val mostFav: MutableLiveData<MutableList<Media>> =
|
private val topRatedManga: MutableLiveData<MutableList<Media>> =
|
||||||
MutableLiveData<MutableList<Media>>(null)
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
fun getMostFav(): LiveData<MutableList<Media>> = mostFav
|
fun getTopRated(): LiveData<MutableList<Media>> = topRatedManga
|
||||||
|
|
||||||
|
private val mostFavManga: MutableLiveData<MutableList<Media>> =
|
||||||
|
MutableLiveData<MutableList<Media>>(null)
|
||||||
|
fun getMostFav(): LiveData<MutableList<Media>> = mostFavManga
|
||||||
suspend fun loadAll() {
|
suspend fun loadAll() {
|
||||||
val response = Anilist.query.loadMangaList()
|
val response = Anilist.query.loadMangaList()?.data
|
||||||
|
|
||||||
val trendingManga = response?.data?.trendingManga?.media?.map { Media(it) }?.toMutableList()
|
response?.apply {
|
||||||
popularManga.postValue(trendingManga ?: arrayListOf())
|
popularManga.postValue(trendingManga?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
|
popularManhwa.postValue(trendingManhwa?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
val trendingManhwa = response?.data?.trendingManhwa?.media?.map { Media(it) }?.toMutableList()
|
popularNovel.postValue(trendingNovel?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
popularManhwa.postValue(trendingManhwa ?: arrayListOf())
|
topRatedManga.postValue(topRated?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
|
mostFavManga.postValue(mostFav?.media?.map { Media(it) }?.toMutableList() ?: arrayListOf())
|
||||||
val topRatedList = response?.data?.topRated?.media?.map { Media(it) }?.toMutableList()
|
}
|
||||||
topRated.postValue(topRatedList ?: arrayListOf())
|
|
||||||
|
|
||||||
val mostFavList = response?.data?.mostFav?.media?.map { Media(it) }?.toMutableList()
|
|
||||||
mostFav.postValue(mostFavList ?: arrayListOf())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,8 @@ class Query {
|
||||||
) {
|
) {
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Data(
|
data class Data(
|
||||||
@SerialName("trendingMovie") val trendingMovie: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("recentUpdates") val recentUpdates: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
|
@SerialName("trendingMovies") val trendingMovies: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
@SerialName("topRated") val topRated: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("topRated") val topRated: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
@SerialName("mostFav") val mostFav: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("mostFav") val mostFav: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
)
|
)
|
||||||
|
@ -173,6 +174,7 @@ class Query {
|
||||||
data class Data(
|
data class Data(
|
||||||
@SerialName("trendingManga") val trendingManga: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("trendingManga") val trendingManga: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
@SerialName("trendingManhwa") val trendingManhwa: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("trendingManhwa") val trendingManhwa: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
|
@SerialName("trendingNovel") val trendingNovel: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
@SerialName("topRated") val topRated: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("topRated") val topRated: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
@SerialName("mostFav") val mostFav: ani.dantotsu.connections.anilist.api.Page?,
|
@SerialName("mostFav") val mostFav: ani.dantotsu.connections.anilist.api.Page?,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue