Implements litanies lyrics truncate & all lyrics bottom '⋆'
This commit is contained in:
parent
7d1e02078f
commit
fea05c3f21
3 changed files with 83 additions and 4 deletions
|
|
@ -3,6 +3,15 @@ package mg.dot.feufaro.solfa
|
||||||
class POneStanzaLyrics {
|
class POneStanzaLyrics {
|
||||||
private val lyrics: MutableList<String> = mutableListOf("")
|
private val lyrics: MutableList<String> = mutableListOf("")
|
||||||
private val alternativeLyrics: MutableMap<Int, MutableMap<Int, String>> = mutableMapOf()
|
private val alternativeLyrics: MutableMap<Int, MutableMap<Int, String>> = mutableMapOf()
|
||||||
|
|
||||||
|
private val litany: MutableMap<Int, String> = mutableMapOf()
|
||||||
|
companion object {
|
||||||
|
private val REGEX_LITANY = Regex("\\$\\{L[:=]([^\\}]*)\\}")
|
||||||
|
}
|
||||||
|
fun getLitany(stanzaNumber: Int): String? = litany[stanzaNumber]
|
||||||
|
fun copyLitany(fromStanzaNumber: Int, toStanzaNumber: Int) {
|
||||||
|
litany[fromStanzaNumber]?.let { litany.putIfAbsent(toStanzaNumber, it) }
|
||||||
|
}
|
||||||
fun getLyrics(stanzaNumber: Int) : String {
|
fun getLyrics(stanzaNumber: Int) : String {
|
||||||
return this.lyrics[stanzaNumber]
|
return this.lyrics[stanzaNumber]
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +19,13 @@ class POneStanzaLyrics {
|
||||||
while (this.lyrics.size <= stanzaNumber) {
|
while (this.lyrics.size <= stanzaNumber) {
|
||||||
this.lyrics.add("")
|
this.lyrics.add("")
|
||||||
}
|
}
|
||||||
|
val litanyText = REGEX_LITANY.findAll(lyrics)
|
||||||
|
.map { it.groupValues[1].trim() }
|
||||||
|
.filter { it.isNotEmpty() }
|
||||||
|
.joinToString(" ")
|
||||||
|
if (litanyText.isNotEmpty()) {
|
||||||
|
litany[stanzaNumber] = litanyText
|
||||||
|
}
|
||||||
this.lyrics[stanzaNumber] = lyrics.replace(Regex("\\$\\{[^\\}]*\\}-?"), "")
|
this.lyrics[stanzaNumber] = lyrics.replace(Regex("\\$\\{[^\\}]*\\}-?"), "")
|
||||||
}
|
}
|
||||||
fun setAlternativeLyrics(stanzaNumber: Int, voiceNumber: Int, text: String) {
|
fun setAlternativeLyrics(stanzaNumber: Int, voiceNumber: Int, text: String) {
|
||||||
|
|
|
||||||
|
|
@ -2893,6 +2893,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
for (i in refrainBeginsAt..refrainMax) {
|
for (i in refrainBeginsAt..refrainMax) {
|
||||||
L[i].setLyrics(stanzaNumber, L[i].getLyrics(1))
|
L[i].setLyrics(stanzaNumber, L[i].getLyrics(1))
|
||||||
L[i].copyAlternativeLyrics(1, stanzaNumber)
|
L[i].copyAlternativeLyrics(1, stanzaNumber)
|
||||||
|
L[i].copyLitany(1, stanzaNumber)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,11 @@ class TimeUnitObject (val pTemplate: PTemplate, val prevTUO: TimeUnitObject?, co
|
||||||
}
|
}
|
||||||
fun isLitany(): Boolean = pTemplate.hasMarker($$"${L}")
|
fun isLitany(): Boolean = pTemplate.hasMarker($$"${L}")
|
||||||
|
|
||||||
|
fun litanyText(stanzaNumber: Int): String? {
|
||||||
|
if (!isLitany()) return null
|
||||||
|
return lyrics.firstNotNullOfOrNull { it.getLitany(stanzaNumber) }?.takeIf { it.isNotBlank() }
|
||||||
|
}
|
||||||
|
|
||||||
fun addLyrics(lyricsIn: POneStanzaLyrics) {
|
fun addLyrics(lyricsIn: POneStanzaLyrics) {
|
||||||
lyrics.add(lyricsIn)
|
lyrics.add(lyricsIn)
|
||||||
}
|
}
|
||||||
|
|
@ -812,6 +817,17 @@ fun LazyVerticalGridTUO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val litanyLabels: Map<Int, Pair<String, String>> = remember(tuoList, currentStanza) {
|
||||||
|
val map = LinkedHashMap<Int, Pair<String, String>>()
|
||||||
|
tuoList.drop(1).forEach { litanyTuo ->
|
||||||
|
val text = litanyTuo.litanyText(currentStanza)
|
||||||
|
if (text != null) {
|
||||||
|
map[litanyTuo.numBlock] = "⋆".repeat(map.size + 1) to text.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map
|
||||||
|
}
|
||||||
|
|
||||||
if (!isLayoutReady) {
|
if (!isLayoutReady) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
@ -1135,11 +1151,20 @@ fun LazyVerticalGridTUO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val allTemps = measureTUOs.map { it.getSingleSyllable(currentStanza) }
|
|
||||||
val maxLines = allTemps.maxOfOrNull { it.size } ?: 0
|
|
||||||
|
|
||||||
|
|
||||||
val textMeasurer = rememberTextMeasurer()
|
val textMeasurer = rememberTextMeasurer()
|
||||||
|
val litanyStyle = MaterialTheme.typography.titleMedium
|
||||||
|
val litanyMaxWidthPx = with(density) { ((gridWidthDp / gridColumnCount) - 4.dp).toPx() }
|
||||||
|
val allTemps = measureTUOs.map { oneTUO ->
|
||||||
|
val litany = litanyLabels[oneTUO.numBlock]
|
||||||
|
if (litany != null) {
|
||||||
|
listOf(fitLitanyLabel(litany.first, litany.second, textMeasurer, litanyStyle, litanyMaxWidthPx))
|
||||||
|
} else {
|
||||||
|
oneTUO.getSingleSyllable(currentStanza)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val maxLines = allTemps.maxOfOrNull { it.size } ?: 0
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.Start
|
horizontalArrangement = Arrangement.Start
|
||||||
|
|
@ -1188,6 +1213,7 @@ fun LazyVerticalGridTUO(
|
||||||
overflow = TextOverflow.Visible,
|
overflow = TextOverflow.Visible,
|
||||||
style = TextStyle(
|
style = TextStyle(
|
||||||
color = when {
|
color = when {
|
||||||
|
litanyLabels.containsKey(measureTUOs[syls_i].numBlock) -> MaterialTheme.colorScheme.onBackground.copy(0.7f)
|
||||||
(isTooLong) -> MaterialTheme.colorScheme.onBackground
|
(isTooLong) -> MaterialTheme.colorScheme.onBackground
|
||||||
(index == 0) -> MaterialTheme.colorScheme.onBackground
|
(index == 0) -> MaterialTheme.colorScheme.onBackground
|
||||||
else -> MaterialTheme.colorScheme.onBackground
|
else -> MaterialTheme.colorScheme.onBackground
|
||||||
|
|
@ -1207,6 +1233,21 @@ fun LazyVerticalGridTUO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (litanyLabels.isNotEmpty()) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(start = 8.dp, end = 8.dp, top = 12.dp, bottom = 8.dp)
|
||||||
|
) {
|
||||||
|
litanyLabels.values.forEach { (stars, fullText) ->
|
||||||
|
Text(
|
||||||
|
text = "$stars$fullText",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onBackground.copy(0.7f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1464,6 +1505,27 @@ private fun TuoEditDialogWrapper(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fitLitanyLabel(
|
||||||
|
stars: String,
|
||||||
|
text: String,
|
||||||
|
textMeasurer: TextMeasurer,
|
||||||
|
style: TextStyle,
|
||||||
|
maxWidthPx: Float
|
||||||
|
): String {
|
||||||
|
fun widthOf(s: String): Int =
|
||||||
|
textMeasurer.measure(text = s, style = style, maxLines = 1, softWrap = false).size.width
|
||||||
|
|
||||||
|
val full = stars + text
|
||||||
|
if (widthOf(full) <= maxWidthPx) return full
|
||||||
|
var end = text.length
|
||||||
|
while (end > 0) {
|
||||||
|
val candidate = stars + text.substring(0, end).trimEnd() + "..."
|
||||||
|
if (widthOf(candidate) <= maxWidthPx) return candidate
|
||||||
|
end--
|
||||||
|
}
|
||||||
|
return stars
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun makeSpaceBetweenSyllables(
|
fun makeSpaceBetweenSyllables(
|
||||||
textMeasurer: TextMeasurer,
|
textMeasurer: TextMeasurer,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue