-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playback 2023 - Top listened categories story (#1482)
- Loading branch information
Showing
9 changed files
with
222 additions
and
67 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
216 changes: 156 additions & 60 deletions
216
.../au/com/shiftyjelly/pocketcasts/endofyear/views/stories/StoryTopListenedCategoriesView.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 |
---|---|---|
@@ -1,123 +1,219 @@ | ||
package au.com.shiftyjelly.pocketcasts.endofyear.views.stories | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.widthIn | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalView | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.font.Font | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import au.com.shiftyjelly.pocketcasts.compose.components.TextH10 | ||
import au.com.shiftyjelly.pocketcasts.compose.components.TextH30 | ||
import au.com.shiftyjelly.pocketcasts.endofyear.components.CategoryPillar | ||
import au.com.shiftyjelly.pocketcasts.compose.components.TextH50 | ||
import au.com.shiftyjelly.pocketcasts.compose.theme | ||
import au.com.shiftyjelly.pocketcasts.endofyear.components.StoryBlurredBackground | ||
import au.com.shiftyjelly.pocketcasts.endofyear.components.StoryPrimaryText | ||
import au.com.shiftyjelly.pocketcasts.endofyear.components.StorySecondaryText | ||
import au.com.shiftyjelly.pocketcasts.endofyear.components.disableScale | ||
import au.com.shiftyjelly.pocketcasts.endofyear.utils.dynamicBackground | ||
import au.com.shiftyjelly.pocketcasts.endofyear.utils.textGradient | ||
import au.com.shiftyjelly.pocketcasts.localization.helper.tryToLocalise | ||
import au.com.shiftyjelly.pocketcasts.models.db.helper.ListenedCategory | ||
import au.com.shiftyjelly.pocketcasts.repositories.endofyear.stories.StoryTopListenedCategories | ||
import au.com.shiftyjelly.pocketcasts.settings.stats.StatsHelper | ||
import kotlin.math.min | ||
import au.com.shiftyjelly.pocketcasts.localization.R as LR | ||
import au.com.shiftyjelly.pocketcasts.ui.R as UR | ||
|
||
private const val BackgroundColor = 0xFF744F9D | ||
private val CategoryColor = Color(0xFF686C74) | ||
private val CategoryFontSize = 40.sp | ||
private val DefaultFontFamily = FontFamily(listOf(Font(UR.font.dm_sans))) | ||
|
||
@Composable | ||
fun StoryTopListenedCategoriesView( | ||
story: StoryTopListenedCategories, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = modifier | ||
.fillMaxSize() | ||
.dynamicBackground(Color(BackgroundColor)) | ||
.verticalScroll(rememberScrollState()) | ||
) { | ||
Spacer(modifier = modifier.height(40.dp)) | ||
Box { | ||
StoryBlurredBackground( | ||
offset = Offset( | ||
-LocalView.current.width * 0.4f, | ||
-LocalView.current.height * 0.4f | ||
), | ||
rotate = 110f, | ||
) | ||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = modifier | ||
.fillMaxSize() | ||
.verticalScroll(rememberScrollState()) | ||
.padding(vertical = 40.dp) | ||
) { | ||
Spacer(modifier = modifier.weight(0.2f)) | ||
|
||
PrimaryText(story) | ||
|
||
Spacer(modifier = modifier.weight(1f)) | ||
Spacer(modifier = modifier.height(14.dp)) | ||
|
||
Title(story) | ||
SecondaryText(story) | ||
|
||
Spacer(modifier = modifier.weight(0.5f)) | ||
Spacer(modifier = modifier.weight(0.2f)) | ||
|
||
CategoryPillars(story, modifier) | ||
CategoryList(story, modifier) | ||
|
||
Spacer(modifier = modifier.weight(1f)) | ||
Spacer(modifier = modifier.weight(0.5f)) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Title( | ||
private fun PrimaryText( | ||
story: StoryTopListenedCategories, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val text = stringResource(LR.string.end_of_year_story_top_categories) | ||
TextH30( | ||
text = text, | ||
textAlign = TextAlign.Center, | ||
color = story.tintColor, | ||
disableScale = disableScale(), | ||
modifier = modifier | ||
.padding(horizontal = 40.dp) | ||
.fillMaxWidth() | ||
val context = LocalContext.current | ||
val text = stringResource( | ||
LR.string.end_of_year_story_top_categories_title, | ||
story.listenedCategories[0].simplifiedCategoryName().tryToLocalise(context.resources) | ||
) | ||
StoryPrimaryText(text = text, color = story.tintColor, modifier = modifier) | ||
} | ||
|
||
@Composable | ||
private fun CategoryPillars( | ||
private fun SecondaryText( | ||
story: StoryTopListenedCategories, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val context = LocalContext.current | ||
val timeText = StatsHelper.secondsToFriendlyString( | ||
story.listenedCategories[0].totalPlayedTime, | ||
context.resources | ||
) | ||
val text = stringResource( | ||
id = LR.string.end_of_year_story_top_categories_subtitle, | ||
story.listenedCategories[0].numberOfEpisodes, | ||
timeText | ||
) | ||
StorySecondaryText(text = text, color = story.subtitleColor, modifier = modifier) | ||
} | ||
|
||
@Composable | ||
private fun CategoryList( | ||
story: StoryTopListenedCategories, | ||
modifier: Modifier = Modifier, | ||
) { | ||
(0..min(story.listenedCategories.size, 3)).forEach { index -> | ||
val listenedCategory = story.listenedCategories.atIndex(index) | ||
listenedCategory?.let { | ||
CategoryItem( | ||
listenedCategory = it, | ||
position = index, | ||
subtitleColor = story.subtitleColor, | ||
modifier = modifier | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun CategoryItem( | ||
listenedCategory: ListenedCategory, | ||
position: Int, | ||
subtitleColor: Color, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.Center, | ||
verticalAlignment = Alignment.Bottom, | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 40.dp) | ||
) { | ||
listOf(1, 0, 2).forEach { index -> | ||
Spacer(modifier.weight(1f)) | ||
|
||
val listenedCategory = story.listenedCategories.atIndex(index) | ||
listenedCategory?.let { | ||
val timeText = | ||
StatsHelper.secondsToFriendlyString( | ||
listenedCategory.totalPlayedTime, | ||
context.resources | ||
) | ||
CategoryPillar( | ||
title = listenedCategory.category, | ||
duration = timeText, | ||
text = (index + 1).toString(), | ||
height = (200 - index * 55).dp, | ||
modifier = modifier | ||
.padding( | ||
bottom = if (index == 0) 70.dp else 0.dp, | ||
) | ||
TextH30( | ||
text = "${position + 1}", | ||
color = subtitleColor, | ||
fontWeight = FontWeight.W700, | ||
fontFamily = DefaultFontFamily, | ||
disableScale = disableScale(), | ||
modifier = modifier | ||
.padding(end = 14.dp) | ||
.widthIn(min = 16.dp) | ||
) | ||
Row( | ||
modifier = modifier | ||
.padding(vertical = 10.dp) | ||
.weight(1f), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
if (position == 0) { | ||
CategoryTexts( | ||
listenedCategory = listenedCategory, | ||
subtitleColor = Color.White, | ||
modifier = Modifier | ||
.textGradient() | ||
) | ||
} ?: CategoryPillar( | ||
title = "", | ||
duration = "", | ||
text = "", | ||
height = 200.dp, | ||
modifier = modifier.alpha(0f) | ||
) | ||
|
||
Spacer(modifier.weight(1f)) | ||
} else { | ||
CategoryTexts( | ||
listenedCategory = listenedCategory, | ||
titleColor = CategoryColor, | ||
subtitleColor = subtitleColor, | ||
modifier = Modifier | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun CategoryTexts( | ||
listenedCategory: ListenedCategory, | ||
titleColor: Color = MaterialTheme.theme.colors.primaryText01, | ||
subtitleColor: Color, | ||
modifier: Modifier, | ||
) { | ||
val context = LocalContext.current | ||
val timeText = StatsHelper.secondsToFriendlyString( | ||
listenedCategory.totalPlayedTime, | ||
context.resources | ||
) | ||
Column { | ||
TextH10( | ||
text = listenedCategory.simplifiedCategoryName(), | ||
maxLines = 1, | ||
color = titleColor, | ||
fontSize = CategoryFontSize, | ||
fontFamily = DefaultFontFamily, | ||
fontWeight = FontWeight.W500, | ||
disableScale = true, | ||
modifier = modifier, | ||
) | ||
Spacer(modifier = Modifier.height(3.dp)) | ||
TextH50( | ||
text = timeText, | ||
color = subtitleColor, | ||
maxLines = 1, | ||
fontFamily = DefaultFontFamily, | ||
fontWeight = FontWeight.W600, | ||
disableScale = disableScale(), | ||
) | ||
} | ||
} | ||
|
||
private fun List<ListenedCategory>.atIndex(index: Int) = | ||
if (index < size) this[index] else null |
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.