Add synchronized lyrics (#126)
This commit is contained in:
@@ -26,6 +26,7 @@ const val repeatModeKey = "repeatMode"
|
||||
const val skipSilenceKey = "skipSilence"
|
||||
const val volumeNormalizationKey = "volumeNormalization"
|
||||
const val persistentQueueKey = "persistentQueue"
|
||||
const val isShowingSynchronizedLyricsKey = "isShowingSynchronizedLyrics"
|
||||
|
||||
inline fun <reified T : Enum<T>> SharedPreferences.getEnum(
|
||||
key: String,
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.InternalComposeApi
|
||||
import androidx.compose.runtime.LaunchedEffectImpl
|
||||
import androidx.compose.runtime.NonRestartableComposable
|
||||
import androidx.compose.runtime.RememberObserver
|
||||
import androidx.compose.runtime.currentComposer
|
||||
import androidx.compose.runtime.remember
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -21,3 +22,13 @@ fun relaunchableEffect(
|
||||
val launchedEffect = remember(key1) { LaunchedEffectImpl(applyContext, block) }
|
||||
return launchedEffect::onRemembered
|
||||
}
|
||||
|
||||
@Composable
|
||||
@NonRestartableComposable
|
||||
fun relaunchableEffect2(
|
||||
key1: Any?,
|
||||
block: suspend CoroutineScope.() -> Unit
|
||||
): RememberObserver {
|
||||
val applyContext = currentComposer.applyCoroutineContext
|
||||
return remember(key1) { LaunchedEffectImpl(applyContext, block) }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package it.vfsfitvnm.vimusic.utils
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import it.vfsfitvnm.synchronizedlyrics.parseSentences
|
||||
|
||||
class SynchronizedLyrics(text: String, private val positionProvider: () -> Long) {
|
||||
val sentences = parseSentences(text)
|
||||
|
||||
var index by mutableStateOf(currentIndex)
|
||||
private set
|
||||
|
||||
private val currentIndex: Int
|
||||
get() {
|
||||
var index = -1
|
||||
for (item in sentences) {
|
||||
if (item.first >= positionProvider()) break
|
||||
index++
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
fun update(): Boolean {
|
||||
val newIndex = currentIndex
|
||||
return if (newIndex != index) {
|
||||
index = newIndex
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user