Skip to content

Commit

Permalink
fix: popuwindow cant hide
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTFtrue committed Jan 29, 2024
1 parent 5b3f8d2 commit 796ac07
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions app/src/main/java/com/ztftrue/music/ui/play/LyricsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fun LyricsView(
val listState = rememberLazyListState()
var currentI by remember { mutableIntStateOf(0) }
var isSelected by remember { mutableStateOf(true) }
var showMenu by remember { mutableStateOf(false) }
LaunchedEffect(musicViewModel.sliderPosition.floatValue) {
val timeState = musicViewModel.sliderPosition.floatValue

Expand All @@ -80,7 +81,7 @@ fun LyricsView(
if (entry.timeStart > timeState) {
if (currentI != index) {
currentI = index
if (musicViewModel.autoScroll.value && isSelected) {
if (musicViewModel.autoScroll.value && isSelected && !showMenu) {
launch(Dispatchers.Main) {
// TODO calculate the scroll position by 
listState.scrollToItem(
Expand All @@ -104,7 +105,7 @@ fun LyricsView(
}
if (cIndex >= 0 && cIndex != currentI) {
currentI = cIndex
if (musicViewModel.autoScroll.value && isSelected) {
if (musicViewModel.autoScroll.value && isSelected && !showMenu) {
launch(Dispatchers.Main) {
// TODO calculate the scroll position by 
listState.scrollToItem(if ((currentI - 1) < 0) 0 else (currentI - 1), 0)
Expand All @@ -116,7 +117,7 @@ fun LyricsView(
if (musicViewModel.currentCaptionList.getOrElse(currentI) {
Caption("", 0)
}.text.isNotBlank()) {
if (musicViewModel.autoScroll.value && isSelected) {
if (musicViewModel.autoScroll.value && isSelected && !showMenu) {
launch(Dispatchers.Main) {
listState.scrollToItem(if ((currentI - 1) < 0) 0 else (currentI - 1), 0)
}
Expand All @@ -125,7 +126,7 @@ fun LyricsView(
}

}
var showMenu by remember { mutableStateOf(false) }

var word by remember {
mutableStateOf("")
}
Expand Down Expand Up @@ -255,7 +256,6 @@ fun LyricsView(
) {
items(musicViewModel.currentCaptionList.size) {
val tex = musicViewModel.currentCaptionList[it].text

val annotatedString = buildAnnotatedString {
for (text in tex.split(Regex("[\\n\\r\\s]+"))) {
val pattern = Regex("[,:;.\"]")
Expand All @@ -269,8 +269,6 @@ fun LyricsView(
pop()
}
}


ClickableText(
text = annotatedString,
style = TextStyle(
Expand All @@ -287,15 +285,21 @@ fun LyricsView(
size.value = sizeIt
},
onClick = { offset ->
val annotations =
annotatedString.getStringAnnotations(offset, offset)
annotations.firstOrNull()?.let { itemAnnotations ->
if (itemAnnotations.tag == "word") {
word = itemAnnotations.item
showMenu = true
}
if (showMenu) {
showMenu = false
} else {
val annotations =
annotatedString.getStringAnnotations(offset, offset)
annotations.firstOrNull()?.let { itemAnnotations ->
if (itemAnnotations.tag == "word") {
word = itemAnnotations.item
showMenu = true
} else {

}
}
}

})
}
}
Expand Down

0 comments on commit 796ac07

Please sign in to comment.