Skip to content

Commit

Permalink
added home state info
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 2, 2023
1 parent b8f5a1c commit ee09736
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ sealed class HomeConfig : Parcelable {
val coverHref: String?,
) : HomeConfig(), Parcelable {
constructor(series: Home.Series) : this(series.title, series.href, series.coverHref)
constructor(episode: Home.Episode) : this(episode.series ?: episode.title, episode.href, episode.href)
constructor(episode: Home.Episode) : this(episode.series ?: episode.title, episode.href, episode.coverHref)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.datlag.burningseries.ui.screen.initial.home

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -20,13 +21,15 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import dev.datlag.burningseries.LocalDarkMode
import dev.datlag.burningseries.common.header
import dev.datlag.burningseries.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.model.Home
import dev.datlag.burningseries.model.state.HomeState
import dev.datlag.burningseries.shared.SharedRes
import dev.datlag.burningseries.ui.screen.initial.home.component.EpisodeItem
import dev.datlag.burningseries.ui.screen.initial.home.component.SeriesItem
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
Expand All @@ -36,20 +39,47 @@ fun HomeScreen(component: HomeComponent) {

when (val currentState = homeState) {
is HomeState.Loading -> {
Box(
Column(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Loading Home Data")
val painterRes = if (LocalDarkMode.current) {
SharedRes.images.movie_dark
} else {
SharedRes.images.movie_light
}
Image(
modifier = Modifier.fillMaxWidth(0.7F),
painter = painterResource(painterRes),
contentDescription = stringResource(SharedRes.strings.loading_home)
)
Text(
text = stringResource(SharedRes.strings.loading_home),
fontWeight = FontWeight.SemiBold
)
}
}
is HomeState.Error -> {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Error Loading Home Data")
val painterRes = if (LocalDarkMode.current) {
SharedRes.images.sad_dark
} else {
SharedRes.images.sad_light
}
Image(
modifier = Modifier.fillMaxWidth(0.7F),
painter = painterResource(painterRes),
contentDescription = stringResource(SharedRes.strings.error_loading_home)
)
Text(
text = stringResource(SharedRes.strings.error_loading_home),
fontWeight = FontWeight.SemiBold
)
Button(
onClick = {
component.retryLoadingHome()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ fun LazyGridItemScope.EpisodeItem(episode: Home.Episode, onclick: () -> Unit) {
Surface(
shape = CardDefaults.elevatedShape
) {
episode.coverHref?.let { cover ->
when (val resource = asyncPainterResource(BSUtil.getBurningSeriesLink(cover))) {
is Resource.Loading, is Resource.Failure -> {
Box(
modifier = Modifier
.aspectRatio(1F, true)
.clip(CardDefaults.elevatedShape)
.background(MaterialTheme.colorScheme.tertiaryContainer)
)
}
is Resource.Success -> {
Image(
painter = resource.value,
contentScale = ContentScale.FillWidth,
contentDescription = episode.title,
modifier = Modifier.aspectRatio(1F, true)
)
}
when (val resource = asyncPainterResource(episode.coverHref?.let { BSUtil.getBurningSeriesLink(it) } ?: String())) {
is Resource.Loading, is Resource.Failure -> {
Box(
modifier = Modifier
.aspectRatio(1F, true)
.clip(CardDefaults.elevatedShape)
.background(MaterialTheme.colorScheme.tertiaryContainer)
)
}
is Resource.Success -> {
Image(
painter = resource.value,
contentScale = ContentScale.FillWidth,
contentDescription = episode.title,
modifier = Modifier.aspectRatio(1F, true)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.datlag.burningseries.ui.screen.initial.series

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -15,9 +17,13 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import dev.datlag.burningseries.model.BSUtil
import dev.datlag.burningseries.ui.custom.DefaultCollapsingToolbar
import io.kamel.core.Resource
import io.kamel.image.asyncPainterResource
import kotlin.math.abs

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
Expand All @@ -33,6 +39,18 @@ fun SeriesScreen(component: SeriesComponent) {
private fun CompactScreen(component: SeriesComponent) {
DefaultCollapsingToolbar(
expandedBody = { state ->
when (val resource = asyncPainterResource(component.initialCoverHref?.let { BSUtil.getBurningSeriesLink(it) } ?: String())) {
is Resource.Loading, is Resource.Failure -> { }
is Resource.Success -> {
Image(
modifier = Modifier.fillMaxWidth().defaultMinSize(minHeight = 320.dp).parallax(0.5F),
painter = resource.value,
contentDescription = component.initialTitle,
contentScale = ContentScale.FillWidth,
)
}
}

Text(
text = component.initialTitle,
modifier = Modifier.road(Alignment.TopStart, Alignment.BottomStart).padding(16.dp),
Expand Down
2 changes: 2 additions & 0 deletions app/shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<string name="newest_episodes">Newest Episodes</string>
<string name="newest_series">Newest Series</string>
<string name="retry">Retry</string>
<string name="loading_home">Loading newest episodes and series, please wait</string>
<string name="error_loading_home">Error while loading newest episodes and series</string>
</resources>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/shared/src/commonMain/resources/MR/images/sad_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.datlag.burningseries.model.state.HomeAction
import dev.datlag.burningseries.network.scraper.BurningSeries
import io.ktor.client.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay

@OptIn(ExperimentalCoroutinesApi::class)
class HomeStateMachine(
Expand Down

0 comments on commit ee09736

Please sign in to comment.