Skip to content

Commit

Permalink
refactor: move select logic to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcarter11 committed Jan 6, 2025
1 parent 4a36270 commit 5b3f17d
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 59 deletions.
36 changes: 13 additions & 23 deletions app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ fun GridItem(
fun SongListItem(
song: Song,
onPlay: () -> Unit,
onSelectModeActivation : () -> Unit,
inSelectMode : Boolean,
selectionIds: MutableList<String>?,
onSelectedChange: (Boolean) -> Unit,
inSelectMode: Boolean?,
isSelected: Boolean,
navController: NavController,
modifier: Modifier = Modifier,
enableSwipeToQueue: Boolean = true,
Expand All @@ -366,8 +366,8 @@ fun SongListItem(
showInLibraryIcon: Boolean = true,
showDownloadIcon: Boolean = true,
showLocalIcon: Boolean = true,
playlistSong : PlaylistSong? = null,
playlistBrowseId : String? = null,
playlistSong: PlaylistSong? = null,
playlistBrowseId: String? = null,
showDragHandle: Boolean = false,
dragHandleModifier: Modifier? = null,
disableShowMenu: Boolean = false,
Expand All @@ -385,15 +385,6 @@ fun SongListItem(

val snackbarHostState = remember { SnackbarHostState() }

val isSelected = selectionIds?.contains(song.id) == true
val onCheckedChange: (Boolean) -> Unit = {
if (it) {
selectionIds?.add(song.id)
} else {
selectionIds?.remove(song.id)
}
}

val listItem: @Composable () -> Unit = {
ListItem(
title = song.song.title,
Expand Down Expand Up @@ -429,10 +420,10 @@ fun SongListItem(
},
trailingContent = {
if (available) {
if (inSelectMode) {
if (inSelectMode == true) {
Checkbox(
checked = isSelected,
onCheckedChange = onCheckedChange
onCheckedChange = onSelectedChange
)
} else {
IconButton(
Expand Down Expand Up @@ -471,14 +462,14 @@ fun SongListItem(
}
}
},
isSelected = inSelectMode && isSelected,
isSelected = inSelectMode == true && isSelected,
isActive = isActive,
available = available,
modifier = modifier.combinedClickable(
onClick = {
if (available) {
if (inSelectMode) {
onCheckedChange(!isSelected)
if (inSelectMode == true) {
onSelectedChange(!isSelected)
} else if (song.id == mediaMetadata?.id) {
playerConnection.player.togglePlayPause()
} else {
Expand All @@ -488,7 +479,7 @@ fun SongListItem(
},
onLongClick = {
if (available) {
if (selectionIds == null) {
if (inSelectMode == null){
menuState.show {
SongMenu(
originalSong = song,
Expand All @@ -497,10 +488,9 @@ fun SongListItem(
)
}
}
if (!inSelectMode) {
else if (!inSelectMode) {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
onSelectModeActivation()
onCheckedChange(true)
onSelectedChange(true)
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/dd3boh/outertune/ui/screens/AlbumScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,16 @@ fun AlbumScreen(
)
)
},
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(song.id)
} else {
selection.remove(song.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(song.id),
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,16 @@ fun HistoryScreen(
)
)
},
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(event.event.id)
} else {
selection.remove(event.event.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(event.event.id),
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/dd3boh/outertune/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ fun HomeScreen(
onPlay = {
playerConnection.playQueue(YouTubeQueue.radio(song!!.toMediaMetadata()))
},
onSelectModeActivation = {},
inSelectMode = false,
selectionIds = null,
onSelectedChange = {},
inSelectMode = null,
isSelected = false,
navController = navController,
modifier = Modifier.width(horizontalLazyGridItemWidth)
)
Expand Down Expand Up @@ -509,9 +509,9 @@ fun HomeScreen(
onPlay = {
playerConnection.playQueue(YouTubeQueue.radio(song!!.toMediaMetadata()))
},
onSelectModeActivation = {},
inSelectMode = false,
selectionIds = null,
onSelectedChange = {},
inSelectMode = null,
isSelected = false,
navController = navController,
modifier = Modifier.width(horizontalLazyGridItemWidth)
)
Expand Down Expand Up @@ -642,9 +642,9 @@ fun HomeScreen(
onPlay = {
playerConnection.playQueue(YouTubeQueue.radio(song!!.toMediaMetadata()))
},
onSelectModeActivation = {},
inSelectMode = false,
selectionIds = null,
onSelectedChange = {},
inSelectMode = null,
isSelected = false,
navController = navController,
modifier = Modifier.width(horizontalLazyGridItemWidth)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.compose.material.icons.rounded.Backup
import androidx.compose.material.icons.rounded.Contrast
import androidx.compose.material.icons.rounded.DarkMode
import androidx.compose.material.icons.rounded.Lyrics
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material.icons.rounded.MusicVideo
import androidx.compose.material.icons.rounded.NotInterested
import androidx.compose.material.icons.rounded.Palette
Expand Down Expand Up @@ -596,9 +595,9 @@ fun SetupWizard(
SongListItem(
song = song,
onPlay = {},
inSelectMode = false,
selectionIds = mutableListOf(),
onSelectModeActivation = {},
onSelectedChange = {},
inSelectMode = null,
isSelected = false,
navController = navController,
enableSwipeToQueue = false,
disableShowMenu = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ fun StatsScreen(
YouTubeQueue.radio(song.toMediaMetadata())
)
},
onSelectModeActivation = {},
onSelectedChange = {},
inSelectMode = false,
selectionIds = null,
isSelected = false,
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ fun ArtistScreen(
)
)
},
onSelectModeActivation = { },
onSelectedChange = { },
inSelectMode = false,
selectionIds = null,
isSelected = false,
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,16 @@ fun ArtistSongsScreen(
}
}
},
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(song.id)
} else {
selection.remove(song.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(song.id),
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ import com.dd3boh.outertune.ui.component.SelectHeader
import com.dd3boh.outertune.ui.component.SongFolderItem
import com.dd3boh.outertune.ui.component.SongListItem
import com.dd3boh.outertune.ui.component.SortHeader
import com.dd3boh.outertune.ui.component.SwipeToQueueBox
import com.dd3boh.outertune.ui.menu.SongMenu
import com.dd3boh.outertune.utils.numberToAlpha
import com.dd3boh.outertune.utils.rememberEnumPreference
import com.dd3boh.outertune.utils.rememberPreference
Expand All @@ -83,7 +81,7 @@ import java.util.Stack
fun LibraryFoldersScreen(
navController: NavController,
viewModel: LibrarySongsViewModel = hiltViewModel(),
filterContent: @Composable() (() -> Unit)? = null
filterContent: @Composable (() -> Unit)? = null
) {
val menuState = LocalMenuState.current
val database = LocalDatabase.current
Expand Down Expand Up @@ -325,9 +323,16 @@ fun LibraryFoldersScreen(
)
)
},
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(song.id)
} else {
selection.remove(song.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(song.id),
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,16 @@ fun LibrarySongsScreen(
)
)
},
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(song.id)
} else {
selection.remove(song.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(song.id),
navController = navController,
modifier = Modifier.fillMaxWidth().animateItem()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,16 @@ fun AutoPlaylistScreen(
},
showLikedIcon = playlistType != PlaylistType.LIKE,
showDownloadIcon = playlistType != PlaylistType.DOWNLOAD,
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(song.id)
} else {
selection.remove(song.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(song.id),
navController = navController,
modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.background),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,16 @@ fun LocalPlaylistScreen(
},
showDragHandle = sortType == PlaylistSongSortType.CUSTOM && !locked && editable,
dragHandleModifier = Modifier.draggableHandle(),
onSelectModeActivation = { inSelectMode = true },
onSelectedChange = {
inSelectMode = true
if (it) {
selection.add(song.song.id)
} else {
selection.remove(song.song.id)
}
},
inSelectMode = inSelectMode,
selectionIds = selection,
isSelected = selection.contains(song.song.id),
navController = navController,
modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.background),
playlistSong = song,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ fun LocalSearchScreen(
startIndex = songs.indexOfFirst { it.id == item.id }
))
},
onSelectModeActivation = { },
onSelectedChange = { },
inSelectMode = false,
selectionIds = null,
isSelected = false,
navController = navController,
modifier = Modifier.animateItem()
)
Expand Down

0 comments on commit 5b3f17d

Please sign in to comment.