Skip to content

Commit

Permalink
initial series loading
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 8, 2023
1 parent 8ac3b78 commit c9119b5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import dev.datlag.burningseries.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.common.onClick
import dev.datlag.burningseries.model.BSUtil
import dev.datlag.burningseries.model.Series
import dev.datlag.burningseries.model.state.SeriesState
Expand Down Expand Up @@ -162,7 +164,8 @@ private fun DefaultScreen(component: SeriesComponent) {
}
is SeriesState.Success -> {
LazyColumn(
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
contentPadding = PaddingValues(16.dp)
) {
item(
key = {
Expand All @@ -172,14 +175,44 @@ private fun DefaultScreen(component: SeriesComponent) {
)
}
) {
SeasonAndLanguageButtons(
current.series.currentSeason,
current.series.currentLanguage,
current.series.seasons,
current.series.languages,
onSeasonClick = { },
onLanguageClick = { }
)
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
when (val resource = asyncPainterResource(component.initialCoverHref?.let { BSUtil.getBurningSeriesLink(it) } ?: String())) {
is Resource.Loading, is Resource.Failure -> { }
is Resource.Success -> {
Image(
modifier = Modifier.width(200.dp).clip(MaterialTheme.shapes.medium),
painter = resource.value,
contentDescription = component.initialTitle,
contentScale = ContentScale.FillWidth,
)
}
}

Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = component.initialTitle,
style = MaterialTheme.typography.headlineMedium,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
softWrap = true
)

SeasonAndLanguageButtons(
current.series.currentSeason,
current.series.currentLanguage,
current.series.seasons,
current.series.languages,
onSeasonClick = { },
onLanguageClick = { }
)
}
}
}

SeriesContent(current.series)
Expand All @@ -189,13 +222,15 @@ private fun DefaultScreen(component: SeriesComponent) {
}

private fun LazyListScope.SeriesContent(content: Series) {
item(content.description) {
val (expanded, onExpandedChange) = rememberSaveable { mutableStateOf(false) }
item {
var expanded by remember { mutableStateOf(false) }

ReadMoreText(
text = content.description,
expanded = expanded,
onExpandedChange = onExpandedChange,
onExpandedChange = {
expanded = it
},
modifier = Modifier.fillMaxWidth(),
readMoreText = stringResource(SharedRes.strings.read_more),
readMoreColor = MaterialTheme.colorScheme.primary,
Expand All @@ -205,7 +240,7 @@ private fun LazyListScope.SeriesContent(content: Series) {
readLessText = stringResource(SharedRes.strings.read_less),
readLessColor = MaterialTheme.colorScheme.primary,
readLessFontWeight = FontWeight.SemiBold,
toggleArea = ToggleArea.More
toggleArea = ToggleArea.All
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data object BSUtil {
return rebuildHrefFromData(hrefDataFromHref(normalizeHref(href)))
}

fun hrefDataFromHref(href: String): Triple<String, String?, String?> {
private fun hrefDataFromHref(href: String): Triple<String, String?, String?> {
fun getTitle(): String {
val newHref = if (href.startsWith("series/")) {
href.substringAfter("series/")
Expand Down Expand Up @@ -84,7 +84,7 @@ data object BSUtil {
)
}

fun rebuildHrefFromData(hrefData: Triple<String, String?, String?>): String {
private fun rebuildHrefFromData(hrefData: Triple<String, String?, String?>): String {
return if (hrefData.second != null && hrefData.third != null) {
"serie/${hrefData.first}/${hrefData.second}/${hrefData.third}"
} else if (hrefData.second != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ data object BurningSeries {
}

suspend fun getSeries(client: HttpClient, href: String): Series? {
val doc = getDocument(client, href) ?: return null
val doc = getDocument(client, BSUtil.fixSeriesHref(href)) ?: return null

val title = doc.querySelector(".serie")?.querySelector("h2")?.textContent() ?: String()
val description = doc.querySelector(".serie")?.querySelector("#sp_left > p")?.textContent() ?: String()
Expand Down

0 comments on commit c9119b5

Please sign in to comment.