@@ -7,6 +7,7 @@ import androidx.compose.foundation.background
77import androidx.compose.foundation.clickable
88import androidx.compose.foundation.layout.*
99import androidx.compose.foundation.lazy.LazyColumn
10+ import androidx.compose.foundation.lazy.items
1011import androidx.compose.foundation.shape.CircleShape
1112import androidx.compose.foundation.shape.RoundedCornerShape
1213import androidx.compose.material.*
@@ -31,6 +32,7 @@ import androidx.compose.ui.platform.LocalConfiguration
3132import androidx.compose.ui.platform.LocalDensity
3233import androidx.compose.ui.res.stringArrayResource
3334import androidx.compose.ui.res.stringResource
35+ import androidx.compose.ui.text.AnnotatedString
3436import androidx.compose.ui.text.SpanStyle
3537import androidx.compose.ui.text.buildAnnotatedString
3638import androidx.compose.ui.text.font.FontWeight
@@ -162,6 +164,7 @@ fun PuzzleBoard(
162164 ScoreBox (viewModel, state.currentRank, state.currentScore)
163165 DiscoveredWordBox (
164166 words = state.discoveredWords,
167+ pangrams = state.discoveredPangrams,
165168 state.wordBoxExpanded,
166169 viewModel::toggleWorldBox
167170 )
@@ -218,6 +221,7 @@ fun PuzzleBoardLandscape(
218221 ) {
219222 DiscoveredWordBox (
220223 words = state.discoveredWords,
224+ pangrams = state.discoveredPangrams,
221225 expanded = state.wordBoxExpanded,
222226 toggleExpand = viewModel::toggleWorldBox
223227 )
@@ -443,6 +447,7 @@ fun MaxWidthText(
443447@Composable
444448fun DiscoveredWordBox (
445449 words : Set <String >,
450+ pangrams : Set <String >,
446451 expanded : Boolean = false,
447452 toggleExpand : () -> Unit = {}
448453) {
@@ -458,24 +463,36 @@ fun DiscoveredWordBox(
458463 .animateContentSize(),
459464 ) {
460465 if (! expanded) {
461- val text = if (words.isEmpty()) {
462- stringResource(R .string.puzzle_detail_word_list_empty)
466+ val text: AnnotatedString = if (words.isEmpty()) {
467+ AnnotatedString ( stringResource(R .string.puzzle_detail_word_list_empty) )
463468 } else {
464- words.reversed()
465- .joinToString(separator = " " ) { word -> word.capitalize(Locale .getDefault()) }
469+ buildAnnotatedString {
470+ words.reversed().forEachIndexed { index, word ->
471+ val fontWeight =
472+ if (word in pangrams) FontWeight .ExtraBold else FontWeight .Medium
473+
474+ withStyle(style = SpanStyle (fontWeight = fontWeight)) {
475+ append(word.capitalize(Locale .ENGLISH ))
476+ }
477+
478+ if (index < words.size - 1 ) {
479+ append(" " )
480+ }
481+ }
482+ }
466483 }
467484 ChevronRow (text, expanded = false )
468485 } else {
469486 Column (modifier = Modifier .fillMaxSize()) {
470487 ChevronRow (
471- stringResource(
488+ AnnotatedString ( stringResource(
472489 R .string.puzzle_detail_word_list_word_count,
473490 words.size
474- ), true
491+ )) , true
475492 )
476493 if (words.isNotEmpty()) {
477494 Spacer (Modifier .height(16 .dp))
478- ColumnGridList (words.toList())
495+ ColumnGridList (words.toList(), pangrams )
479496 }
480497 }
481498 }
@@ -484,37 +501,34 @@ fun DiscoveredWordBox(
484501}
485502
486503@Composable
487- fun ColumnGridList (words : List <String >, columnNum : Int = 3) {
488- val wordsPerColumn = ceil(words.size / columnNum.toDouble()).toInt()
489- val columns = words.windowed(wordsPerColumn, step = wordsPerColumn, partialWindows = true )
504+ fun ColumnGridList (words : List <String >, pangrams : Set <String >, columnNum : Int = 3) {
505+ val rows = words.sorted().chunked(columnNum)
490506 LazyColumn (modifier = Modifier .fillMaxSize()) {
491- for (i in 0 until wordsPerColumn) {
492- item {
493- Row (
494- modifier = Modifier .fillMaxWidth(),
495- horizontalArrangement = Arrangement .SpaceEvenly
496- ) {
497- for (j in 0 until columnNum) {
498- val word = columns.getOrNull(j)?.getOrNull(i) ? : " "
499- Text (
500- text = word.capitalize(Locale .getDefault()),
501- maxLines = 1 ,
502- textAlign = TextAlign .Start ,
503- modifier = Modifier .weight(1f ),
504- overflow = TextOverflow .Ellipsis
505- )
506- }
507+ items(rows) { rowWords ->
508+ Row (
509+ modifier = Modifier .fillMaxWidth(),
510+ horizontalArrangement = Arrangement .SpaceEvenly
511+ ) {
512+ for (i in 0 until columnNum) {
513+ val word = rowWords.getOrNull(i) ? : " "
514+ Text (
515+ text = word.capitalize(Locale .ENGLISH ),
516+ maxLines = 1 ,
517+ textAlign = TextAlign .Start ,
518+ modifier = Modifier .weight(1f ),
519+ overflow = TextOverflow .Ellipsis ,
520+ fontWeight = if (word in pangrams) FontWeight .ExtraBold else FontWeight .Medium
521+ )
507522 }
508- Spacer (modifier = Modifier .height(4 .dp))
509523 }
510-
524+ Spacer (modifier = Modifier .height( 4 .dp))
511525 }
512526 }
513527}
514528
515529@Composable
516530fun ChevronRow (
517- text : String ,
531+ text : AnnotatedString ,
518532 expanded : Boolean ,
519533 textColor : Color = MaterialTheme .colors.onSurface
520534) {
@@ -543,7 +557,7 @@ fun ChevronRow(
543557@Preview
544558@Composable
545559fun PreviewDiscoveredWordBoxEmpty () {
546- DiscoveredWordBox (words = emptySet(), false )
560+ DiscoveredWordBox (words = emptySet(), pangrams = emptySet(), false )
547561}
548562
549563@Preview
@@ -552,7 +566,8 @@ fun PreviewDiscoveredWordBoxFull() {
552566 DiscoveredWordBox (
553567 words = setOf (
554568 " handle" , " story" , " rabbit" , " cloud" , " couch" , " towel" , " anger" , " greeting"
555- )
569+ ),
570+ pangrams = emptySet()
556571 )
557572}
558573
@@ -563,6 +578,7 @@ fun PreviewDiscoveredWordBoxFullExpanded() {
563578 words = setOf (
564579 " handle" , " story" , " rabbit" , " cloud"
565580 ),
581+ pangrams = emptySet(),
566582 expanded = true
567583 )
568584}
0 commit comments