Skip to content

Commit

Permalink
Enable haptics for long-clicking in gallery viewer (fixes #1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Aug 25, 2024
1 parent e69b349 commit 5a2cf2f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/main/assets/changelog-alpha.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Fix "Malformed URL" error for Imgur images (thanks to Alexey Rochev)
Remove red background/border behind transparent images in the gallery
Gallery theme fixes for devices which forcibly modify app colors in dark mode
Fix for swiping between images when "Automatically open first album image" is enabled
Enable haptics for long-clicking in gallery viewer

/Alpha 356 (2024-08-18)
Preference change: video playback controls now enabled by default (Settings > Images/Video > Enable video playback controls)
Expand Down
1 change: 1 addition & 0 deletions src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Fix "Malformed URL" error for Imgur images (thanks to Alexey Rochev)
Remove red background/border behind transparent images in the gallery
Gallery theme fixes for devices which forcibly modify app colors in dark mode
Fix for swiping between images when "Automatically open first album image" is enabled
Enable haptics for long-clicking in gallery viewer

112/1.24
Improved gallery viewer with card, list, and grid modes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.quantumbadger.redreader.compose.theme

import android.app.Activity
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -31,7 +33,10 @@ import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -376,3 +381,32 @@ fun TextStyle.StyledText(
maxLines = maxLines
)
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Modifier.combinedClickableWithHaptics(
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onDoubleClick: (() -> Unit)? = null,
onClick: () -> Unit
): Modifier {
val haptics = LocalHapticFeedback.current

return this.combinedClickable(
enabled = enabled,
onClickLabel = onClickLabel,
role = role,
onLongClickLabel = onLongClickLabel,
onLongClick = onLongClick?.let {
{
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
it()
}
},
onDoubleClick = onDoubleClick,
onClick = onClick
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package org.quantumbadger.redreader.compose.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
Expand Down Expand Up @@ -49,11 +47,11 @@ import org.quantumbadger.redreader.compose.ctx.RRComposeContextTest
import org.quantumbadger.redreader.compose.prefs.LocalComposePrefs
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
import org.quantumbadger.redreader.compose.theme.StyledText
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
import org.quantumbadger.redreader.image.ImageInfo
import org.quantumbadger.redreader.image.ImageSize
import org.quantumbadger.redreader.image.ImageUrlInfo

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun AlbumCard(
index: Int,
Expand Down Expand Up @@ -108,9 +106,9 @@ fun AlbumCard(
.shadow(3.dp, shape)
.clip(shape)
.background(theme.postCard.backgroundColor)
.combinedClickable(
.combinedClickableWithHaptics(
onClick = { onClick(index) },
onLongClick = { onLongClick(index) }
onLongClick = { onLongClick(index) },
)
) {
Column(Modifier.fillMaxWidth()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ package org.quantumbadger.redreader.compose.ui
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -48,12 +46,12 @@ import org.quantumbadger.redreader.compose.ctx.RRComposeContextTest
import org.quantumbadger.redreader.compose.prefs.LocalComposePrefs
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
import org.quantumbadger.redreader.compose.theme.StyledText
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
import org.quantumbadger.redreader.image.ImageInfo
import org.quantumbadger.redreader.image.ImageSize
import org.quantumbadger.redreader.image.ImageUrlInfo
import java.util.Locale

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun AlbumListItem(
index: Int,
Expand All @@ -72,7 +70,7 @@ fun AlbumListItem(
modifier = Modifier
.fillMaxWidth()
.background(theme.postCard.backgroundColor)
.combinedClickable(
.combinedClickableWithHaptics(
onClick = { onClick(index) },
onLongClick = { onLongClick(index) }
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -89,6 +87,7 @@ import org.quantumbadger.redreader.compose.net.fetchAlbum
import org.quantumbadger.redreader.compose.prefs.LocalComposePrefs
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
import org.quantumbadger.redreader.compose.theme.StyledText
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics
import org.quantumbadger.redreader.image.AlbumInfo
import org.quantumbadger.redreader.image.ImageInfo
import org.quantumbadger.redreader.settings.types.AlbumViewMode
Expand Down Expand Up @@ -157,7 +156,6 @@ private fun DoOnce(input: AlbumInfo, action: () -> Unit) {
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun AlbumScreen(
onBackPressed: () -> Unit,
Expand Down Expand Up @@ -373,7 +371,7 @@ fun AlbumScreen(

NetImage(
modifier = Modifier
.combinedClickable(
.combinedClickableWithHaptics(
onClick = { itemClickHandler(it) },
onLongClick = { itemLongClickListener(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

package org.quantumbadger.redreader.compose.ui

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.border
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -45,8 +43,8 @@ import org.quantumbadger.redreader.compose.ctx.RRComposeContextTest
import org.quantumbadger.redreader.compose.theme.ComposeThemeLinkButton
import org.quantumbadger.redreader.compose.theme.LocalComposeTheme
import org.quantumbadger.redreader.compose.theme.StyledText
import org.quantumbadger.redreader.compose.theme.combinedClickableWithHaptics

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun RRLinkButton(
title: String,
Expand All @@ -61,7 +59,7 @@ fun RRLinkButton(
.semantics(mergeDescendants = true) {}
.border(theme.borderThickness, theme.borderColor, theme.shape)
.clip(theme.shape)
.combinedClickable(
.combinedClickableWithHaptics(
role = Role.Button,
onClick = { launch(Dest.Link(link)) },
onLongClick = { launch(Dest.LinkLongClick(link)) }
Expand Down

0 comments on commit 5a2cf2f

Please sign in to comment.