Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify queue multiselect look with playlist screen (reopenend) #237

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions app/src/main/java/com/malopieds/innertune/ui/component/Items.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ fun PlaylistGridItem(
fun MediaMetadataListItem(
mediaMetadata: MediaMetadata,
modifier: Modifier,
isSelected: Boolean = false,
isActive: Boolean = false,
isPlaying: Boolean = false,
trailingContent: @Composable RowScope.() -> Unit = {},
Expand All @@ -1127,26 +1128,49 @@ fun MediaMetadataListItem(
makeTimeString(mediaMetadata.duration * 1000L),
),
thumbnailContent = {
AsyncImage(
model = mediaMetadata.thumbnailUrl,
contentDescription = null,
modifier =
Modifier
.size(ListThumbnailSize)
.clip(RoundedCornerShape(ThumbnailCornerRadius)),
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(ListThumbnailSize),
) {
if (isSelected) {
Box(
modifier =
Modifier
.fillMaxSize()
.zIndex(1000f)
.clip(RoundedCornerShape(ThumbnailCornerRadius))
.background(Color.Black.copy(alpha = 0.5f)),
) {
Icon(
painter = painterResource(R.drawable.done),
modifier = Modifier.align(Alignment.Center),
contentDescription = null,
)
}
}

PlayingIndicatorBox(
isActive = isActive,
playWhenReady = isPlaying,
modifier =
Modifier
.size(ListThumbnailSize)
.background(
color = Color.Black.copy(alpha = 0.4f),
shape = RoundedCornerShape(ThumbnailCornerRadius),
),
)
AsyncImage(
model = mediaMetadata.thumbnailUrl,
contentDescription = null,
modifier =
Modifier
.fillMaxSize()
.clip(RoundedCornerShape(ThumbnailCornerRadius)),
)

PlayingIndicatorBox(
isActive = isActive,
playWhenReady = isPlaying,
color = Color.White,
modifier =
Modifier
.fillMaxSize()
.background(
color = Color.Black.copy(alpha = 0.4f),
shape = RoundedCornerShape(ThumbnailCornerRadius),
),
)
}
},
trailingContent = trailingContent,
modifier = modifier,
Expand Down
172 changes: 100 additions & 72 deletions app/src/main/java/com/malopieds/innertune/ui/player/Queue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ package com.malopieds.innertune.ui.player
import android.annotation.SuppressLint
import android.text.format.Formatter
import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -120,6 +128,9 @@ fun Queue(

val selectedSongs: MutableList<MediaMetadata> = mutableStateListOf()
val selectedItems: MutableList<Timeline.Window> = mutableStateListOf()
var selection by remember {
mutableStateOf(false)
}

var showDetailsDialog by rememberSaveable {
mutableStateOf(false)
Expand Down Expand Up @@ -278,6 +289,15 @@ fun Queue(
.reorderable(reorderableState)
.nestedScroll(state.preUpPostDownNestedScrollConnection),
) {
item {
Spacer(
modifier =
Modifier
.animateContentSize()
.height(if (selection) 64.dp else 0.dp),
)
}

itemsIndexed(
items = mutableQueueWindows,
key = { _, item -> item.uid.hashCode() },
Expand Down Expand Up @@ -308,40 +328,9 @@ fun Queue(
// state = dismissState,
// = {
) {
Row(
horizontalArrangement = Arrangement.Center,
) {
IconButton(
modifier =
Modifier
.align(Alignment.CenterVertically),
onClick = {
if (window.mediaItem.metadata!! in selectedSongs) {
selectedSongs.remove(window.mediaItem.metadata!!)
selectedItems.remove(currentItem)
} else {
selectedSongs.add(window.mediaItem.metadata!!)
selectedItems.add(currentItem)
}
},
) {
Icon(
painter =
painterResource(
if (window.mediaItem.metadata!! in
selectedSongs
) {
R.drawable.check_box
} else {
R.drawable.uncheck_box
},
),
contentDescription = null,
tint = LocalContentColor.current,
)
}
MediaMetadataListItem(
mediaMetadata = window.mediaItem.metadata!!,
isSelected = selection && window.mediaItem.metadata!! in selectedSongs,
isActive = index == currentWindowIndex,
isPlaying = isPlaying,
trailingContent = {
Expand All @@ -362,7 +351,15 @@ fun Queue(
.fillMaxWidth()
.combinedClickable(
onClick = {
if (selectedSongs.isEmpty()) {
if (selection) {
if (window.mediaItem.metadata!! in selectedSongs) {
selectedSongs.remove(window.mediaItem.metadata!!)
selectedItems.remove(currentItem)
} else {
selectedSongs.add(window.mediaItem.metadata!!)
selectedItems.add(currentItem)
}
} else {
if (index == currentWindowIndex) {
playerConnection.player.togglePlayPause()
} else {
Expand All @@ -371,14 +368,6 @@ fun Queue(
)
playerConnection.player.playWhenReady = true
}
} else {
if (window.mediaItem.metadata!! in selectedSongs) {
selectedSongs.remove(window.mediaItem.metadata!!)
selectedItems.remove(currentItem)
} else {
selectedSongs.add(window.mediaItem.metadata!!)
selectedItems.add(currentItem)
}
}
},
onLongClick = {
Expand All @@ -398,13 +387,12 @@ fun Queue(
),
// .detectReorderAfterLongPress(reorderableState)
)
}
}
}
}
}

Box(
Column(
modifier =
Modifier
.background(
Expand All @@ -431,19 +419,80 @@ fun Queue(
modifier = Modifier.weight(1f),
)

if (selectedSongs.isNotEmpty()) {
AnimatedVisibility(
visible = !selection,
enter = fadeIn() + slideInVertically { it },
exit = fadeOut() + slideOutVertically { it },
) {
IconButton(
onClick = {
selectedSongs.clear()
selectedItems.clear()
selection = true
},
) {
Icon(
painter = painterResource(R.drawable.deselect),
painter = painterResource(R.drawable.select_all),
contentDescription = null,
tint = LocalContentColor.current,
)
}
}

Column(
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalAlignment = Alignment.End,
) {
Text(
text = pluralStringResource(R.plurals.n_song, queueWindows.size, queueWindows.size),
style = MaterialTheme.typography.bodyMedium,
)

Text(
text = makeTimeString(queueLength * 1000L),
style = MaterialTheme.typography.bodyMedium,
)
}
}

AnimatedVisibility(
visible = selection,
enter = fadeIn() + expandVertically(),
exit = fadeOut() + shrinkVertically(),
) {
Row(
modifier = Modifier
.height(64.dp)
.padding(start = 16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
val count = selectedSongs.size
Text(text = "$count elements selected", modifier = Modifier.weight(1f))
IconButton(
onClick = {
if (count == mutableQueueWindows.size) {
selectedSongs.clear()
selectedItems.clear()
} else {
queueWindows
.filter { it.mediaItem.metadata!! !in selectedSongs }
.forEach {
selectedSongs.add(it.mediaItem.metadata!!)
selectedItems.add(it)
}
}
},
) {
Icon(
painter =
painterResource(
if (count == mutableQueueWindows.size) {
R.drawable.deselect
} else {
R.drawable.select_all
},
),
contentDescription = null,
)
}

IconButton(
onClick = {
menuState.show {
Expand All @@ -465,37 +514,16 @@ fun Queue(
tint = LocalContentColor.current,
)
}
} else {

IconButton(
onClick = {
queueWindows.forEach {
selectedSongs.add(it.mediaItem.metadata!!)
selectedItems.add(it)
}
},
onClick = { selection = false },
) {
Icon(
painter = painterResource(R.drawable.select_all),
painter = painterResource(R.drawable.close),
contentDescription = null,
tint = LocalContentColor.current,
)
}
}

Column(
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalAlignment = Alignment.End,
) {
Text(
text = pluralStringResource(R.plurals.n_song, queueWindows.size, queueWindows.size),
style = MaterialTheme.typography.bodyMedium,
)

Text(
text = makeTimeString(queueLength * 1000L),
style = MaterialTheme.typography.bodyMedium,
)
}
}
}

Expand Down