refactor(home): extract status strip -> components/HomeStatusStrip.kt
Step 6/9. Verbatim move (strip public, chip private). compileDebugKotlin green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
48197ffd1e
commit
d324efe182
|
|
@ -94,6 +94,7 @@ import app.closer.ui.home.components.ErrorHomeCard
|
||||||
import app.closer.ui.home.components.HomeActionColors
|
import app.closer.ui.home.components.HomeActionColors
|
||||||
import app.closer.ui.home.components.HomeGlyphIcon
|
import app.closer.ui.home.components.HomeGlyphIcon
|
||||||
import app.closer.ui.home.components.HomePill
|
import app.closer.ui.home.components.HomePill
|
||||||
|
import app.closer.ui.home.components.HomeStatusStrip
|
||||||
import app.closer.ui.home.components.LoadingHomeCard
|
import app.closer.ui.home.components.LoadingHomeCard
|
||||||
import app.closer.ui.home.components.WaitingForYouSection
|
import app.closer.ui.home.components.WaitingForYouSection
|
||||||
import app.closer.ui.home.components.actionColors
|
import app.closer.ui.home.components.actionColors
|
||||||
|
|
@ -423,105 +424,6 @@ private fun HomeContent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun HomeStatusStrip(
|
|
||||||
streakCount: Int,
|
|
||||||
privateCount: Int,
|
|
||||||
partnerName: String?,
|
|
||||||
dailyQuestionState: DailyQuestionState,
|
|
||||||
onPartner: () -> Unit = {},
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val streakLabel = when (streakCount) {
|
|
||||||
0 -> "Start streak"
|
|
||||||
1 -> "1 night"
|
|
||||||
else -> "$streakCount nights"
|
|
||||||
}
|
|
||||||
val tonightLabel = when (dailyQuestionState) {
|
|
||||||
DailyQuestionState.UNANSWERED -> "Question ready"
|
|
||||||
DailyQuestionState.USER_ANSWERED_PARTNER_PENDING -> "Answer saved"
|
|
||||||
DailyQuestionState.PARTNER_ANSWERED_USER_PENDING -> "Your turn"
|
|
||||||
DailyQuestionState.BOTH_ANSWERED -> "Reveal ready"
|
|
||||||
DailyQuestionState.REVEALED -> "Revealed"
|
|
||||||
}
|
|
||||||
val partnerLabel = partnerName?.takeIf { it.isNotBlank() } ?: "Paired"
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
StatusChip(
|
|
||||||
icon = R.drawable.glyph_streak,
|
|
||||||
label = streakLabel,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
StatusChip(
|
|
||||||
icon = R.drawable.glyph_privacy_lock,
|
|
||||||
label = "Just for two",
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
secondaryLabel = "$privateCount saved"
|
|
||||||
)
|
|
||||||
StatusChip(
|
|
||||||
icon = R.drawable.glyph_closer_heart_keyhole,
|
|
||||||
label = partnerLabel,
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
onClick = onPartner.takeIf { partnerName != null },
|
|
||||||
secondaryLabel = tonightLabel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun StatusChip(
|
|
||||||
@DrawableRes icon: Int,
|
|
||||||
label: String,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
secondaryLabel: String? = null,
|
|
||||||
onClick: (() -> Unit)? = null
|
|
||||||
) {
|
|
||||||
val chipModifier = if (onClick != null) modifier.clickable(onClick = onClick) else modifier
|
|
||||||
Surface(
|
|
||||||
modifier = chipModifier,
|
|
||||||
shape = RoundedCornerShape(CloserRadii.Tile),
|
|
||||||
color = closerCardColor(alpha = 0.78f),
|
|
||||||
tonalElevation = 0.dp
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(horizontal = 10.dp, vertical = 10.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(7.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
HomeGlyphIcon(
|
|
||||||
resId = icon,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = CloserPalette.PinkAccentDeep,
|
|
||||||
modifier = Modifier.size(17.dp)
|
|
||||||
)
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(1.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
style = MaterialTheme.typography.labelMedium.copy(fontWeight = FontWeight.SemiBold),
|
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
secondaryLabel?.let {
|
|
||||||
Text(
|
|
||||||
text = it,
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun HomeHeader(
|
private fun HomeHeader(
|
||||||
partnerName: String?,
|
partnerName: String?,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,126 @@
|
||||||
|
package app.closer.ui.home.components
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import app.closer.R
|
||||||
|
import app.closer.ui.components.CloserRadii
|
||||||
|
import app.closer.ui.home.DailyQuestionState
|
||||||
|
import app.closer.ui.theme.CloserPalette
|
||||||
|
import app.closer.ui.theme.closerCardColor
|
||||||
|
|
||||||
|
/** Home's 3-chip status strip (streak / private / partner-tonight). Extracted from HomeScreen.kt. */
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun HomeStatusStrip(
|
||||||
|
streakCount: Int,
|
||||||
|
privateCount: Int,
|
||||||
|
partnerName: String?,
|
||||||
|
dailyQuestionState: DailyQuestionState,
|
||||||
|
onPartner: () -> Unit = {},
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
val streakLabel = when (streakCount) {
|
||||||
|
0 -> "Start streak"
|
||||||
|
1 -> "1 night"
|
||||||
|
else -> "$streakCount nights"
|
||||||
|
}
|
||||||
|
val tonightLabel = when (dailyQuestionState) {
|
||||||
|
DailyQuestionState.UNANSWERED -> "Question ready"
|
||||||
|
DailyQuestionState.USER_ANSWERED_PARTNER_PENDING -> "Answer saved"
|
||||||
|
DailyQuestionState.PARTNER_ANSWERED_USER_PENDING -> "Your turn"
|
||||||
|
DailyQuestionState.BOTH_ANSWERED -> "Reveal ready"
|
||||||
|
DailyQuestionState.REVEALED -> "Revealed"
|
||||||
|
}
|
||||||
|
val partnerLabel = partnerName?.takeIf { it.isNotBlank() } ?: "Paired"
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
StatusChip(
|
||||||
|
icon = R.drawable.glyph_streak,
|
||||||
|
label = streakLabel,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
StatusChip(
|
||||||
|
icon = R.drawable.glyph_privacy_lock,
|
||||||
|
label = "Just for two",
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
secondaryLabel = "$privateCount saved"
|
||||||
|
)
|
||||||
|
StatusChip(
|
||||||
|
icon = R.drawable.glyph_closer_heart_keyhole,
|
||||||
|
label = partnerLabel,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
onClick = onPartner.takeIf { partnerName != null },
|
||||||
|
secondaryLabel = tonightLabel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun StatusChip(
|
||||||
|
@DrawableRes icon: Int,
|
||||||
|
label: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
secondaryLabel: String? = null,
|
||||||
|
onClick: (() -> Unit)? = null
|
||||||
|
) {
|
||||||
|
val chipModifier = if (onClick != null) modifier.clickable(onClick = onClick) else modifier
|
||||||
|
Surface(
|
||||||
|
modifier = chipModifier,
|
||||||
|
shape = RoundedCornerShape(CloserRadii.Tile),
|
||||||
|
color = closerCardColor(alpha = 0.78f),
|
||||||
|
tonalElevation = 0.dp
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(horizontal = 10.dp, vertical = 10.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(7.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
HomeGlyphIcon(
|
||||||
|
resId = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = CloserPalette.PinkAccentDeep,
|
||||||
|
modifier = Modifier.size(17.dp)
|
||||||
|
)
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(1.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
style = MaterialTheme.typography.labelMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
secondaryLabel?.let {
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue