Skip to content

Commit

Permalink
feat(UX): add haptic feedback on long press
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Apr 10, 2024
1 parent 2f26e4f commit 14ca8c4
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -41,6 +43,7 @@ fun AccountScreen(
viewModel: AccountViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current

val coroutineScope = rememberCoroutineScope()

Expand All @@ -63,6 +66,7 @@ fun AccountScreen(
navController.navigate("online_playlist/${item.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
Expand Down Expand Up @@ -95,6 +97,7 @@ fun AlbumScreen(
val context = LocalContext.current
val menuState = LocalMenuState.current
val database = LocalDatabase.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -460,6 +463,7 @@ fun AlbumScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
SongMenu(
originalSong = songWrapper.item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand All @@ -51,6 +53,7 @@ fun ExploreScreen(
viewModel: ExploreViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -99,6 +102,7 @@ fun ExploreScreen(
navController.navigate("album/${album.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubeAlbumMenu(
albumItem = album,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -49,6 +51,7 @@ fun HistoryScreen(
viewModel: HistoryViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -121,6 +124,7 @@ fun HistoryScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
SongMenu(
originalSong = event.song,
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/zionhuang/music/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -67,6 +69,7 @@ fun HomeScreen(
) {
val menuState = LocalMenuState.current
val database = LocalDatabase.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -245,6 +248,7 @@ fun HomeScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
SongMenu(
originalSong = song!!,
Expand Down Expand Up @@ -285,6 +289,7 @@ fun HomeScreen(
navController.navigate("artist/${keepListeningArtists!![it].id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
ArtistMenu(
originalArtist = keepListeningArtists!![it],
Expand Down Expand Up @@ -328,6 +333,7 @@ fun HomeScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
SongMenu(
originalSong = keepListeningSongs!![it - 10],
Expand Down Expand Up @@ -378,6 +384,7 @@ fun HomeScreen(

},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
when (item) {
is PlaylistItem -> YouTubePlaylistMenu(
Expand Down Expand Up @@ -465,6 +472,7 @@ fun HomeScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
SongMenu(
originalSong = song!!,
Expand Down Expand Up @@ -510,6 +518,7 @@ fun HomeScreen(
navController.navigate("online_playlist/${playlist.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = playlist,
Expand Down Expand Up @@ -554,6 +563,7 @@ fun HomeScreen(
navController.navigate("online_playlist/${album.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = album,
Expand Down Expand Up @@ -601,6 +611,7 @@ fun HomeScreen(
navController.navigate("online_playlist/${playlist.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = playlist,
Expand Down Expand Up @@ -649,6 +660,7 @@ fun HomeScreen(

},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
when (item) {
is PlaylistItem -> YouTubePlaylistMenu(
Expand Down Expand Up @@ -704,6 +716,7 @@ fun HomeScreen(
navController.navigate("online_playlist/${playlist.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = playlist,
Expand Down Expand Up @@ -748,6 +761,7 @@ fun HomeScreen(
navController.navigate("online_playlist/${album.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = album,
Expand Down Expand Up @@ -797,6 +811,7 @@ fun HomeScreen(
navController.navigate("online_playlist/${playlist.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = playlist,
Expand Down Expand Up @@ -845,6 +860,7 @@ fun HomeScreen(

},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
when (item) {
is PlaylistItem -> YouTubePlaylistMenu(
Expand Down Expand Up @@ -898,6 +914,7 @@ fun HomeScreen(
navController.navigate("album/${album.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubeAlbumMenu(
albumItem = album,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -42,6 +44,7 @@ fun NewReleaseScreen(
viewModel: NewReleaseViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -70,6 +73,7 @@ fun NewReleaseScreen(
navController.navigate("album/${album.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubeAlbumMenu(
albumItem = album,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -53,6 +55,7 @@ fun StatsScreen(
viewModel: StatsViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -132,6 +135,7 @@ fun StatsScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
SongMenu(
originalSong = song,
Expand Down Expand Up @@ -167,6 +171,7 @@ fun StatsScreen(
navController.navigate("artist/${artist.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
ArtistMenu(
originalArtist = artist,
Expand Down Expand Up @@ -208,6 +213,7 @@ fun StatsScreen(
navController.navigate("album/${album.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
AlbumMenu(
originalAlbum = album,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEach
Expand Down Expand Up @@ -74,6 +76,7 @@ fun YouTubeBrowseScreen(
viewModel: YouTubeBrowseViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -212,6 +215,7 @@ fun YouTubeBrowseScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
when (item) {
is SongItem -> YouTubeSongMenu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -61,6 +63,7 @@ fun ArtistItemsScreen(
viewModel: ArtistItemsViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val haptic = LocalHapticFeedback.current
val playerConnection = LocalPlayerConnection.current ?: return
val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()
Expand Down Expand Up @@ -203,6 +206,7 @@ fun ArtistItemsScreen(
}
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
when (item) {
is SongItem -> YouTubeSongMenu(
Expand Down
Loading

0 comments on commit 14ca8c4

Please sign in to comment.