Skip to content

Commit

Permalink
Improve haptics
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 9, 2025
1 parent 7ad8e1d commit c4599b9
Show file tree
Hide file tree
Showing 46 changed files with 112 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -68,10 +67,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -91,6 +88,7 @@ import ru.tech.imageresizershrinker.core.ui.theme.outlineVariant
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedModalBottomSheet
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.image.Picture
import ru.tech.imageresizershrinker.core.ui.widget.modifier.ContainerShapeDefaults
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
Expand All @@ -113,7 +111,6 @@ internal fun FilterSelectionCubeLutBottomContent(
) {
cubeLutRemoteResources?.let { resources ->
val context = LocalContext.current
val haptics = LocalHapticFeedback.current

var showSelection by rememberSaveable {
mutableStateOf(false)
Expand All @@ -131,10 +128,7 @@ internal fun FilterSelectionCubeLutBottomContent(
resultPadding = 0.dp,
shape = shape
)
.clickable {
haptics.performHapticFeedback(
HapticFeedbackType.Companion.LongPress
)
.hapticsClickable {
if (resources.list.isEmpty()) {
onShowDownloadDialog(false, false)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.animation.scaleOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -55,10 +54,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil3.compose.rememberAsyncImagePainter
Expand All @@ -80,6 +77,7 @@ import ru.tech.imageresizershrinker.core.ui.theme.outlineVariant
import ru.tech.imageresizershrinker.core.ui.utils.helper.ContextUtils.isNetworkAvailable
import ru.tech.imageresizershrinker.core.ui.utils.helper.toImageModel
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.shimmer
import ru.tech.imageresizershrinker.core.ui.widget.modifier.transparencyChecker
import ru.tech.imageresizershrinker.core.ui.widget.other.LocalToastHostState
Expand All @@ -104,8 +102,6 @@ internal fun FilterSelectionItem(
onCubeLutDownloadRequest: (forceUpdate: Boolean, downloadOnlyNewData: Boolean) -> Unit = { _, _ -> },
previewModel: ImageModel = remember { R.drawable.filter_preview_source.toImageModel() }
) {
val haptics = LocalHapticFeedback.current

val toastHostState = LocalToastHostState.current
val scope = rememberCoroutineScope()
val context = LocalContext.current
Expand Down Expand Up @@ -172,12 +168,7 @@ internal fun FilterSelectionItem(
modifier = Modifier
.size(36.dp)
.clip(CircleShape)
.clickable {
haptics.performHapticFeedback(
HapticFeedbackType.LongPress
)
onOpenPreview()
},
.hapticsClickable(onClick = onOpenPreview),
contentAlignment = Alignment.Center
) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ru.tech.imageresizershrinker.core.filters.presentation.widget

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -45,10 +44,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil3.compose.rememberAsyncImagePainter
Expand All @@ -68,6 +65,7 @@ import ru.tech.imageresizershrinker.core.ui.theme.White
import ru.tech.imageresizershrinker.core.ui.theme.outlineVariant
import ru.tech.imageresizershrinker.core.ui.utils.helper.toImageModel
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.shimmer
import ru.tech.imageresizershrinker.core.ui.widget.modifier.transparencyChecker
import ru.tech.imageresizershrinker.core.ui.widget.preferences.PreferenceItemOverload
Expand Down Expand Up @@ -131,17 +129,11 @@ internal fun TemplateFilterSelectionItem(
.transparencyChecker()
.shimmer(loading)
)
val haptics = LocalHapticFeedback.current
Box(
modifier = Modifier
.size(36.dp)
.clip(CircleShape)
.clickable {
haptics.performHapticFeedback(
HapticFeedbackType.LongPress
)
onLongClick()
},
.hapticsClickable(onClick = onLongClick),
contentAlignment = Alignment.Center
) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ru.tech.imageresizershrinker.core.filters.presentation.widget.addFilters

import android.graphics.Bitmap
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -68,6 +67,7 @@ import ru.tech.imageresizershrinker.core.ui.widget.buttons.ShareButton
import ru.tech.imageresizershrinker.core.ui.widget.controls.selection.ImageSelector
import ru.tech.imageresizershrinker.core.ui.widget.dialogs.OneTimeSaveLocationSelectionDialog
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.image.Picture
import ru.tech.imageresizershrinker.core.ui.widget.modifier.ContainerShapeDefaults
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
Expand Down Expand Up @@ -159,7 +159,7 @@ internal fun OtherContent(
modifier = Modifier
.weight(1f)
.clip(shape)
.clickable {
.hapticsClickable {
component.setFilterPreviewModel(
index.toString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package ru.tech.imageresizershrinker.core.ui.widget.buttons

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
Expand All @@ -33,10 +32,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.unit.dp
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable

@Composable
fun SupportingButton(
Expand All @@ -46,7 +44,6 @@ fun SupportingButton(
containerColor: Color = MaterialTheme.colorScheme.secondaryContainer,
contentColor: Color = MaterialTheme.colorScheme.contentColorFor(containerColor)
) {
val haptics = LocalHapticFeedback.current
Icon(
imageVector = icon,
contentDescription = icon.name,
Expand All @@ -57,12 +54,7 @@ fun SupportingButton(
shape = CircleShape
)
.clip(CircleShape)
.clickable {
haptics.performHapticFeedback(
HapticFeedbackType.TextHandleMove
)
onClick()
}
.hapticsClickable(onClick = onClick)
.padding(1.dp)
.size(
with(LocalDensity.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package ru.tech.imageresizershrinker.core.ui.widget.color_picker
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -92,6 +91,7 @@ import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedModalBottomSheet
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedModalSheetDragHandle
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedSliderItem
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.palette_selection.PaletteStyleSelection
import ru.tech.imageresizershrinker.core.ui.widget.preferences.PreferenceRowSwitch
Expand Down Expand Up @@ -459,7 +459,7 @@ fun AvailableColorTuplesSheet(
borderColor = MaterialTheme.colorScheme.outlineVariant(0.2f),
resultPadding = 0.dp
)
.clickable { onOpenColorPicker() }
.hapticsClickable(onClick = onOpenColorPicker)
.padding(3.dp)
.clip(CircleShape),
backgroundColor = Color.Transparent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package ru.tech.imageresizershrinker.core.ui.widget.color_picker
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -77,6 +76,7 @@ import ru.tech.imageresizershrinker.core.ui.utils.helper.ContextUtils.pasteColor
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedAlertDialog
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.modifier.transparencyChecker
import ru.tech.imageresizershrinker.core.ui.widget.text.AutoSizeText
Expand Down Expand Up @@ -204,7 +204,7 @@ fun ColorInfo(
maxLines = 1,
modifier = Modifier
.clip(RoundedCornerShape(6.dp))
.clickable {
.hapticsClickable {
expanded = true
}
.padding(4.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -81,6 +80,7 @@ import ru.tech.imageresizershrinker.core.ui.theme.inverse
import ru.tech.imageresizershrinker.core.ui.utils.helper.ContextUtils.pasteColorFromClipboard
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedModalBottomSheet
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.animateShape
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.modifier.fadingEdges
Expand Down Expand Up @@ -245,7 +245,7 @@ fun ColorSelectionRow(
)
.transparencyChecker()
.background(color, shape)
.clickable {
.hapticsClickable {
onValueChange(color)
customColor = null
},
Expand Down Expand Up @@ -332,7 +332,7 @@ fun ColorSelectionRow(
)
.transparencyChecker()
.background(color, CircleShape)
.clickable {
.hapticsClickable {
tempColor = color.toArgb()
},
contentAlignment = Alignment.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -75,6 +74,7 @@ import ru.tech.imageresizershrinker.core.ui.utils.helper.sortedByType
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedModalBottomSheet
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.image.Picture
import ru.tech.imageresizershrinker.core.ui.widget.modifier.ContainerShapeDefaults
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
Expand Down Expand Up @@ -206,7 +206,7 @@ fun ImageReorderCarousel(
),
resultPadding = 0.dp
)
.clickable {
.hapticsClickable {
val newValue = images
?.sortedByType(
sortType = item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsDraggedAsState
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -74,6 +73,7 @@ import ru.tech.imageresizershrinker.core.ui.theme.takeColorFromScheme
import ru.tech.imageresizershrinker.core.ui.utils.helper.toUiPath
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedAlertDialog
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.ContainerShapeDefaults
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.modifier.fadingEdges
Expand Down Expand Up @@ -226,7 +226,7 @@ fun OneTimeSaveLocationSelectionDialog(
autoShadowElevation = 0.dp,
resultPadding = 0.dp
)
.clickable {
.hapticsClickable {
scope.launch {
state.animateTo(RevealValue.Default)
}
Expand Down
Loading

0 comments on commit c4599b9

Please sign in to comment.