@@ -367,6 +367,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
367367 var timeUntilNext = 0uL
368368 var firstHighlight: Int? = null
369369 var lastHighlight: Int? = null
370+ var lastNonTranslated: SemanticLyrics .LyricLine ? = null
370371 canvas.save()
371372 canvas.translate(globalPaddingHorizontal, heightSoFar.toFloat())
372373 val width = width - globalPaddingHorizontal * 2
@@ -432,6 +433,8 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
432433 }
433434 heightSoFarWithoutTranslated = heightSoFar
434435 }
436+ if (it.line?.isTranslated != true )
437+ lastNonTranslated = it.line
435438 if (highlight && firstHighlight == null ) {
436439 firstHighlight = heightSoFarWithoutTranslated
437440 determineTimeUntilNext = true
@@ -451,11 +454,11 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
451454 if (highlight) {
452455 canvas.save()
453456 canvas.scale(1f / hlScaleFactor, 1f / hlScaleFactor)
454- if (it.line?.words != null ) {
455- wordIdx = it.line.words .indexOfLast { it.timeRange.start <= posForRender }
457+ if (it.theWords != null ) {
458+ wordIdx = it.theWords .indexOfLast { it.timeRange.start <= posForRender }
456459 if (wordIdx == - 1 ) wordIdx = null
457460 if (wordIdx != null ) {
458- val word = it.line.words [wordIdx]
461+ val word = it.theWords [wordIdx]
459462 spanEnd = word.charRange.last + 1 // get exclusive end
460463 val gradientEndTime = min(
461464 lastTs.toFloat() - timeOffsetForUse,
@@ -481,11 +484,11 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
481484 it.layout.getLineForOffset(word.charRange.endInclusive)
482485 val firstCharOnStartLine = it.layout.getLineStart(wordStartLine)
483486 val lastCharOnEndLineExcl = it.layout.getLineEnd(wordEndLine)
484- realGradientStart = it.line.words .lastOrNull {
487+ realGradientStart = it.theWords .lastOrNull {
485488 it.charRange.first >= firstCharOnStartLine && it.charRange.last <
486489 word.charRange.first && it.isRtl != word.isRtl
487490 }?.charRange?.last?.plus(1 ) ? : firstCharOnStartLine
488- realGradientEnd = it.line.words .firstOrNull {
491+ realGradientEnd = it.theWords .firstOrNull {
489492 it.charRange.first > word.charRange.last && it.charRange.last <
490493 lastCharOnEndLineExcl && it.isRtl != word.isRtl
491494 }?.charRange?.first ? : lastCharOnEndLineExcl
@@ -662,8 +665,16 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
662665 val pixels = b?.let { IntArray (it.width * it.height) }
663666 val c = b?.let { Canvas (it) }
664667 val tmpPaint = b?.let { TextPaint () }
668+ var lastNonTranslated: SemanticLyrics .LyricLine ? = null
665669 val spLines = lines.mapIndexed { i, it ->
666670 val syncedLine = syncedLines?.get(i)
671+ if (syncedLine?.isTranslated != true )
672+ lastNonTranslated = syncedLine
673+ val words = syncedLine?.words ? :
674+ if (syncedLine?.isTranslated == true && lastNonTranslated?.words != null )
675+ listOf (SemanticLyrics .Word (lastNonTranslated.timeRange, 0 .. < syncedLine.text.length,
676+ findBidirectionalBarriers(syncedLine.text).firstOrNull()?.second == true
677+ )) else null
667678 val sb = SpannableStringBuilder (it.first)
668679 val speaker = syncedLine?.speaker ? : it.second
669680 val align = if (prefs.getBooleanStrict(" lyric_center" , false ) || speaker?.isGroup == true )
@@ -694,7 +705,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
694705 val alignmentNormal = if (paragraphRtl) align == Layout .Alignment .ALIGN_OPPOSITE
695706 else align == Layout .Alignment .ALIGN_NORMAL
696707 var l: StaticLayout ? = null
697- val lineOffsets = syncedLine?. words?.map {
708+ val lineOffsets = words?.map {
698709 val ia = mutableListOf<Int >()
699710 val firstLine = layout.getLineForOffset(it.charRange.first)
700711 val lastLine = layout.getLineForOffset(it.charRange.last + 1 )
@@ -764,7 +775,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
764775 return @map ia
765776 }
766777 SbItem (layout, sb, paddingTop.dpToPx(context), paddingBottom.dpToPx(context),
767- lineOffsets, lineOffsets?.let { _ ->
778+ words, lineOffsets, lineOffsets?.let { _ ->
768779 (0 .. < layout.lineCount).map { line ->
769780 findBidirectionalBarriers(layout.text.subSequence(
770781 layout.getLineStart(line), layout.getLineEnd(line))).flatMap {
@@ -880,8 +891,9 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
880891
881892 data class SbItem (
882893 val layout : StaticLayout , val text : SpannableStringBuilder ,
883- val paddingTop : Int , val paddingBottom : Int , val words : List <List <Int >>? ,
884- val rlm : List <Int >? , val speaker : SpeakerEntity ? , val line : SemanticLyrics .LyricLine ?
894+ val paddingTop : Int , val paddingBottom : Int , val theWords : List <SemanticLyrics .Word >? ,
895+ val words : List <List <Int >>? , val rlm : List <Int >? , val speaker : SpeakerEntity ? ,
896+ val line : SemanticLyrics .LyricLine ?
885897 )
886898
887899}
0 commit comments