Skip to content

Commit

Permalink
Merge branch 'master' into l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g authored May 11, 2024
2 parents 826f159 + 89a3970 commit cbedf2e
Show file tree
Hide file tree
Showing 119 changed files with 2,985 additions and 2,454 deletions.
7 changes: 5 additions & 2 deletions anilist/src/commonMain/graphql/AiringQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ query AiringQuery(
}
},
mediaListEntry {
score(format: POINT_5)
score(format: POINT_5),
status
},
trailer {
id,
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion anilist/src/commonMain/graphql/MediaListEntryQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query MediaListEntryQuery($id: Int) {
MediaList(mediaId: $id) {
score(format: POINT_5)
score(format: POINT_5),
status
}
}
7 changes: 5 additions & 2 deletions anilist/src/commonMain/graphql/MediumQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ query MediumQuery($id: Int, $statusVersion: Int, $html: Boolean) {
}
},
mediaListEntry {
score(format: POINT_5)
score(format: POINT_5),
status
},
trailer {
id,
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
7 changes: 5 additions & 2 deletions anilist/src/commonMain/graphql/SeasonQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ query SeasonQuery(
}
},
mediaListEntry {
score(format: POINT_5)
score(format: POINT_5),
status
},
trailer {
id,
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
}
7 changes: 5 additions & 2 deletions anilist/src/commonMain/graphql/TrendingQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ query TrendingQuery(
}
},
mediaListEntry {
score(format: POINT_5)
score(format: POINT_5),
status
},
trailer {
id,
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.type.AiringSort
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.datetime.Clock
import kotlinx.serialization.Serializable
import kotlin.time.Duration.Companion.hours

class AiringTodayRepository(
Expand All @@ -22,12 +24,16 @@ class AiringTodayRepository(
)
}.distinctUntilChanged()

private val airingPreFilter = query.transform {
return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow())
@OptIn(ExperimentalCoroutinesApi::class)
private val airingPreFilter = query.transformLatest {
return@transformLatest emitAll(apolloClient.query(it.toGraphQL()).toFlow())
}
private val fallbackPreFilter = query.transform {
return@transform emitAll(fallbackClient.query(it.toGraphQL()).toFlow())

@OptIn(ExperimentalCoroutinesApi::class)
private val fallbackPreFilter = query.transformLatest {
return@transformLatest emitAll(fallbackClient.query(it.toGraphQL()).toFlow())
}

private val fallbackQuery = combine(fallbackPreFilter, nsfw.distinctUntilChanged()) { q, n ->
val data = q.data
if (data == null) {
Expand All @@ -41,6 +47,7 @@ class AiringTodayRepository(
}
}.filterNotNull()

@OptIn(ExperimentalCoroutinesApi::class)
val airing = combine(airingPreFilter, nsfw.distinctUntilChanged()) { q, n ->
val data = q.data
if (data == null) {
Expand All @@ -52,8 +59,8 @@ class AiringTodayRepository(
} else {
State.fromGraphQL(data, n)
}
}.filterNotNull().transform {
return@transform if (it is State.Error) {
}.filterNotNull().transformLatest {
return@transformLatest if (it is State.Error) {
emitAll(fallbackQuery)
} else {
emit(it)
Expand Down Expand Up @@ -85,10 +92,14 @@ class AiringTodayRepository(
}

sealed interface State {
@Serializable
data object None : State

data class Success(
val collection: Collection<AiringQuery.AiringSchedule>
) : State

@Serializable
data object Error : State

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,65 @@ package dev.datlag.aniflow.anilist
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import dev.datlag.aniflow.anilist.common.nextSeason
import dev.datlag.aniflow.anilist.state.SeasonState
import dev.datlag.aniflow.anilist.state.CollectionState
import dev.datlag.aniflow.anilist.type.MediaSeason
import dev.datlag.aniflow.anilist.type.MediaSort
import dev.datlag.aniflow.anilist.type.MediaType
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.datetime.Clock

class PopularNextSeasonRepository(
private val apolloClient: ApolloClient,
private val fallbackClient: ApolloClient,
private val nsfw: Flow<Boolean> = flowOf(false),
private val viewManga: Flow<Boolean> = flowOf(false),
) {

private val page = MutableStateFlow(0)
private val type = viewManga.distinctUntilChanged().map {
page.update { 0 }
if (it) {
MediaType.MANGA
} else {
MediaType.ANIME
}
}
private val query = combine(page, type, nsfw.distinctUntilChanged()) { p, t, n ->

private val query = combine(page, nsfw.distinctUntilChanged()) { p, n ->
val (season, year) = Clock.System.now().nextSeason

Query(
page = p,
type = t,
nsfw = n,
season = season,
year = year
)
}.distinctUntilChanged()
private val fallbackQuery = query.transform {
return@transform emitAll(fallbackClient.query(it.toGraphQL()).toFlow())

@OptIn(ExperimentalCoroutinesApi::class)
private val fallbackQuery = query.transformLatest {
return@transformLatest emitAll(fallbackClient.query(it.toGraphQL()).toFlow())
}.mapNotNull {
val data = it.data
if (data == null) {
if (it.hasErrors()) {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
} else {
null
}
} else {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
}
}

val popularNextSeason = query.transform {
return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow())
@OptIn(ExperimentalCoroutinesApi::class)
val popularNextSeason = query.transformLatest {
return@transformLatest emitAll(apolloClient.query(it.toGraphQL()).toFlow())
}.mapNotNull {
val data = it.data
if (data == null) {
if (it.hasErrors()) {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
} else {
null
}
} else {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
}
}.transform {
return@transform if (it is SeasonState.Error) {
}.transformLatest {
return@transformLatest if (it.isError) {
emitAll(fallbackQuery)
} else {
emit(it)
Expand All @@ -83,20 +78,19 @@ class PopularNextSeasonRepository(

private data class Query(
val page: Int,
val type: MediaType,
val nsfw: Boolean,
val season: MediaSeason,
val year: Int
) {
fun toGraphQL() = SeasonQuery(
page = Optional.present(page),
perPage = Optional.present(10),
perPage = Optional.present(20),
adultContent = if (nsfw) {
Optional.absent()
} else {
Optional.present(nsfw)
},
type = Optional.present(type),
type = Optional.present(MediaType.ANIME),
sort = Optional.present(listOf(MediaSort.POPULARITY_DESC)),
preventGenres = if (nsfw) {
Optional.absent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package dev.datlag.aniflow.anilist

import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import dev.datlag.aniflow.anilist.state.SeasonState
import dev.datlag.aniflow.anilist.state.CollectionState
import dev.datlag.aniflow.anilist.type.MediaSort
import dev.datlag.aniflow.anilist.type.MediaType
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*

class PopularSeasonRepository(
Expand All @@ -15,51 +16,57 @@ class PopularSeasonRepository(
) {

private val page = MutableStateFlow(0)
private val type = viewManga.distinctUntilChanged().map {

@OptIn(ExperimentalCoroutinesApi::class)
private val type = viewManga.distinctUntilChanged().mapLatest {
page.update { 0 }
if (it) {
MediaType.MANGA
} else {
MediaType.ANIME
}
}

private val query = combine(page, type, nsfw.distinctUntilChanged()) { p, t, n ->
Query(
page = p,
type = t,
nsfw = n
)
}.distinctUntilChanged()
private val fallbackQuery = query.transform {
return@transform emitAll(fallbackClient.query(it.toGraphQL()).toFlow())

@OptIn(ExperimentalCoroutinesApi::class)
private val fallbackQuery = query.transformLatest {
return@transformLatest emitAll(fallbackClient.query(it.toGraphQL()).toFlow())
}.mapNotNull {
val data = it.data
if (data == null) {
if (it.hasErrors()) {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
} else {
null
}
} else {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
}
}

val popularThisSeason = query.transform {
return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow())
@OptIn(ExperimentalCoroutinesApi::class)
val popularThisSeason = query.transformLatest {
return@transformLatest emitAll(apolloClient.query(it.toGraphQL()).toFlow())
}.mapNotNull {
val data = it.data
if (data == null) {
if (it.hasErrors()) {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
} else {
null
}
} else {
SeasonState.fromGraphQL(data)
CollectionState.fromSeasonGraphQL(data)
}
}.transform {
return@transform if (it is SeasonState.Error) {
}.transformLatest {
return@transformLatest if (it.isError) {
emitAll(fallbackQuery)
} else {
emit(it)
Expand All @@ -81,7 +88,7 @@ class PopularSeasonRepository(
) {
fun toGraphQL() = SeasonQuery(
page = Optional.present(page),
perPage = Optional.present(10),
perPage = Optional.present(20),
adultContent = if (nsfw) {
Optional.absent()
} else {
Expand Down
Loading

0 comments on commit cbedf2e

Please sign in to comment.