feat: lil faster home screen? idk tbh
This commit is contained in:
parent
46d16be835
commit
f62bdf9360
4 changed files with 243 additions and 276 deletions
|
@ -313,7 +313,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
mainViewPager.adapter =
|
mainViewPager.adapter =
|
||||||
ViewPagerAdapter(supportFragmentManager, lifecycle)
|
ViewPagerAdapter(supportFragmentManager, lifecycle)
|
||||||
mainViewPager.setPageTransformer(ZoomOutPageTransformer())
|
mainViewPager.setPageTransformer(ZoomOutPageTransformer())
|
||||||
mainViewPager.offscreenPageLimit = 1
|
|
||||||
navbar.selectTabAt(selectedOption)
|
navbar.selectTabAt(selectedOption)
|
||||||
navbar.setOnTabSelectListener(object :
|
navbar.setOnTabSelectListener(object :
|
||||||
AnimatedBottomBar.OnTabSelectListener {
|
AnimatedBottomBar.OnTabSelectListener {
|
||||||
|
|
|
@ -6,14 +6,14 @@ import ani.dantotsu.checkGenreTime
|
||||||
import ani.dantotsu.checkId
|
import ani.dantotsu.checkId
|
||||||
import ani.dantotsu.connections.anilist.Anilist.authorRoles
|
import ani.dantotsu.connections.anilist.Anilist.authorRoles
|
||||||
import ani.dantotsu.connections.anilist.Anilist.executeQuery
|
import ani.dantotsu.connections.anilist.Anilist.executeQuery
|
||||||
import ani.dantotsu.connections.anilist.api.Activity
|
|
||||||
import ani.dantotsu.connections.anilist.api.FeedResponse
|
import ani.dantotsu.connections.anilist.api.FeedResponse
|
||||||
import ani.dantotsu.connections.anilist.api.FuzzyDate
|
import ani.dantotsu.connections.anilist.api.FuzzyDate
|
||||||
|
import ani.dantotsu.connections.anilist.api.MediaEdge
|
||||||
|
import ani.dantotsu.connections.anilist.api.MediaList
|
||||||
import ani.dantotsu.connections.anilist.api.NotificationResponse
|
import ani.dantotsu.connections.anilist.api.NotificationResponse
|
||||||
import ani.dantotsu.connections.anilist.api.Page
|
import ani.dantotsu.connections.anilist.api.Page
|
||||||
import ani.dantotsu.connections.anilist.api.Query
|
import ani.dantotsu.connections.anilist.api.Query
|
||||||
import ani.dantotsu.connections.anilist.api.ReplyResponse
|
import ani.dantotsu.connections.anilist.api.ReplyResponse
|
||||||
import ani.dantotsu.connections.anilist.api.ToggleLike
|
|
||||||
import ani.dantotsu.currContext
|
import ani.dantotsu.currContext
|
||||||
import ani.dantotsu.isOnline
|
import ani.dantotsu.isOnline
|
||||||
import ani.dantotsu.logError
|
import ani.dantotsu.logError
|
||||||
|
@ -28,6 +28,7 @@ import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.snackString
|
import ani.dantotsu.snackString
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
@ -422,9 +423,7 @@ class AnilistQueries {
|
||||||
val toShow: List<Boolean> =
|
val toShow: List<Boolean> =
|
||||||
PrefManager.getVal(PrefName.HomeLayout)
|
PrefManager.getVal(PrefName.HomeLayout)
|
||||||
if (toShow.getOrNull(7) != true) return null
|
if (toShow.getOrNull(7) != true) return null
|
||||||
var query = """{"""
|
val query = """{Page1:${status(1)}Page2:${status(2)}}"""
|
||||||
query += "Page1:${status(1)}Page2:${status(2)}"
|
|
||||||
query += """}""".trimEnd(',')
|
|
||||||
val response = executeQuery<Query.HomePageMedia>(query, show = true)
|
val response = executeQuery<Query.HomePageMedia>(query, show = true)
|
||||||
val list = mutableListOf<User>()
|
val list = mutableListOf<User>()
|
||||||
val threeDaysAgo = Calendar.getInstance().apply {
|
val threeDaysAgo = Calendar.getInstance().apply {
|
||||||
|
@ -461,8 +460,9 @@ class AnilistQueries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anilistActivities.isEmpty() && Anilist.token != null){
|
if (anilistActivities.isEmpty() && Anilist.token != null) {
|
||||||
anilistActivities.add(0,
|
anilistActivities.add(
|
||||||
|
0,
|
||||||
User(
|
User(
|
||||||
Anilist.userid!!,
|
Anilist.userid!!,
|
||||||
Anilist.username!!,
|
Anilist.username!!,
|
||||||
|
@ -477,206 +477,176 @@ class AnilistQueries {
|
||||||
} else return null
|
} else return null
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun initHomePage(): Map<String, ArrayList<*>> {
|
suspend fun initHomePage(): Map<String, ArrayList<Media>> {
|
||||||
val removeList = PrefManager.getCustomVal("removeList", setOf<Int>())
|
val removeList = PrefManager.getCustomVal("removeList", setOf<Int>())
|
||||||
val hidePrivate = PrefManager.getVal<Boolean>(PrefName.HidePrivate)
|
val hidePrivate = PrefManager.getVal<Boolean>(PrefName.HidePrivate)
|
||||||
val removedMedia = ArrayList<Media>()
|
val removedMedia = ArrayList<Media>()
|
||||||
val toShow: List<Boolean> =
|
val toShow: List<Boolean> =
|
||||||
PrefManager.getVal(PrefName.HomeLayout) // anime continue, anime fav, anime planned, manga continue, manga fav, manga planned, recommendations
|
PrefManager.getVal(PrefName.HomeLayout) // list of booleans for what to show
|
||||||
var query = """{"""
|
|
||||||
if (toShow.getOrNull(0) == true) query += """currentAnime: ${
|
|
||||||
continueMediaQuery(
|
|
||||||
"ANIME",
|
|
||||||
"CURRENT"
|
|
||||||
)
|
|
||||||
}, repeatingAnime: ${continueMediaQuery("ANIME", "REPEATING")}"""
|
|
||||||
if (toShow.getOrNull(1) == true) query += """favoriteAnime: ${favMediaQuery(true, 1)}"""
|
|
||||||
if (toShow.getOrNull(2) == true) query += """plannedAnime: ${
|
|
||||||
continueMediaQuery(
|
|
||||||
"ANIME",
|
|
||||||
"PLANNING"
|
|
||||||
)
|
|
||||||
}"""
|
|
||||||
if (toShow.getOrNull(3) == true) query += """currentManga: ${
|
|
||||||
continueMediaQuery(
|
|
||||||
"MANGA",
|
|
||||||
"CURRENT"
|
|
||||||
)
|
|
||||||
}, repeatingManga: ${continueMediaQuery("MANGA", "REPEATING")}"""
|
|
||||||
if (toShow.getOrNull(4) == true) query += """favoriteManga: ${favMediaQuery(false, 1)}"""
|
|
||||||
if (toShow.getOrNull(5) == true) query += """plannedManga: ${
|
|
||||||
continueMediaQuery(
|
|
||||||
"MANGA",
|
|
||||||
"PLANNING"
|
|
||||||
)
|
|
||||||
}"""
|
|
||||||
if (toShow.getOrNull(6) == true) query += """recommendationQuery: ${recommendationQuery()}, recommendationPlannedQueryAnime: ${
|
|
||||||
recommendationPlannedQuery(
|
|
||||||
"ANIME"
|
|
||||||
)
|
|
||||||
}, recommendationPlannedQueryManga: ${recommendationPlannedQuery("MANGA")}"""
|
|
||||||
query += """}""".trimEnd(',')
|
|
||||||
|
|
||||||
|
val queries = mutableListOf<String>()
|
||||||
|
if (toShow.getOrNull(0) == true) {
|
||||||
|
queries.add("""currentAnime: ${continueMediaQuery("ANIME", "CURRENT")}""")
|
||||||
|
queries.add("""repeatingAnime: ${continueMediaQuery("ANIME", "REPEATING")}""")
|
||||||
|
}
|
||||||
|
if (toShow.getOrNull(1) == true) queries.add("""favoriteAnime: ${favMediaQuery(true, 1)}""")
|
||||||
|
if (toShow.getOrNull(2) == true) queries.add(
|
||||||
|
"""plannedAnime: ${
|
||||||
|
continueMediaQuery(
|
||||||
|
"ANIME",
|
||||||
|
"PLANNING"
|
||||||
|
)
|
||||||
|
}"""
|
||||||
|
)
|
||||||
|
if (toShow.getOrNull(3) == true) {
|
||||||
|
queries.add("""currentManga: ${continueMediaQuery("MANGA", "CURRENT")}""")
|
||||||
|
queries.add("""repeatingManga: ${continueMediaQuery("MANGA", "REPEATING")}""")
|
||||||
|
}
|
||||||
|
if (toShow.getOrNull(4) == true) queries.add(
|
||||||
|
"""favoriteManga: ${
|
||||||
|
favMediaQuery(
|
||||||
|
false,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
}"""
|
||||||
|
)
|
||||||
|
if (toShow.getOrNull(5) == true) queries.add(
|
||||||
|
"""plannedManga: ${
|
||||||
|
continueMediaQuery(
|
||||||
|
"MANGA",
|
||||||
|
"PLANNING"
|
||||||
|
)
|
||||||
|
}"""
|
||||||
|
)
|
||||||
|
if (toShow.getOrNull(6) == true) {
|
||||||
|
queries.add("""recommendationQuery: ${recommendationQuery()}""")
|
||||||
|
queries.add("""recommendationPlannedQueryAnime: ${recommendationPlannedQuery("ANIME")}""")
|
||||||
|
queries.add("""recommendationPlannedQueryManga: ${recommendationPlannedQuery("MANGA")}""")
|
||||||
|
}
|
||||||
|
|
||||||
|
val query = "{${queries.joinToString(",")}}"
|
||||||
val response = executeQuery<Query.HomePageMedia>(query, show = true)
|
val response = executeQuery<Query.HomePageMedia>(query, show = true)
|
||||||
val returnMap = mutableMapOf<String, ArrayList<*>>()
|
val returnMap = mutableMapOf<String, ArrayList<Media>>()
|
||||||
fun current(type: String) {
|
|
||||||
|
fun processMedia(
|
||||||
|
type: String,
|
||||||
|
currentMedia: List<MediaList>?,
|
||||||
|
repeatingMedia: List<MediaList>?
|
||||||
|
) {
|
||||||
val subMap = mutableMapOf<Int, Media>()
|
val subMap = mutableMapOf<Int, Media>()
|
||||||
val returnArray = arrayListOf<Media>()
|
val returnArray = arrayListOf<Media>()
|
||||||
val current =
|
|
||||||
if (type == "Anime") response?.data?.currentAnime else response?.data?.currentManga
|
(currentMedia ?: emptyList()).forEach { entry ->
|
||||||
val repeating =
|
val media = Media(entry)
|
||||||
if (type == "Anime") response?.data?.repeatingAnime else response?.data?.repeatingManga
|
if (media.id !in removeList && (!hidePrivate || !media.isListPrivate)) {
|
||||||
current?.lists?.forEach { li ->
|
media.cameFromContinue = true
|
||||||
li.entries?.reversed()?.forEach {
|
subMap[media.id] = media
|
||||||
val m = Media(it)
|
} else {
|
||||||
if (m.id !in removeList && if (hidePrivate) !m.isListPrivate else true) {
|
removedMedia.add(media)
|
||||||
m.cameFromContinue = true
|
|
||||||
subMap[m.id] = m
|
|
||||||
} else {
|
|
||||||
removedMedia.add(m)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repeating?.lists?.forEach { li ->
|
(repeatingMedia ?: emptyList()).forEach { entry ->
|
||||||
li.entries?.reversed()?.forEach {
|
val media = Media(entry)
|
||||||
val m = Media(it)
|
if (media.id !in removeList && (!hidePrivate || !media.isListPrivate)) {
|
||||||
if (m.id !in removeList && if (hidePrivate) !m.isListPrivate else true) {
|
media.cameFromContinue = true
|
||||||
m.cameFromContinue = true
|
subMap[media.id] = media
|
||||||
subMap[m.id] = m
|
} else {
|
||||||
} else {
|
removedMedia.add(media)
|
||||||
removedMedia.add(m)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type != "Anime") {
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val list = PrefManager.getNullableCustomVal(
|
||||||
|
"continue${type}List",
|
||||||
|
listOf<Int>(),
|
||||||
|
List::class.java
|
||||||
|
) as List<Int>
|
||||||
|
if (list.isNotEmpty()) {
|
||||||
|
list.reversed().forEach { id ->
|
||||||
|
subMap[id]?.let { returnArray.add(it) }
|
||||||
|
}
|
||||||
|
subMap.values.forEach {
|
||||||
|
if (!returnArray.contains(it)) returnArray.add(it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
returnArray.addAll(subMap.values)
|
returnArray.addAll(subMap.values)
|
||||||
returnMap["current$type"] = returnArray
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val list = PrefManager.getNullableCustomVal(
|
|
||||||
"continueAnimeList",
|
|
||||||
listOf<Int>(),
|
|
||||||
List::class.java
|
|
||||||
) as List<Int>
|
|
||||||
if (list.isNotEmpty()) {
|
|
||||||
list.reversed().forEach {
|
|
||||||
if (subMap.containsKey(it)) returnArray.add(subMap[it]!!)
|
|
||||||
}
|
|
||||||
for (i in subMap) {
|
|
||||||
if (i.value !in returnArray) returnArray.add(i.value)
|
|
||||||
}
|
|
||||||
} else returnArray.addAll(subMap.values)
|
|
||||||
returnMap["current$type"] = returnArray
|
returnMap["current$type"] = returnArray
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun planned(type: String) {
|
if (toShow.getOrNull(0) == true) processMedia(
|
||||||
val subMap = mutableMapOf<Int, Media>()
|
"Anime",
|
||||||
val returnArray = arrayListOf<Media>()
|
response?.data?.currentAnime?.lists?.flatMap { it.entries ?: emptyList() }?.reversed(),
|
||||||
val current =
|
response?.data?.repeatingAnime?.lists?.flatMap { it.entries ?: emptyList() }?.reversed()
|
||||||
if (type == "Anime") response?.data?.plannedAnime else response?.data?.plannedManga
|
)
|
||||||
current?.lists?.forEach { li ->
|
if (toShow.getOrNull(2) == true) processMedia(
|
||||||
li.entries?.reversed()?.forEach {
|
"AnimePlanned",
|
||||||
val m = Media(it)
|
response?.data?.plannedAnime?.lists?.flatMap { it.entries ?: emptyList() }?.reversed(),
|
||||||
if (m.id !in removeList && if (hidePrivate) !m.isListPrivate else true) {
|
null
|
||||||
m.cameFromContinue = true
|
)
|
||||||
subMap[m.id] = m
|
if (toShow.getOrNull(3) == true) processMedia(
|
||||||
} else {
|
"Manga",
|
||||||
removedMedia.add(m)
|
response?.data?.currentManga?.lists?.flatMap { it.entries ?: emptyList() }?.reversed(),
|
||||||
}
|
response?.data?.repeatingManga?.lists?.flatMap { it.entries ?: emptyList() }?.reversed()
|
||||||
}
|
)
|
||||||
}
|
if (toShow.getOrNull(5) == true) processMedia(
|
||||||
@Suppress("UNCHECKED_CAST")
|
"MangaPlanned",
|
||||||
val list = PrefManager.getNullableCustomVal(
|
response?.data?.plannedManga?.lists?.flatMap { it.entries ?: emptyList() }?.reversed(),
|
||||||
"continueAnimeList",
|
null
|
||||||
listOf<Int>(),
|
)
|
||||||
List::class.java
|
|
||||||
) as List<Int>
|
|
||||||
if (list.isNotEmpty()) {
|
|
||||||
list.reversed().forEach {
|
|
||||||
if (subMap.containsKey(it)) returnArray.add(subMap[it]!!)
|
|
||||||
}
|
|
||||||
for (i in subMap) {
|
|
||||||
if (i.value !in returnArray) returnArray.add(i.value)
|
|
||||||
}
|
|
||||||
} else returnArray.addAll(subMap.values)
|
|
||||||
returnMap["planned$type"] = returnArray
|
|
||||||
}
|
|
||||||
|
|
||||||
fun favorite(type: String) {
|
fun processFavorites(type: String, favorites: List<MediaEdge>?) {
|
||||||
val favourites =
|
|
||||||
if (type == "Anime") response?.data?.favoriteAnime?.favourites else response?.data?.favoriteManga?.favourites
|
|
||||||
val apiMediaList = if (type == "Anime") favourites?.anime else favourites?.manga
|
|
||||||
val returnArray = arrayListOf<Media>()
|
val returnArray = arrayListOf<Media>()
|
||||||
apiMediaList?.edges?.forEach {
|
favorites?.forEach { edge ->
|
||||||
it.node?.let { i ->
|
edge.node?.let {
|
||||||
val m = Media(i).apply { isFav = true }
|
val media = Media(it).apply { isFav = true }
|
||||||
if (m.id !in removeList && if (hidePrivate) !m.isListPrivate else true) {
|
if (media.id !in removeList && (!hidePrivate || !media.isListPrivate)) {
|
||||||
returnArray.add(m)
|
returnArray.add(media)
|
||||||
} else {
|
} else {
|
||||||
removedMedia.add(m)
|
removedMedia.add(media)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
returnMap["favorite$type"] = returnArray
|
returnMap["favorite$type"] = returnArray
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toShow.getOrNull(0) == true) {
|
if (toShow.getOrNull(1) == true) processFavorites(
|
||||||
current("Anime")
|
"Anime",
|
||||||
}
|
response?.data?.favoriteAnime?.favourites?.anime?.edges
|
||||||
if (toShow.getOrNull(1) == true) {
|
)
|
||||||
favorite("Anime")
|
if (toShow.getOrNull(4) == true) processFavorites(
|
||||||
}
|
"Manga",
|
||||||
if (toShow.getOrNull(2) == true) {
|
response?.data?.favoriteManga?.favourites?.manga?.edges
|
||||||
planned("Anime")
|
)
|
||||||
}
|
|
||||||
if (toShow.getOrNull(3) == true) {
|
|
||||||
current("Manga")
|
|
||||||
}
|
|
||||||
if (toShow.getOrNull(4) == true) {
|
|
||||||
favorite("Manga")
|
|
||||||
}
|
|
||||||
if (toShow.getOrNull(5) == true) {
|
|
||||||
planned("Manga")
|
|
||||||
}
|
|
||||||
if (toShow.getOrNull(6) == true) {
|
if (toShow.getOrNull(6) == true) {
|
||||||
val subMap = mutableMapOf<Int, Media>()
|
val subMap = mutableMapOf<Int, Media>()
|
||||||
response?.data?.recommendationQuery?.apply {
|
response?.data?.recommendationQuery?.recommendations?.forEach {
|
||||||
recommendations?.onEach {
|
it.mediaRecommendation?.let { json ->
|
||||||
val json = it.mediaRecommendation
|
val media = Media(json)
|
||||||
if (json != null) {
|
media.relation = json.type?.toString()
|
||||||
val m = Media(json)
|
subMap[media.id] = media
|
||||||
m.relation = json.type?.toString()
|
|
||||||
subMap[m.id] = m
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response?.data?.recommendationPlannedQueryAnime?.apply {
|
response?.data?.recommendationPlannedQueryAnime?.lists?.flatMap {
|
||||||
lists?.forEach { li ->
|
it.entries ?: emptyList()
|
||||||
li.entries?.forEach {
|
}?.forEach {
|
||||||
val m = Media(it)
|
val media = Media(it)
|
||||||
if (m.status == "RELEASING" || m.status == "FINISHED") {
|
if (media.status in listOf("RELEASING", "FINISHED")) {
|
||||||
m.relation = it.media?.type?.toString()
|
media.relation = it.media?.type?.toString()
|
||||||
subMap[m.id] = m
|
subMap[media.id] = media
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response?.data?.recommendationPlannedQueryManga?.apply {
|
response?.data?.recommendationPlannedQueryManga?.lists?.flatMap {
|
||||||
lists?.forEach { li ->
|
it.entries ?: emptyList()
|
||||||
li.entries?.forEach {
|
}?.forEach {
|
||||||
val m = Media(it)
|
val media = Media(it)
|
||||||
if (m.status == "RELEASING" || m.status == "FINISHED") {
|
if (media.status in listOf("RELEASING", "FINISHED")) {
|
||||||
m.relation = it.media?.type?.toString()
|
media.relation = it.media?.type?.toString()
|
||||||
subMap[m.id] = m
|
subMap[media.id] = media
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val list = ArrayList(subMap.values.toList())
|
val list = ArrayList(subMap.values).apply { sortByDescending { it.meanScore } }
|
||||||
list.sortByDescending { it.meanScore }
|
|
||||||
returnMap["recommendations"] = list
|
returnMap["recommendations"] = list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,102 +1031,97 @@ query (${"$"}page: Int = 1, ${"$"}id: Int, ${"$"}type: MediaType, ${"$"}isAdult:
|
||||||
media1?.media?.mapTo(combinedList) { Media(it) }
|
media1?.media?.mapTo(combinedList) { Media(it) }
|
||||||
return combinedList
|
return combinedList
|
||||||
}
|
}
|
||||||
private fun getPreference(pref: PrefName): Boolean = PrefManager.getVal(pref)
|
|
||||||
private fun buildQueryString(sort: String, type: String, format: String? = null, country: String? = null): String {
|
|
||||||
val includeList = if (type == "ANIME" && !getPreference(PrefName.IncludeAnimeList)) "onList:false" else if (type == "MANGA" && !getPreference(PrefName.IncludeMangaList)) "onList:false" else ""
|
|
||||||
val isAdult = if (getPreference(PrefName.AdultOnly)) "isAdult:true" else ""
|
|
||||||
val formatFilter = format?.let { "format: $it, " } ?: ""
|
|
||||||
val countryFilter = country?.let { "countryOfOrigin: $it, " } ?: ""
|
|
||||||
|
|
||||||
return """Page(page:1,perPage:50){
|
private fun getPreference(pref: PrefName): Boolean = PrefManager.getVal(pref)
|
||||||
pageInfo{hasNextPage total}
|
|
||||||
media(sort:$sort, type:$type, $formatFilter $countryFilter $includeList $isAdult){
|
private fun buildQueryString(
|
||||||
id idMal status chapters episodes nextAiringEpisode{episode}
|
sort: String,
|
||||||
isAdult type meanScore isFavourite format bannerImage countryOfOrigin
|
type: String,
|
||||||
coverImage{large} title{english romaji userPreferred}
|
format: String? = null,
|
||||||
mediaListEntry{progress private score(format:POINT_100) status}
|
country: String? = null
|
||||||
|
): String {
|
||||||
|
val includeList = when {
|
||||||
|
type == "ANIME" && !getPreference(PrefName.IncludeAnimeList) -> "onList:false"
|
||||||
|
type == "MANGA" && !getPreference(PrefName.IncludeMangaList) -> "onList:false"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
val isAdult = if (getPreference(PrefName.AdultOnly)) "isAdult:true" else ""
|
||||||
|
val formatFilter = format?.let { "format:$it, " } ?: ""
|
||||||
|
val countryFilter = country?.let { "countryOfOrigin:$it, " } ?: ""
|
||||||
|
|
||||||
|
return buildString {
|
||||||
|
append("""Page(page:1,perPage:50){pageInfo{hasNextPage total}media(sort:$sort, type:$type, $formatFilter $countryFilter $includeList $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 recentAnimeUpdates(page: Int): String {
|
private fun recentAnimeUpdates(page: Int): String {
|
||||||
val currentTime = System.currentTimeMillis() / 1000
|
val currentTime = System.currentTimeMillis() / 1000
|
||||||
return """Page(page:$page,perPage:50){
|
return buildString {
|
||||||
pageInfo{hasNextPage total}
|
append("""Page(page:$page,perPage:50){pageInfo{hasNextPage total}airingSchedules(airingAt_greater:0 airingAt_lesser:${currentTime - 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}}}}""")
|
||||||
airingSchedules(airingAt_greater:0 airingAt_lesser:${currentTime - 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 queryAnimeList(): String {
|
private fun queryAnimeList(): String {
|
||||||
return """{
|
return buildString {
|
||||||
recentUpdates:${recentAnimeUpdates(1)}
|
append("""{recentUpdates:${recentAnimeUpdates(1)} recentUpdates2:${recentAnimeUpdates(2)} trendingMovies:${buildQueryString("POPULARITY_DESC", "ANIME", "MOVIE")} topRated:${buildQueryString("SCORE_DESC", "ANIME")} mostFav:${buildQueryString("FAVOURITES_DESC", "ANIME")}}""")
|
||||||
recentUpdates2:${recentAnimeUpdates(2)}
|
}
|
||||||
trendingMovies:${buildQueryString("POPULARITY_DESC", "ANIME", "MOVIE")}
|
|
||||||
topRated:${buildQueryString("SCORE_DESC", "ANIME")}
|
|
||||||
mostFav:${buildQueryString("FAVOURITES_DESC", "ANIME")}
|
|
||||||
}"""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun queryMangaList(): String {
|
private fun queryMangaList(): String {
|
||||||
return """{
|
return buildString {
|
||||||
trendingManga:${buildQueryString("POPULARITY_DESC", "MANGA", country = "JP")}
|
append("""{trendingManga:${buildQueryString("POPULARITY_DESC", "MANGA", country = "JP")} trendingManhwa:${buildQueryString("POPULARITY_DESC", "MANGA", country = "KR")} trendingNovel:${buildQueryString("POPULARITY_DESC", "MANGA", format = "NOVEL", country = "JP")} topRated:${buildQueryString("SCORE_DESC", "MANGA")} mostFav:${buildQueryString("FAVOURITES_DESC", "MANGA")}}""")
|
||||||
trendingManhwa:${buildQueryString("POPULARITY_DESC", "MANGA", country = "KR")}
|
}
|
||||||
trendingNovel:${buildQueryString("POPULARITY_DESC", "MANGA", format = "NOVEL", country = "JP")}
|
|
||||||
topRated:${buildQueryString("SCORE_DESC", "MANGA")}
|
|
||||||
mostFav:${buildQueryString("FAVOURITES_DESC", "MANGA")}
|
|
||||||
|
|
||||||
}"""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun loadAnimeList(): Map<String, ArrayList<Media>> {
|
suspend fun loadAnimeList(): Map<String, ArrayList<Media>> = coroutineScope {
|
||||||
val list = mutableMapOf<String, ArrayList<Media>>()
|
val list = mutableMapOf<String, ArrayList<Media>>()
|
||||||
|
|
||||||
fun filterRecentUpdates(
|
fun filterRecentUpdates(page: Page?): ArrayList<Media> {
|
||||||
page: Page?,
|
val listOnly = getPreference(PrefName.RecentlyListOnly)
|
||||||
): ArrayList<Media> {
|
val adultOnly = getPreference(PrefName.AdultOnly)
|
||||||
val listOnly: Boolean = PrefManager.getVal(PrefName.RecentlyListOnly)
|
val idArr = mutableSetOf<Int>()
|
||||||
val adultOnly: Boolean = PrefManager.getVal(PrefName.AdultOnly)
|
|
||||||
val idArr = mutableListOf<Int>()
|
|
||||||
return page?.airingSchedules?.mapNotNull { i ->
|
return page?.airingSchedules?.mapNotNull { i ->
|
||||||
i.media?.let {
|
i.media?.takeIf { !idArr.contains(it.id) }?.let {
|
||||||
if (!idArr.contains(it.id)) {
|
val shouldAdd = when {
|
||||||
val shouldAdd = when {
|
!listOnly && it.countryOfOrigin == "JP" && adultOnly && it.isAdult == true -> true
|
||||||
!listOnly && it.countryOfOrigin == "JP" && Anilist.adult && adultOnly && it.isAdult == true -> true
|
!listOnly && !adultOnly && it.countryOfOrigin == "JP" && it.isAdult == false -> true
|
||||||
!listOnly && !adultOnly && it.countryOfOrigin == "JP" && it.isAdult == false -> true
|
listOnly && it.mediaListEntry != null -> true
|
||||||
listOnly && it.mediaListEntry != null -> true
|
else -> false
|
||||||
else -> false
|
}
|
||||||
}
|
if (shouldAdd) {
|
||||||
if (shouldAdd) {
|
idArr.add(it.id)
|
||||||
idArr.add(it.id)
|
Media(it)
|
||||||
Media(it)
|
|
||||||
} else null
|
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
}?.toCollection(ArrayList()) ?: arrayListOf()
|
}?.toCollection(ArrayList()) ?: arrayListOf()
|
||||||
}
|
}
|
||||||
executeQuery<Query.AnimeList>(queryAnimeList(), force = true)?.data?.apply {
|
|
||||||
|
val animeList = async { executeQuery<Query.AnimeList>(queryAnimeList(), force = true) }
|
||||||
|
|
||||||
|
animeList.await()?.data?.apply {
|
||||||
list["recentUpdates"] = filterRecentUpdates(recentUpdates)
|
list["recentUpdates"] = filterRecentUpdates(recentUpdates)
|
||||||
list["trendingMovies"] = mediaList(trendingMovies)
|
list["trendingMovies"] = mediaList(trendingMovies)
|
||||||
list["topRated"] = mediaList(topRated)
|
list["topRated"] = mediaList(topRated)
|
||||||
list["mostFav"] = mediaList(mostFav)
|
list["mostFav"] = mediaList(mostFav)
|
||||||
}
|
}
|
||||||
return list
|
|
||||||
|
list
|
||||||
}
|
}
|
||||||
suspend fun loadMangaList(): Map<String, ArrayList<Media>> {
|
|
||||||
|
suspend fun loadMangaList(): Map<String, ArrayList<Media>> = coroutineScope {
|
||||||
val list = mutableMapOf<String, ArrayList<Media>>()
|
val list = mutableMapOf<String, ArrayList<Media>>()
|
||||||
executeQuery<Query.MangaList>(queryMangaList(), force = true)?.data?.apply {
|
|
||||||
|
val mangaList = async { executeQuery<Query.MangaList>(queryMangaList(), force = true) }
|
||||||
|
|
||||||
|
mangaList.await()?.data?.apply {
|
||||||
list["trendingManga"] = mediaList(trendingManga)
|
list["trendingManga"] = mediaList(trendingManga)
|
||||||
list["trendingManhwa"] = mediaList(trendingManhwa)
|
list["trendingManhwa"] = mediaList(trendingManhwa)
|
||||||
list["trendingNovel"] = mediaList(trendingNovel)
|
list["trendingNovel"] = mediaList(trendingNovel)
|
||||||
list["topRated"] = mediaList(topRated)
|
list["topRated"] = mediaList(topRated)
|
||||||
list["mostFav"] = mediaList(mostFav)
|
list["mostFav"] = mediaList(mostFav)
|
||||||
}
|
}
|
||||||
return list
|
|
||||||
|
list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1560,10 +1525,10 @@ Page(page:$page,perPage:50) {
|
||||||
resetNotification: Boolean = true,
|
resetNotification: Boolean = true,
|
||||||
type: Boolean? = null
|
type: Boolean? = null
|
||||||
): NotificationResponse? {
|
): NotificationResponse? {
|
||||||
val type_in = "type_in:[AIRING,MEDIA_MERGE,MEDIA_DELETION,MEDIA_DATA_CHANGE]"
|
val typeIn = "type_in:[AIRING,MEDIA_MERGE,MEDIA_DELETION,MEDIA_DATA_CHANGE]"
|
||||||
val reset = if (resetNotification) "true" else "false"
|
val reset = if (resetNotification) "true" else "false"
|
||||||
val res = executeQuery<NotificationResponse>(
|
val res = executeQuery<NotificationResponse>(
|
||||||
"""{User(id:$id){unreadNotificationCount}Page(page:$page,perPage:$ITEMS_PER_PAGE){pageInfo{currentPage,hasNextPage}notifications(resetNotificationCount:$reset , ${if (type == true) type_in else ""}){__typename...on AiringNotification{id,type,animeId,episode,contexts,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}},}...on FollowingNotification{id,userId,type,context,createdAt,user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMessageNotification{id,userId,type,activityId,context,createdAt,message{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMentionNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplySubscribedNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentMentionNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentReplyNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentSubscribedNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentLikeNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadLikeNotification{id,userId,type,threadId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on RelatedMediaAdditionNotification{id,type,context,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDataChangeNotification{id,type,mediaId,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaMergeNotification{id,type,mediaId,deletedMediaTitles,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDeletionNotification{id,type,deletedMediaTitle,context,reason,createdAt,}}}}""",
|
"""{User(id:$id){unreadNotificationCount}Page(page:$page,perPage:$ITEMS_PER_PAGE){pageInfo{currentPage,hasNextPage}notifications(resetNotificationCount:$reset , ${if (type == true) typeIn else ""}){__typename...on AiringNotification{id,type,animeId,episode,contexts,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}},}...on FollowingNotification{id,userId,type,context,createdAt,user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMessageNotification{id,userId,type,activityId,context,createdAt,message{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityMentionNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplySubscribedNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ActivityReplyLikeNotification{id,userId,type,activityId,context,createdAt,activity{__typename}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentMentionNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentReplyNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentSubscribedNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadCommentLikeNotification{id,userId,type,commentId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on ThreadLikeNotification{id,userId,type,threadId,context,createdAt,thread{id}comment{id}user{id,name,bannerImage,avatar{medium,large,}}}...on RelatedMediaAdditionNotification{id,type,context,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDataChangeNotification{id,type,mediaId,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaMergeNotification{id,type,mediaId,deletedMediaTitles,context,reason,createdAt,media{id,title{romaji,english,native,userPreferred}bannerImage,coverImage{medium,large}}}...on MediaDeletionNotification{id,type,deletedMediaTitle,context,reason,createdAt,}}}}""",
|
||||||
force = true
|
force = true
|
||||||
)
|
)
|
||||||
if (res != null && resetNotification) {
|
if (res != null && resetNotification) {
|
||||||
|
|
|
@ -91,17 +91,16 @@ class AnilistHomeViewModel : ViewModel() {
|
||||||
|
|
||||||
fun getHidden(): LiveData<ArrayList<Media>> = hidden
|
fun getHidden(): LiveData<ArrayList<Media>> = hidden
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
suspend fun initHomePage() {
|
suspend fun initHomePage() {
|
||||||
val res = Anilist.query.initHomePage()
|
val res = Anilist.query.initHomePage()
|
||||||
res["currentAnime"]?.let { animeContinue.postValue(it as ArrayList<Media>?) }
|
res["currentAnime"]?.let { animeContinue.postValue(it) }
|
||||||
res["favoriteAnime"]?.let { animeFav.postValue(it as ArrayList<Media>?) }
|
res["favoriteAnime"]?.let { animeFav.postValue(it) }
|
||||||
res["plannedAnime"]?.let { animePlanned.postValue(it as ArrayList<Media>?) }
|
res["currentAnimePlanned"]?.let { animePlanned.postValue(it) }
|
||||||
res["currentManga"]?.let { mangaContinue.postValue(it as ArrayList<Media>?) }
|
res["currentManga"]?.let { mangaContinue.postValue(it) }
|
||||||
res["favoriteManga"]?.let { mangaFav.postValue(it as ArrayList<Media>?) }
|
res["favoriteManga"]?.let { mangaFav.postValue(it) }
|
||||||
res["plannedManga"]?.let { mangaPlanned.postValue(it as ArrayList<Media>?) }
|
res["currentMangaPlanned"]?.let { mangaPlanned.postValue(it) }
|
||||||
res["recommendations"]?.let { recommendation.postValue(it as ArrayList<Media>?) }
|
res["recommendations"]?.let { recommendation.postValue(it) }
|
||||||
res["hidden"]?.let { hidden.postValue(it as ArrayList<Media>?) }
|
res["hidden"]?.let { hidden.postValue(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun loadMain(context: FragmentActivity) {
|
suspend fun loadMain(context: FragmentActivity) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ import ani.dantotsu.statusBarHeight
|
||||||
import ani.dantotsu.util.Logger
|
import ani.dantotsu.util.Logger
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
@ -457,53 +458,56 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
var running = false
|
var running = false
|
||||||
val live = Refresh.activity.getOrPut(1) { MutableLiveData(true) }
|
val live = Refresh.activity.getOrPut(1) { MutableLiveData(true) }
|
||||||
live.observe(viewLifecycleOwner)
|
live.observe(viewLifecycleOwner) { shouldRefresh ->
|
||||||
{
|
if (!running && shouldRefresh) {
|
||||||
if (!running && it) {
|
|
||||||
running = true
|
running = true
|
||||||
scope.launch {
|
scope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
//Get userData First
|
// Get user data first
|
||||||
Anilist.userid =
|
Anilist.userid = PrefManager.getNullableVal<String>(PrefName.AnilistUserId, null)?.toIntOrNull()
|
||||||
PrefManager.getNullableVal<String>(PrefName.AnilistUserId, null)
|
|
||||||
?.toIntOrNull()
|
|
||||||
if (Anilist.userid == null) {
|
if (Anilist.userid == null) {
|
||||||
getUserId(requireContext()) {
|
withContext(Dispatchers.Main) {
|
||||||
load()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
getUserId(requireContext()) {
|
getUserId(requireContext()) {
|
||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
getUserId(requireContext()) {
|
||||||
|
load()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
model.loaded = true
|
model.loaded = true
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
model.setListImages()
|
||||||
model.setListImages()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var empty = true
|
var empty = true
|
||||||
val homeLayoutShow: List<Boolean> =
|
val homeLayoutShow: List<Boolean> = PrefManager.getVal(PrefName.HomeLayout)
|
||||||
PrefManager.getVal(PrefName.HomeLayout)
|
|
||||||
model.initHomePage()
|
withContext(Dispatchers.Main) {
|
||||||
model.initUserStatus()
|
homeLayoutShow.indices.forEach { i ->
|
||||||
(array.indices).forEach { i ->
|
|
||||||
if (homeLayoutShow.elementAt(i)) {
|
if (homeLayoutShow.elementAt(i)) {
|
||||||
empty = false
|
empty = false
|
||||||
} else withContext(Dispatchers.Main) {
|
} else {
|
||||||
containers[i].visibility = View.GONE
|
containers[i].visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.empty.postValue(empty)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val initHomePage = async(Dispatchers.IO) { model.initHomePage() }
|
||||||
|
val initUserStatus = async(Dispatchers.IO) { model.initUserStatus() }
|
||||||
|
initHomePage.await()
|
||||||
|
initUserStatus.await()
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
model.empty.postValue(empty)
|
||||||
|
binding.homeHiddenItemsContainer.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
live.postValue(false)
|
live.postValue(false)
|
||||||
_binding?.homeRefresh?.isRefreshing = false
|
_binding?.homeRefresh?.isRefreshing = false
|
||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
binding.homeHiddenItemsContainer.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue