feat: lut name overlay
This commit is contained in:
1 parent
b9479a70e5
commit
c77c98606d
5 files changed
+132
-14
No files matched your search
@@ -211,6 +211,7 @@ fun CameraScreen(
|
||||
val focusPeakingEnabled by viewModel.focusPeakingEnabled.collectAsState(initial = true)
|
||||
val keepScreenOn by viewModel.keepScreenOn.collectAsState(initial = false)
|
||||
val currentLutId by viewModel.currentLutId.collectAsState()
|
||||
val lutNameOverlayState = rememberLutNameOverlayState()
|
||||
val currentRecipeParams by viewModel.currentRecipeParams.collectAsState()
|
||||
val lutSelectorMode by viewModel.lutSelectorMode.collectAsState()
|
||||
val currentEffectParams by viewModel.currentEffectParams.collectAsState()
|
||||
@@ -985,11 +986,14 @@ fun CameraScreen(
|
||||
} else {
|
||||
// onDragEnd logic
|
||||
if (abs(totalDrag) > 100) {
|
||||
if (totalDrag > 0) {
|
||||
val selectedLut = if (totalDrag > 0) {
|
||||
viewModel.switchToPreviousLut()
|
||||
} else {
|
||||
viewModel.switchToNextLut()
|
||||
}
|
||||
selectedLut?.let {
|
||||
lutNameOverlayState.show(it.getName())
|
||||
}
|
||||
}
|
||||
totalDrag = 0f
|
||||
viewModel.isZooming = false
|
||||
@@ -1220,6 +1224,11 @@ fun CameraScreen(
|
||||
radius = if (isVideoMode) 0.dp else 4.dp,
|
||||
color = Color.Black
|
||||
)
|
||||
|
||||
LutNameOverlay(
|
||||
state = lutNameOverlayState,
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
)
|
||||
}
|
||||
if (isPhotoStyleMode) {
|
||||
parameterRuler()
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.hinnka.mycamera.ui.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private const val LutNameOverlayDurationMillis = 1_000L
|
||||
|
||||
@Stable
|
||||
class LutNameOverlayState internal constructor(
|
||||
private val coroutineScope: CoroutineScope,
|
||||
) {
|
||||
var name by mutableStateOf("")
|
||||
private set
|
||||
|
||||
var visible by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
private var hideJob: Job? = null
|
||||
|
||||
fun show(name: String) {
|
||||
if (name.isBlank()) return
|
||||
|
||||
this.name = name
|
||||
visible = true
|
||||
hideJob?.cancel()
|
||||
hideJob = coroutineScope.launch {
|
||||
delay(LutNameOverlayDurationMillis)
|
||||
visible = false
|
||||
hideJob = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberLutNameOverlayState(): LutNameOverlayState {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
return remember(coroutineScope) {
|
||||
LutNameOverlayState(coroutineScope)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LutNameOverlay(
|
||||
state: LutNameOverlayState,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = state.visible,
|
||||
modifier = modifier,
|
||||
enter = fadeIn(animationSpec = tween(durationMillis = 150)),
|
||||
exit = fadeOut(animationSpec = tween(durationMillis = 250)),
|
||||
) {
|
||||
Surface(
|
||||
color = Color.Black.copy(alpha = 0.32f),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
shadowElevation = 4.dp,
|
||||
) {
|
||||
Text(
|
||||
text = state.name,
|
||||
color = Color.White,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,7 @@ fun GalleryEditScreen(
|
||||
val editPhotoRecipeParams by viewModel.editPhotoRecipeParams.collectAsState()
|
||||
val editLutConfig = viewModel.editLutConfig
|
||||
val availableLuts = viewModel.availableLuts
|
||||
val lutNameOverlayState = rememberLutNameOverlayState()
|
||||
val showPaymentDialog = viewModel.showPaymentDialog
|
||||
val isPurchased by viewModel.isPurchased.collectAsState()
|
||||
val categoryOrder by viewModel.categoryOrder.collectAsState()
|
||||
@@ -648,11 +649,14 @@ fun GalleryEditScreen(
|
||||
detectHorizontalDragGestures(
|
||||
onDragEnd = {
|
||||
if (kotlin.math.abs(totalDrag) > 100) {
|
||||
if (totalDrag > 0) {
|
||||
val selectedLut = if (totalDrag > 0) {
|
||||
viewModel.switchToPreviousLut()
|
||||
} else {
|
||||
viewModel.switchToNextLut()
|
||||
}
|
||||
selectedLut?.let {
|
||||
lutNameOverlayState.show(it.getName())
|
||||
}
|
||||
}
|
||||
totalDrag = 0f
|
||||
},
|
||||
@@ -785,6 +789,11 @@ fun GalleryEditScreen(
|
||||
modifier = Modifier.size(48.dp)
|
||||
)
|
||||
}
|
||||
|
||||
LutNameOverlay(
|
||||
state = lutNameOverlayState,
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
)
|
||||
}
|
||||
|
||||
AnimatedVisibility(
|
||||
|
||||
@@ -3565,23 +3565,27 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
/**
|
||||
* 切换到下一个滤镜
|
||||
*/
|
||||
fun switchToNextLut() {
|
||||
if (availableLutList.isEmpty()) return
|
||||
fun switchToNextLut(): LutInfo? {
|
||||
if (availableLutList.isEmpty()) return null
|
||||
val currentIndex = availableLutList.indexOfFirst { it.id == currentLutId.value }
|
||||
val nextIndex = if (currentIndex == -1 || currentIndex == availableLutList.size - 1) 0 else currentIndex + 1
|
||||
setLut(availableLutList[nextIndex].id)
|
||||
val nextLut = availableLutList[nextIndex]
|
||||
setLut(nextLut.id)
|
||||
vibrationHelper.vibrate()
|
||||
return nextLut
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换到上一个滤镜
|
||||
*/
|
||||
fun switchToPreviousLut() {
|
||||
if (availableLutList.isEmpty()) return
|
||||
fun switchToPreviousLut(): LutInfo? {
|
||||
if (availableLutList.isEmpty()) return null
|
||||
val currentIndex = availableLutList.indexOfFirst { it.id == currentLutId.value }
|
||||
val prevIndex = if (currentIndex <= 0) availableLutList.size - 1 else currentIndex - 1
|
||||
setLut(availableLutList[prevIndex].id)
|
||||
val previousLut = availableLutList[prevIndex]
|
||||
setLut(previousLut.id)
|
||||
vibrationHelper.vibrate()
|
||||
return previousLut
|
||||
}
|
||||
|
||||
fun updateLut() {
|
||||
|
||||
@@ -2155,20 +2155,24 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun switchToNextLut() {
|
||||
if (availableLuts.isEmpty()) return
|
||||
fun switchToNextLut(): LutInfo? {
|
||||
if (availableLuts.isEmpty()) return null
|
||||
val currentLut = editLutId.value
|
||||
val currentIndex = availableLuts.indexOfFirst { it.id == currentLut }
|
||||
val nextIndex = (currentIndex + 1) % availableLuts.size
|
||||
setEditLut(availableLuts[nextIndex].id)
|
||||
val nextLut = availableLuts[nextIndex]
|
||||
setEditLut(nextLut.id)
|
||||
return nextLut
|
||||
}
|
||||
|
||||
fun switchToPreviousLut() {
|
||||
if (availableLuts.isEmpty()) return
|
||||
fun switchToPreviousLut(): LutInfo? {
|
||||
if (availableLuts.isEmpty()) return null
|
||||
val currentLut = editLutId.value
|
||||
val currentIndex = availableLuts.indexOfFirst { it.id == currentLut }
|
||||
val prevIndex = if (currentIndex <= 0) availableLuts.size - 1 else currentIndex - 1
|
||||
setEditLut(availableLuts[prevIndex].id)
|
||||
val previousLut = availableLuts[prevIndex]
|
||||
setEditLut(previousLut.id)
|
||||
return previousLut
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user