Skip to content

Commit

Permalink
added manga info
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 11, 2024
1 parent ac2ed4e commit 39af1ee
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 67 deletions.
4 changes: 3 additions & 1 deletion anilist/src/commonMain/graphql/AiringQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ query AiringQuery(
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion anilist/src/commonMain/graphql/MediumQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ query MediumQuery($id: Int, $statusVersion: Int, $html: Boolean) {
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
4 changes: 3 additions & 1 deletion anilist/src/commonMain/graphql/SeasonQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ query SeasonQuery(
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
}
4 changes: 3 additions & 1 deletion anilist/src/commonMain/graphql/TrendingQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ query TrendingQuery(
site,
thumbnail
},
siteUrl
siteUrl,
chapters,
volumes
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ data class Medium(
val trailer: Trailer? = null,
val isFavorite: Boolean = false,
private val _isFavoriteBlocked: Boolean = true,
val siteUrl: String = "$SITE_URL$id"
val siteUrl: String = "$SITE_URL$id",
val chapters: Int = -1,
val volumes: Int = -1,
) {
constructor(trending: TrendingQuery.Medium) : this(
id = trending.id,
Expand Down Expand Up @@ -94,7 +96,9 @@ data class Medium(
},
isFavorite = trending.isFavourite,
_isFavoriteBlocked = trending.isFavouriteBlocked,
siteUrl = trending.siteUrl?.ifBlank { null } ?: "$SITE_URL${trending.id}"
siteUrl = trending.siteUrl?.ifBlank { null } ?: "$SITE_URL${trending.id}",
chapters = trending.chapters ?: -1,
volumes = trending.volumes ?: -1
)

constructor(airing: AiringQuery.Media) : this(
Expand Down Expand Up @@ -143,7 +147,9 @@ data class Medium(
},
isFavorite = airing.isFavourite,
_isFavoriteBlocked = airing.isFavouriteBlocked,
siteUrl = airing.siteUrl?.ifBlank { null } ?: "$SITE_URL${airing.id}"
siteUrl = airing.siteUrl?.ifBlank { null } ?: "$SITE_URL${airing.id}",
chapters = airing.chapters ?: -1,
volumes = airing.volumes ?: -1
)

constructor(season: SeasonQuery.Medium) : this(
Expand Down Expand Up @@ -192,7 +198,9 @@ data class Medium(
},
isFavorite = season.isFavourite,
_isFavoriteBlocked = season.isFavouriteBlocked,
siteUrl = season.siteUrl?.ifBlank { null } ?: "$SITE_URL${season.id}"
siteUrl = season.siteUrl?.ifBlank { null } ?: "$SITE_URL${season.id}",
chapters = season.chapters ?: -1,
volumes = season.volumes ?: -1
)

constructor(query: MediumQuery.Media) : this(
Expand Down Expand Up @@ -241,7 +249,9 @@ data class Medium(
},
isFavorite = query.isFavourite,
_isFavoriteBlocked = query.isFavouriteBlocked,
siteUrl = query.siteUrl?.ifBlank { null } ?: "$SITE_URL${query.id}"
siteUrl = query.siteUrl?.ifBlank { null } ?: "$SITE_URL${query.id}",
chapters = query.chapters ?: -1,
volumes = query.volumes ?: -1
)

@Transient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MainActivity : AppCompatActivity() {
}

val accessToken = uri.getFragmentOrQueryParameter("access_token")
if (accessToken.isNullOrBlank() || !::root.isInitialized) {
if (accessToken.isNullOrBlank()) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface MediumComponent : ContentHolderComponent {
val episodes: Flow<Int>
val duration: Flow<Int>
val status: Flow<MediaStatus>
val chapters: Flow<Int>
val volumes: Flow<Int>

val rated: Flow<Medium.Ranking?>
val popular: Flow<Medium.Ranking?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,9 @@ fun MediumScreen(component: MediumComponent) {
CollapsingToolbar(
state = appBarState,
scrollBehavior = scrollState,
initialMedium = component.initialMedium,
titleLanguageFlow = component.titleLanguage,
mediumFlow = component.mediumState,
bannerImageFlow = component.bannerImage,
coverImage = coverImage,
titleFlow = component.title,
isLoggedIn = component.isLoggedIn,
loginUri = component.loginUri,
isFavoriteFlow = component.isFavorite,
isFavoriteBlockedFlow = component.isFavoriteBlocked,
siteUrlFlow = component.siteUrl,
showShare = listState.isScrollingUp(),
onBack = { component.back() },
onToggleFavorite = { component.toggleFavorite() }
component = component
)
},
floatingActionButton = {
Expand Down Expand Up @@ -159,12 +148,7 @@ fun MediumScreen(component: MediumComponent) {
item {
CoverSection(
coverImage = coverImage,
initialMedium = component.initialMedium,
formatFlow = component.format,
episodesFlow = component.episodes,
durationFlow = component.duration,
statusFlow = component.status,
isAdultFlow = component.isAdult,
component = component,
modifier = Modifier.fillParentMaxWidth().padding(horizontal = 16.dp)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ class MediumScreenComponent(
it.medium.entry?.status ?: MediaListStatus.UNKNOWN__
}

@OptIn(ExperimentalCoroutinesApi::class)
override val chapters: Flow<Int> = mediumSuccessState.mapLatest {
it.medium.chapters
}

@OptIn(ExperimentalCoroutinesApi::class)
override val volumes: Flow<Int> = mediumSuccessState.mapLatest {
it.medium.volumes
}

private val dialogNavigation = SlotNavigation<DialogConfig>()
override val dialog: Value<ChildSlot<DialogConfig, DialogComponent>> = childSlot(
source = dialogNavigation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import dev.datlag.aniflow.common.preferred
import dev.datlag.aniflow.other.rememberInstantAppHelper
import dev.datlag.aniflow.settings.model.AppSettings
import dev.datlag.aniflow.ui.custom.shareHandler
import dev.datlag.aniflow.ui.navigation.screen.medium.MediumComponent
import dev.datlag.tooling.compose.ifFalse
import dev.datlag.tooling.compose.ifTrue
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
Expand All @@ -53,25 +54,14 @@ import dev.datlag.aniflow.settings.model.TitleLanguage as SettingsTitle
fun CollapsingToolbar(
state: TopAppBarState,
scrollBehavior: TopAppBarScrollBehavior,
initialMedium: Medium,
titleLanguageFlow: Flow<SettingsTitle?>,
mediumFlow: Flow<MediumRepository.State>,
bannerImageFlow: Flow<String?>,
coverImage: Medium.CoverImage,
titleFlow: Flow<Medium.Title>,
isLoggedIn: Flow<Boolean>,
loginUri: String,
isFavoriteFlow: Flow<Boolean>,
isFavoriteBlockedFlow: Flow<Boolean>,
siteUrlFlow: Flow<String>,
showShare: Boolean,
onBack: () -> Unit,
onToggleFavorite: () -> Unit
component: MediumComponent
) {
Box(
modifier = Modifier.fillMaxWidth()
) {
val bannerImage by bannerImageFlow.collectAsStateWithLifecycle(initialMedium.bannerImage)
val bannerImage by component.bannerImage.collectAsStateWithLifecycle(component.initialMedium.bannerImage)
val isCollapsed by remember(state) {
derivedStateOf { state.collapsedFraction >= 0.99F }
}
Expand Down Expand Up @@ -107,7 +97,7 @@ fun CollapsingToolbar(
Modifier.background(MaterialTheme.colorScheme.surface.copy(alpha = 0.75F), CircleShape)
},
onClick = {
onBack()
component.back()
}
) {
Icon(
Expand All @@ -121,8 +111,8 @@ fun CollapsingToolbar(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically)
) {
val title by titleFlow.collectAsStateWithLifecycle(initialMedium.title)
val titleLanguage by titleLanguageFlow.collectAsStateWithLifecycle(null)
val title by component.title.collectAsStateWithLifecycle(component.initialMedium.title)
val titleLanguage by component.titleLanguage.collectAsStateWithLifecycle(null)

Text(
text = title.preferred(titleLanguage),
Expand Down Expand Up @@ -172,8 +162,8 @@ fun CollapsingToolbar(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
) {
val mediumState by mediumFlow.collectAsStateWithLifecycle(null)
val siteUrl by siteUrlFlow.collectAsStateWithLifecycle(initialMedium.siteUrl)
val mediumState by component.mediumState.collectAsStateWithLifecycle(null)
val siteUrl by component.siteUrl.collectAsStateWithLifecycle(component.initialMedium.siteUrl)
val shareHandler = shareHandler()
val instantAppHelper = rememberInstantAppHelper()

Expand All @@ -182,19 +172,19 @@ fun CollapsingToolbar(
enter = fadeIn(),
exit = fadeOut()
) {
val loggedIn by isLoggedIn.collectAsStateWithLifecycle(false)
val isFavoriteBlocked by isFavoriteBlockedFlow.collectAsStateWithLifecycle(initialMedium.isFavoriteBlocked)
val isFavorite by isFavoriteFlow.collectAsStateWithLifecycle(initialMedium.isFavorite)
val loggedIn by component.isLoggedIn.collectAsStateWithLifecycle(false)
val isFavoriteBlocked by component.isFavoriteBlocked.collectAsStateWithLifecycle(component.initialMedium.isFavoriteBlocked)
val isFavorite by component.isFavorite.collectAsStateWithLifecycle(component.initialMedium.isFavorite)
var favoriteChanged by remember(isFavorite) { mutableStateOf<Boolean?>(null) }
val uriHandler = LocalUriHandler.current

IconButton(
onClick = {
if (!loggedIn) {
uriHandler.openUri(loginUri)
uriHandler.openUri(component.loginUri)
} else {
favoriteChanged = !(favoriteChanged ?: isFavorite)
onToggleFavorite()
component.toggleFavorite()
}
},
enabled = !loggedIn || !isFavoriteBlocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import androidx.compose.material.icons.filled.NoAdultContent
import androidx.compose.material.icons.filled.OndemandVideo
import androidx.compose.material.icons.filled.RssFeed
import androidx.compose.material.icons.filled.Timelapse
import androidx.compose.material.icons.rounded.NoAdultContent
import androidx.compose.material.icons.rounded.RssFeed
import androidx.compose.material.icons.rounded.Timelapse
import androidx.compose.material.icons.rounded.*
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -28,21 +26,18 @@ import dev.datlag.aniflow.anilist.type.MediaFormat
import dev.datlag.aniflow.anilist.type.MediaStatus
import dev.datlag.aniflow.common.icon
import dev.datlag.aniflow.common.text
import dev.datlag.aniflow.ui.navigation.screen.medium.MediumComponent
import dev.datlag.tooling.compose.ifTrue
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.pluralStringResource
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow

@Composable
fun CoverSection(
coverImage: Medium.CoverImage,
initialMedium: Medium,
formatFlow: Flow<MediaFormat>,
episodesFlow: Flow<Int>,
durationFlow: Flow<Int>,
statusFlow: Flow<MediaStatus>,
isAdultFlow: Flow<Boolean>,
component: MediumComponent,
modifier: Modifier = Modifier
) {
Row(
Expand Down Expand Up @@ -88,11 +83,13 @@ fun CoverSection(
modifier = Modifier.weight(1F).fillMaxHeight(),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
) {
val format by formatFlow.collectAsStateWithLifecycle(initialMedium.format)
val episodes by episodesFlow.collectAsStateWithLifecycle(initialMedium.episodes)
val duration by durationFlow.collectAsStateWithLifecycle(initialMedium.avgEpisodeDurationInMin)
val status by statusFlow.collectAsStateWithLifecycle(initialMedium.status)
val isAdult by isAdultFlow.collectAsStateWithLifecycle(initialMedium.isAdult)
val format by component.format.collectAsStateWithLifecycle(component.initialMedium.format)
val episodes by component.episodes.collectAsStateWithLifecycle(component.initialMedium.episodes)
val duration by component.duration.collectAsStateWithLifecycle(component.initialMedium.avgEpisodeDurationInMin)
val status by component.status.collectAsStateWithLifecycle(component.initialMedium.status)
val isAdult by component.isAdult.collectAsStateWithLifecycle(component.initialMedium.isAdult)
val chapters by component.chapters.collectAsStateWithLifecycle(component.initialMedium.chapters)
val volumes by component.volumes.collectAsStateWithLifecycle(component.initialMedium.volumes)

Row(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -128,7 +125,21 @@ fun CoverSection(
imageVector = Icons.AutoMirrored.Rounded.List,
contentDescription = null
)
Text(text = "$episodes Episodes")
Text(text = pluralStringResource(SharedRes.plurals.episodes, episodes, episodes))
}
} else {
if (chapters > -1) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
imageVector = Icons.Rounded.AutoStories,
contentDescription = null
)
Text(text = pluralStringResource(SharedRes.plurals.chapters, chapters, chapters))
}
}
}
if (duration > -1) {
Expand All @@ -141,7 +152,21 @@ fun CoverSection(
imageVector = Icons.Rounded.Timelapse,
contentDescription = null
)
Text(text = "${duration}min / Episode")
Text(text = stringResource(SharedRes.strings.duration_per_episode, duration))
}
} else {
if (volumes > -1) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
imageVector = Icons.Rounded.Book,
contentDescription = null
)
Text(text = pluralStringResource(SharedRes.plurals.volumes, volumes, volumes))
}
}
}
Row(
Expand Down
15 changes: 15 additions & 0 deletions composeApp/src/commonMain/moko-resources/base/plurals.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<plural name="episodes">
<item quantity="one">%d Episode</item>
<item quantity="other">%d Episodes</item>
</plural>
<plural name="chapters">
<item quantity="one">%d Chapter</item>
<item quantity="other">%d Chapters</item>
</plural>
<plural name="volumes">
<item quantity="one">%d Volume</item>
<item quantity="other">%d Volumes</item>
</plural>
</resources>
1 change: 1 addition & 0 deletions composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@
<string name="paused">Paused</string>
<string name="repeating">Repeating</string>
<string name="install">Install</string>
<string name="duration_per_episode">%dmin / Episode</string>
</resources>

0 comments on commit 39af1ee

Please sign in to comment.