-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change season requests to easier repository
- Loading branch information
Showing
12 changed files
with
243 additions
and
310 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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.type.MediaSeason | ||
import dev.datlag.aniflow.anilist.type.MediaSort | ||
import dev.datlag.aniflow.anilist.type.MediaType | ||
import kotlinx.coroutines.flow.* | ||
import kotlinx.datetime.Clock | ||
|
||
class PopularNextSeasonRepository( | ||
private val apolloClient: ApolloClient, | ||
private val nsfw: Flow<Boolean> = flowOf(false), | ||
) { | ||
|
||
private val page = MutableStateFlow(0) | ||
private val type = MutableStateFlow(MediaType.ANIME) | ||
private val query = combine(page, type, nsfw.distinctUntilChanged()) { p, t, n -> | ||
val (season, year) = Clock.System.now().nextSeason | ||
|
||
Query( | ||
page = p, | ||
type = t, | ||
nsfw = n, | ||
season = season, | ||
year = year | ||
) | ||
} | ||
|
||
val popularNextSeason = query.transform { | ||
return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow()) | ||
}.map { | ||
SeasonState.fromGraphQL(it.data) | ||
} | ||
|
||
fun nextPage() = page.getAndUpdate { | ||
it + 1 | ||
} | ||
|
||
fun previousPage() = page.getAndUpdate { | ||
it - 1 | ||
} | ||
|
||
fun viewAnime() { | ||
type.getAndUpdate { | ||
if (it == MediaType.ANIME) { | ||
it | ||
} else { | ||
page.update { 0 } | ||
MediaType.ANIME | ||
} | ||
} | ||
} | ||
|
||
fun viewManga() { | ||
type.getAndUpdate { | ||
if (it == MediaType.MANGA) { | ||
it | ||
} else { | ||
page.update { 0 } | ||
MediaType.MANGA | ||
} | ||
} | ||
} | ||
|
||
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), | ||
adultContent = if (nsfw) { | ||
Optional.absent() | ||
} else { | ||
Optional.present(nsfw) | ||
}, | ||
type = Optional.present(type), | ||
sort = Optional.present(listOf(MediaSort.POPULARITY_DESC)), | ||
preventGenres = if (nsfw) { | ||
Optional.absent() | ||
} else { | ||
Optional.present(AdultContent.Genre.allTags) | ||
}, | ||
year = Optional.present(year), | ||
season = if (season == MediaSeason.UNKNOWN__) { | ||
Optional.absent() | ||
} else { | ||
Optional.present(season) | ||
}, | ||
statusVersion = Optional.present(2), | ||
html = Optional.present(true) | ||
) | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularNextSeasonStateMachine.kt
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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.type.MediaSort | ||
import dev.datlag.aniflow.anilist.type.MediaType | ||
import kotlinx.coroutines.flow.* | ||
|
||
class PopularSeasonRepository( | ||
private val apolloClient: ApolloClient, | ||
private val nsfw: Flow<Boolean> = flowOf(false), | ||
) { | ||
|
||
private val page = MutableStateFlow(0) | ||
private val type = MutableStateFlow(MediaType.ANIME) | ||
private val query = combine(page, type, nsfw.distinctUntilChanged()) { p, t, n -> | ||
Query( | ||
page = p, | ||
type = t, | ||
nsfw = n | ||
) | ||
} | ||
|
||
val popularThisSeason = query.transform { | ||
return@transform emitAll(apolloClient.query(it.toGraphQL()).toFlow()) | ||
}.map { | ||
SeasonState.fromGraphQL(it.data) | ||
} | ||
|
||
fun nextPage() = page.getAndUpdate { | ||
it + 1 | ||
} | ||
|
||
fun previousPage() = page.getAndUpdate { | ||
it - 1 | ||
} | ||
|
||
fun viewAnime() { | ||
type.getAndUpdate { | ||
if (it == MediaType.ANIME) { | ||
it | ||
} else { | ||
page.update { 0 } | ||
MediaType.ANIME | ||
} | ||
} | ||
} | ||
|
||
fun viewManga() { | ||
type.getAndUpdate { | ||
if (it == MediaType.MANGA) { | ||
it | ||
} else { | ||
page.update { 0 } | ||
MediaType.MANGA | ||
} | ||
} | ||
} | ||
|
||
private data class Query( | ||
val page: Int, | ||
val type: MediaType, | ||
val nsfw: Boolean | ||
) { | ||
fun toGraphQL() = SeasonQuery( | ||
page = Optional.present(page), | ||
perPage = Optional.present(10), | ||
adultContent = if (nsfw) { | ||
Optional.absent() | ||
} else { | ||
Optional.present(nsfw) | ||
}, | ||
type = Optional.present(type), | ||
sort = Optional.present(listOf(MediaSort.POPULARITY_DESC)), | ||
preventGenres = if (nsfw) { | ||
Optional.absent() | ||
} else { | ||
Optional.present(AdultContent.Genre.allTags) | ||
}, | ||
year = Optional.absent(), | ||
season = Optional.absent(), | ||
statusVersion = Optional.present(2), | ||
html = Optional.present(true) | ||
) | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/PopularSeasonStateMachine.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/StateSaver.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/CommonState.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.