Skip to content

Commit 5a2cf2f

Browse files
committed
Enable haptics for long-clicking in gallery viewer (fixes #1220)
1 parent e69b349 commit 5a2cf2f

File tree

7 files changed

+45
-17
lines changed

7 files changed

+45
-17
lines changed

src/main/assets/changelog-alpha.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Fix "Malformed URL" error for Imgur images (thanks to Alexey Rochev)
33
Remove red background/border behind transparent images in the gallery
44
Gallery theme fixes for devices which forcibly modify app colors in dark mode
55
Fix for swiping between images when "Automatically open first album image" is enabled
6+
Enable haptics for long-clicking in gallery viewer
67

78
/Alpha 356 (2024-08-18)
89
Preference change: video playback controls now enabled by default (Settings > Images/Video > Enable video playback controls)

src/main/assets/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Fix "Malformed URL" error for Imgur images (thanks to Alexey Rochev)
33
Remove red background/border behind transparent images in the gallery
44
Gallery theme fixes for devices which forcibly modify app colors in dark mode
55
Fix for swiping between images when "Automatically open first album image" is enabled
6+
Enable haptics for long-clicking in gallery viewer
67

78
112/1.24
89
Improved gallery viewer with card, list, and grid modes

src/main/java/org/quantumbadger/redreader/compose/theme/ComposeTheme.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.quantumbadger.redreader.compose.theme
1919

2020
import android.app.Activity
21+
import androidx.compose.foundation.ExperimentalFoundationApi
22+
import androidx.compose.foundation.combinedClickable
2123
import androidx.compose.foundation.shape.RoundedCornerShape
2224
import androidx.compose.material3.MaterialTheme
2325
import androidx.compose.material3.Text
@@ -31,7 +33,10 @@ import androidx.compose.runtime.staticCompositionLocalOf
3133
import androidx.compose.ui.Modifier
3234
import androidx.compose.ui.graphics.Color
3335
import androidx.compose.ui.graphics.Shape
36+
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
37+
import androidx.compose.ui.platform.LocalHapticFeedback
3438
import androidx.compose.ui.platform.LocalView
39+
import androidx.compose.ui.semantics.Role
3540
import androidx.compose.ui.text.TextStyle
3641
import androidx.compose.ui.text.font.FontWeight
3742
import androidx.compose.ui.text.style.TextOverflow
@@ -376,3 +381,32 @@ fun TextStyle.StyledText(
376381
maxLines = maxLines
377382
)
378383
}
384+
385+
@OptIn(ExperimentalFoundationApi::class)
386+
@Composable
387+
fun Modifier.combinedClickableWithHaptics(
388+
enabled: Boolean = true,
389+
onClickLabel: String? = null,
390+
role: Role? = null,
391+
onLongClickLabel: String? = null,
392+
onLongClick: (() -> Unit)? = null,
393+
onDoubleClick: (() -> Unit)? = null,
394+
onClick: () -> Unit
395+
): Modifier {
396+
val haptics = LocalHapticFeedback.current
397+
398+
return this.combinedClickable(
399+
enabled = enabled,
400+
onClickLabel = onClickLabel,
401+
role = role,
402+
onLongClickLabel = onLongClickLabel,
403+
onLongClick = onLongClick?.let {
404+
{
405+
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
406+
it()
407+
}
408+
},
409+
onDoubleClick = onDoubleClick,
410+
onClick = onClick
411+
)
412+
}

src/main/java/org/quantumbadger/redreader/compose/ui/AlbumCard.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
package org.quantumbadger.redreader.compose.ui
1919

2020
import androidx.compose.animation.AnimatedVisibility
21-
import androidx.compose.foundation.ExperimentalFoundationApi
2221
import androidx.compose.foundation.background
23-
import androidx.compose.foundation.combinedClickable
2422
import androidx.compose.foundation.layout.Box
2523
import androidx.compose.foundation.layout.Column
2624
import androidx.compose.foundation.layout.WindowInsets
@@ -49,11 +47,11 @@ import org.quantumbadger.redreader.compose.ctx.RRComposeContextTest
4947
import org.quantumbadger.redreader.compose.prefs.LocalComposePrefs
5048
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
5149
import org.quantumbadger.redreader.compose.theme.StyledText
50+
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
5251
import org.quantumbadger.redreader.image.ImageInfo
5352
import org.quantumbadger.redreader.image.ImageSize
5453
import org.quantumbadger.redreader.image.ImageUrlInfo
5554

56-
@OptIn(ExperimentalFoundationApi::class)
5755
@Composable
5856
fun AlbumCard(
5957
index: Int,
@@ -108,9 +106,9 @@ fun AlbumCard(
108106
.shadow(3.dp, shape)
109107
.clip(shape)
110108
.background(theme.postCard.backgroundColor)
111-
.combinedClickable(
109+
.combinedClickableWithHaptics(
112110
onClick = { onClick(index) },
113-
onLongClick = { onLongClick(index) }
111+
onLongClick = { onLongClick(index) },
114112
)
115113
) {
116114
Column(Modifier.fillMaxWidth()) {

src/main/java/org/quantumbadger/redreader/compose/ui/AlbumListItem.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ package org.quantumbadger.redreader.compose.ui
2020
import androidx.compose.animation.AnimatedVisibility
2121
import androidx.compose.animation.slideInHorizontally
2222
import androidx.compose.animation.slideOutHorizontally
23-
import androidx.compose.foundation.ExperimentalFoundationApi
2423
import androidx.compose.foundation.background
25-
import androidx.compose.foundation.combinedClickable
2624
import androidx.compose.foundation.layout.Box
2725
import androidx.compose.foundation.layout.Column
2826
import androidx.compose.foundation.layout.Spacer
@@ -48,12 +46,12 @@ import org.quantumbadger.redreader.compose.ctx.RRComposeContextTest
4846
import org.quantumbadger.redreader.compose.prefs.LocalComposePrefs
4947
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
5048
import org.quantumbadger.redreader.compose.theme.StyledText
49+
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
5150
import org.quantumbadger.redreader.image.ImageInfo
5251
import org.quantumbadger.redreader.image.ImageSize
5352
import org.quantumbadger.redreader.image.ImageUrlInfo
5453
import java.util.Locale
5554

56-
@OptIn(ExperimentalFoundationApi::class)
5755
@Composable
5856
fun AlbumListItem(
5957
index: Int,
@@ -72,7 +70,7 @@ fun AlbumListItem(
7270
modifier = Modifier
7371
.fillMaxWidth()
7472
.background(theme.postCard.backgroundColor)
75-
.combinedClickable(
73+
.combinedClickableWithHaptics(
7674
onClick = { onClick(index) },
7775
onLongClick = { onLongClick(index) }
7876
),

src/main/java/org/quantumbadger/redreader/compose/ui/AlbumScreen.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ import androidx.compose.animation.fadeIn
2424
import androidx.compose.animation.fadeOut
2525
import androidx.compose.animation.slideInVertically
2626
import androidx.compose.animation.slideOutVertically
27-
import androidx.compose.foundation.ExperimentalFoundationApi
2827
import androidx.compose.foundation.background
29-
import androidx.compose.foundation.combinedClickable
3028
import androidx.compose.foundation.focusable
3129
import androidx.compose.foundation.layout.Arrangement
3230
import androidx.compose.foundation.layout.Box
@@ -89,6 +87,7 @@ import org.quantumbadger.redreader.compose.net.fetchAlbum
8987
import org.quantumbadger.redreader.compose.prefs.LocalComposePrefs
9088
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
9189
import org.quantumbadger.redreader.compose.theme.StyledText
90+
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
9291
import org.quantumbadger.redreader.image.AlbumInfo
9392
import org.quantumbadger.redreader.image.ImageInfo
9493
import org.quantumbadger.redreader.settings.types.AlbumViewMode
@@ -157,7 +156,6 @@ private fun DoOnce(input: AlbumInfo, action: () -> Unit) {
157156
}
158157
}
159158

160-
@OptIn(ExperimentalFoundationApi::class)
161159
@Composable
162160
fun AlbumScreen(
163161
onBackPressed: () -> Unit,
@@ -373,7 +371,7 @@ fun AlbumScreen(
373371

374372
NetImage(
375373
modifier = Modifier
376-
.combinedClickable(
374+
.combinedClickableWithHaptics(
377375
onClick = { itemClickHandler(it) },
378376
onLongClick = { itemLongClickListener(it) }
379377
)

src/main/java/org/quantumbadger/redreader/compose/ui/RRLinkButton.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
package org.quantumbadger.redreader.compose.ui
1919

20-
import androidx.compose.foundation.ExperimentalFoundationApi
2120
import androidx.compose.foundation.border
22-
import androidx.compose.foundation.combinedClickable
2321
import androidx.compose.foundation.layout.Column
2422
import androidx.compose.foundation.layout.Spacer
2523
import androidx.compose.foundation.layout.fillMaxWidth
@@ -45,8 +43,8 @@ import org.quantumbadger.redreader.compose.ctx.RRComposeContextTest
4543
import org.quantumbadger.redreader.compose.theme.ComposeThemeLinkButton
4644
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
4745
import org.quantumbadger.redreader.compose.theme.StyledText
46+
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
4847

49-
@OptIn(ExperimentalFoundationApi::class)
5048
@Composable
5149
fun RRLinkButton(
5250
title: String,
@@ -61,7 +59,7 @@ fun RRLinkButton(
6159
.semantics(mergeDescendants = true) {}
6260
.border(theme.borderThickness, theme.borderColor, theme.shape)
6361
.clip(theme.shape)
64-
.combinedClickable(
62+
.combinedClickableWithHaptics(
6563
role = Role.Button,
6664
onClick = { launch(Dest.Link(link)) },
6765
onLongClick = { launch(Dest.LinkLongClick(link)) }

0 commit comments

Comments
 (0)