-
-
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.
- Loading branch information
Showing
35 changed files
with
752 additions
and
851 deletions.
There are no files selected for viewing
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
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
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
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
52 changes: 52 additions & 0 deletions
52
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/CollectionState.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,52 @@ | ||
package dev.datlag.aniflow.anilist.state | ||
|
||
import dev.datlag.aniflow.anilist.SeasonQuery | ||
import dev.datlag.aniflow.anilist.TrendingQuery | ||
import dev.datlag.aniflow.anilist.model.Medium | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
sealed interface CollectionState { | ||
|
||
val isSuccess: Boolean | ||
get() = this is Success | ||
|
||
val isError: Boolean | ||
get() = this is Error | ||
|
||
@Serializable | ||
data object None : CollectionState | ||
|
||
@Serializable | ||
data class Success( | ||
val collection: Collection<Medium> | ||
) : CollectionState | ||
|
||
@Serializable | ||
data object Error : CollectionState | ||
|
||
companion object { | ||
fun fromTrendingGraphQL(data: TrendingQuery.Data?): CollectionState { | ||
val mediaList = data?.Page?.mediaFilterNotNull() | ||
|
||
if (mediaList.isNullOrEmpty()) { | ||
return Error | ||
} | ||
|
||
return Success(mediaList.map { Medium(it) }) | ||
} | ||
|
||
fun fromSeasonGraphQL(data: SeasonQuery.Data?): CollectionState { | ||
val mediaList = data?.Page?.mediaFilterNotNull() | ||
|
||
if (mediaList.isNullOrEmpty()) { | ||
return Error | ||
} | ||
|
||
return Success(mediaList.map { Medium(it) }) | ||
} | ||
} | ||
} | ||
|
||
val CollectionState?.isLoading: Boolean | ||
get() = this == null || this is CollectionState.None |
33 changes: 0 additions & 33 deletions
33
anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/state/SeasonState.kt
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.