Skip to content

Commit bef840d

Browse files
committed
Remove unused code.
1 parent 3384c6f commit bef840d

File tree

4 files changed

+80
-41
lines changed

4 files changed

+80
-41
lines changed

Jetcaster/app/src/main/java/com/example/jetcaster/ui/player/PlayerScreen.kt

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.example.jetcaster.ui.player
1818

1919
import androidx.compose.foundation.ExperimentalFoundationApi
2020
import androidx.compose.foundation.Image
21+
import androidx.compose.foundation.background
2122
import androidx.compose.foundation.basicMarquee
2223
import androidx.compose.foundation.clickable
2324
import androidx.compose.foundation.layout.Arrangement
@@ -42,6 +43,7 @@ import androidx.compose.foundation.layout.windowInsetsPadding
4243
import androidx.compose.foundation.layout.wrapContentSize
4344
import androidx.compose.foundation.rememberScrollState
4445
import androidx.compose.foundation.text.selection.SelectionContainer
46+
import androidx.compose.foundation.shape.CircleShape
4547
import androidx.compose.foundation.verticalScroll
4648
import androidx.compose.material.icons.Icons
4749
import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -51,8 +53,8 @@ import androidx.compose.material.icons.filled.MoreVert
5153
import androidx.compose.material.icons.filled.Replay10
5254
import androidx.compose.material.icons.filled.SkipNext
5355
import androidx.compose.material.icons.filled.SkipPrevious
54-
import androidx.compose.material.icons.rounded.PauseCircleFilled
55-
import androidx.compose.material.icons.rounded.PlayCircleFilled
56+
import androidx.compose.material.icons.outlined.Pause
57+
import androidx.compose.material.icons.outlined.PlayArrow
5658
import androidx.compose.material3.CircularProgressIndicator
5759
import androidx.compose.material3.Icon
5860
import androidx.compose.material3.IconButton
@@ -202,7 +204,7 @@ private fun PlayerBackground(
202204
) {
203205
ImageBackgroundColorScrim(
204206
url = episode?.podcastImageUrl,
205-
color = Color.Black.copy(alpha = 0.68f),
207+
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.9f),
206208
modifier = modifier,
207209
)
208210
}
@@ -238,7 +240,7 @@ fun PlayerContentWithBackground(
238240
onRewindBy = onRewindBy,
239241
onNext = onNext,
240242
onPrevious = onPrevious,
241-
onAddToQueue = onAddToQueue
243+
onAddToQueue = onAddToQueue,
242244
)
243245
}
244246
}
@@ -281,7 +283,9 @@ fun PlayerContent(
281283
if (usingVerticalStrategy) {
282284
TwoPane(
283285
first = {
284-
PlayerContentTableTopTop(uiState = uiState)
286+
PlayerContentTableTopTop(
287+
uiState = uiState,
288+
)
285289
},
286290
second = {
287291
PlayerContentTableTopBottom(
@@ -617,13 +621,6 @@ private fun TopAppBar(
617621
}
618622
}
619623

620-
@Composable
621-
private fun PlayerCarousel(
622-
modifier: Modifier = Modifier
623-
) {
624-
625-
}
626-
627624
@Composable
628625
private fun PlayerImage(
629626
podcastImageUrl: String,
@@ -654,11 +651,13 @@ private fun PodcastDescription(
654651
text = title,
655652
style = titleTextStyle,
656653
maxLines = 1,
654+
color = MaterialTheme.colorScheme.onSurface,
657655
modifier = Modifier.basicMarquee()
658656
)
659657
Text(
660658
text = podcastName,
661659
style = MaterialTheme.typography.bodyMedium,
660+
color = MaterialTheme.colorScheme.onSurface,
662661
maxLines = 1
663662
)
664663
}
@@ -742,50 +741,60 @@ private fun PlayerButtons(
742741
verticalAlignment = Alignment.CenterVertically,
743742
horizontalArrangement = Arrangement.SpaceEvenly
744743
) {
745-
val buttonsModifier = Modifier
744+
val sideButtonsModifier = Modifier
746745
.size(sideButtonSize)
746+
.background(
747+
color = MaterialTheme.colorScheme.surfaceContainerHighest,
748+
shape = CircleShape
749+
)
750+
.semantics { role = Role.Button }
751+
752+
val primaryButtonModifier = Modifier
753+
.size(playerButtonSize)
754+
.background(
755+
color = MaterialTheme.colorScheme.primaryContainer,
756+
shape = CircleShape
757+
)
747758
.semantics { role = Role.Button }
748759

749760
Image(
750761
imageVector = Icons.Filled.SkipPrevious,
751762
contentDescription = stringResource(R.string.cd_skip_previous),
752-
contentScale = ContentScale.Fit,
753-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
754-
modifier = buttonsModifier
763+
contentScale = ContentScale.Inside,
764+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurfaceVariant),
765+
modifier = sideButtonsModifier
755766
.clickable(enabled = isPlaying, onClick = onPrevious)
756767
)
757768
Image(
758769
imageVector = Icons.Filled.Replay10,
759770
contentDescription = stringResource(R.string.cd_replay10),
760-
contentScale = ContentScale.Fit,
771+
contentScale = ContentScale.Inside,
761772
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
762-
modifier = buttonsModifier
773+
modifier = sideButtonsModifier
763774
.clickable {
764775
onRewindBy(Duration.ofSeconds(10))
765776
}
766777
)
767778
if (isPlaying) {
768779
Image(
769-
imageVector = Icons.Rounded.PauseCircleFilled,
780+
imageVector = Icons.Outlined.Pause,
770781
contentDescription = stringResource(R.string.cd_pause),
771782
contentScale = ContentScale.Fit,
772-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.primaryContainer),
773-
modifier = Modifier
774-
.size(playerButtonSize)
775-
.semantics { role = Role.Button }
783+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onPrimaryContainer),
784+
modifier = primaryButtonModifier
785+
.padding(8.dp)
776786
.clickable {
777787
onPausePress()
778788
}
779789
)
780790
} else {
781791
Image(
782-
imageVector = Icons.Rounded.PlayCircleFilled,
792+
imageVector = Icons.Outlined.PlayArrow,
783793
contentDescription = stringResource(R.string.cd_play),
784794
contentScale = ContentScale.Fit,
785-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.primaryContainer),
786-
modifier = Modifier
787-
.size(playerButtonSize)
788-
.semantics { role = Role.Button }
795+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onPrimaryContainer),
796+
modifier = primaryButtonModifier
797+
.padding(8.dp)
789798
.clickable {
790799
onPlayPress()
791800
}
@@ -794,19 +803,19 @@ private fun PlayerButtons(
794803
Image(
795804
imageVector = Icons.Filled.Forward10,
796805
contentDescription = stringResource(R.string.cd_forward10),
797-
contentScale = ContentScale.Fit,
806+
contentScale = ContentScale.Inside,
798807
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
799-
modifier = buttonsModifier
808+
modifier = sideButtonsModifier
800809
.clickable {
801810
onAdvanceBy(Duration.ofSeconds(10))
802811
}
803812
)
804813
Image(
805814
imageVector = Icons.Filled.SkipNext,
806815
contentDescription = stringResource(R.string.cd_skip_next),
807-
contentScale = ContentScale.Fit,
808-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
809-
modifier = buttonsModifier
816+
contentScale = ContentScale.Inside,
817+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurfaceVariant),
818+
modifier = sideButtonsModifier
810819
.clickable(enabled = hasNext, onClick = onNext)
811820
)
812821
}
@@ -890,6 +899,11 @@ fun PlayerScreenPreview() {
890899
podcastName = "Podcast",
891900
),
892901
isPlaying = false,
902+
queue = listOf(
903+
PlayerEpisode(),
904+
PlayerEpisode(),
905+
PlayerEpisode(),
906+
)
893907
),
894908
),
895909
displayFeatures = emptyList(),

Jetcaster/app/src/main/java/com/example/jetcaster/ui/player/PlayerViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ import androidx.lifecycle.ViewModel
2525
import androidx.lifecycle.viewModelScope
2626
import com.example.jetcaster.core.data.database.model.toPlayerEpisode
2727
import com.example.jetcaster.core.data.repository.EpisodeStore
28+
import com.example.jetcaster.core.model.PlayerEpisode
2829
import com.example.jetcaster.core.player.EpisodePlayer
2930
import com.example.jetcaster.core.player.EpisodePlayerState
3031
import com.example.jetcaster.ui.Screen
3132
import dagger.hilt.android.lifecycle.HiltViewModel
32-
import java.time.Duration
33-
import javax.inject.Inject
3433
import kotlinx.coroutines.ExperimentalCoroutinesApi
3534
import kotlinx.coroutines.flow.flatMapConcat
3635
import kotlinx.coroutines.flow.map
3736
import kotlinx.coroutines.launch
37+
import java.time.Duration
38+
import javax.inject.Inject
3839

3940
data class PlayerUiState(
4041
val episodePlayerState: EpisodePlayerState = EpisodePlayerState()
@@ -105,4 +106,8 @@ class PlayerViewModel @Inject constructor(
105106
episodePlayer.addToQueue(it)
106107
}
107108
}
109+
110+
fun onPlay(episode: PlayerEpisode) {
111+
episodePlayer.play(episode)
112+
}
108113
}

Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/player/MockEpisodePlayerTest.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,34 @@ class MockEpisodePlayerTest {
9191
}
9292

9393
@Test
94-
fun whenNextQueueNotEmpty_notRemovedFromQueue() {
95-
}
94+
fun whenNextQueueNotEmpty_notRemovedFromQueue() = runTest(testDispatcher) {
95+
mockEpisodePlayer.currentEpisode = PlayerEpisode(
96+
uri = "currentEpisode",
97+
duration = Duration.ofSeconds(60)
98+
)
99+
testEpisodes.forEach { mockEpisodePlayer.addToQueue(it) }
96100

97-
@Test
98-
fun whenPreviousQueueEmpty_resetSameEpisode() {
101+
mockEpisodePlayer.play()
102+
advanceTimeBy(100)
103+
104+
// TODO override next?
105+
mockEpisodePlayer.next()
106+
advanceTimeBy(100)
107+
108+
assertEquals(testEpisodes.first(), mockEpisodePlayer.currentEpisode)
109+
110+
val queue = mockEpisodePlayer.playerState.value.queue
111+
assertEquals(testEpisodes.size - 1, queue.size)
99112
}
100113

101114
@Test
102-
fun whenPreviousQueueNotEmpty_differentEpisode() {
115+
fun whenPreviousQueueEmpty_resetSameEpisode() = runTest(testDispatcher) {
116+
mockEpisodePlayer.currentEpisode = testEpisodes[0]
117+
mockEpisodePlayer.play()
118+
advanceTimeBy(1000L)
119+
120+
mockEpisodePlayer.previous()
121+
assertEquals(0, mockEpisodePlayer.playerState.value.timeElapsed.toMillis())
122+
assertEquals(testEpisodes[0], mockEpisodePlayer.currentEpisode)
103123
}
104124
}

Jetcaster/designsystem/src/main/java/com/example/jetcaster/designsystem/component/ImageBackground.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fun ImageBackgroundColorScrim(
3838
url = url,
3939
modifier = modifier,
4040
overlay = {
41-
drawRect(color, blendMode = BlendMode.Multiply)
41+
drawRect(color)
4242
}
4343
)
4444
}

0 commit comments

Comments
 (0)