Skip to content

Commit b1cac54

Browse files
committed
Remove unused code.
1 parent fa67945 commit b1cac54

File tree

4 files changed

+80
-42
lines changed

4 files changed

+80
-42
lines changed

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

Lines changed: 47 additions & 34 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
@@ -41,6 +42,7 @@ import androidx.compose.foundation.layout.systemBarsPadding
4142
import androidx.compose.foundation.layout.windowInsetsPadding
4243
import androidx.compose.foundation.layout.wrapContentSize
4344
import androidx.compose.foundation.rememberScrollState
45+
import androidx.compose.foundation.shape.CircleShape
4446
import androidx.compose.foundation.verticalScroll
4547
import androidx.compose.material.icons.Icons
4648
import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -50,8 +52,8 @@ import androidx.compose.material.icons.filled.MoreVert
5052
import androidx.compose.material.icons.filled.Replay10
5153
import androidx.compose.material.icons.filled.SkipNext
5254
import androidx.compose.material.icons.filled.SkipPrevious
53-
import androidx.compose.material.icons.rounded.PauseCircleFilled
54-
import androidx.compose.material.icons.rounded.PlayCircleFilled
55+
import androidx.compose.material.icons.outlined.Pause
56+
import androidx.compose.material.icons.outlined.PlayArrow
5557
import androidx.compose.material3.CircularProgressIndicator
5658
import androidx.compose.material3.Icon
5759
import androidx.compose.material3.IconButton
@@ -71,7 +73,6 @@ import androidx.compose.runtime.rememberCoroutineScope
7173
import androidx.compose.ui.Alignment
7274
import androidx.compose.ui.Modifier
7375
import androidx.compose.ui.draw.clip
74-
import androidx.compose.ui.graphics.Color
7576
import androidx.compose.ui.graphics.ColorFilter
7677
import androidx.compose.ui.layout.ContentScale
7778
import androidx.compose.ui.platform.LocalContext
@@ -200,7 +201,7 @@ private fun PlayerBackground(
200201
) {
201202
ImageBackgroundColorScrim(
202203
url = episode?.podcastImageUrl,
203-
color = Color.Black.copy(alpha = 0.68f),
204+
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.9f),
204205
modifier = modifier,
205206
)
206207
}
@@ -236,7 +237,7 @@ fun PlayerContentWithBackground(
236237
onRewindBy = onRewindBy,
237238
onNext = onNext,
238239
onPrevious = onPrevious,
239-
onAddToQueue = onAddToQueue
240+
onAddToQueue = onAddToQueue,
240241
)
241242
}
242243
}
@@ -279,7 +280,9 @@ fun PlayerContent(
279280
if (usingVerticalStrategy) {
280281
TwoPane(
281282
first = {
282-
PlayerContentTableTopTop(uiState = uiState)
283+
PlayerContentTableTopTop(
284+
uiState = uiState,
285+
)
283286
},
284287
second = {
285288
PlayerContentTableTopBottom(
@@ -618,13 +621,6 @@ private fun TopAppBar(
618621
}
619622
}
620623

621-
@Composable
622-
private fun PlayerCarousel(
623-
modifier: Modifier = Modifier
624-
) {
625-
626-
}
627-
628624
@Composable
629625
private fun PlayerImage(
630626
podcastImageUrl: String,
@@ -655,11 +651,13 @@ private fun PodcastDescription(
655651
text = title,
656652
style = titleTextStyle,
657653
maxLines = 1,
654+
color = MaterialTheme.colorScheme.onSurface,
658655
modifier = Modifier.basicMarquee()
659656
)
660657
Text(
661658
text = podcastName,
662659
style = MaterialTheme.typography.bodyMedium,
660+
color = MaterialTheme.colorScheme.onSurface,
663661
maxLines = 1
664662
)
665663
}
@@ -743,50 +741,60 @@ private fun PlayerButtons(
743741
verticalAlignment = Alignment.CenterVertically,
744742
horizontalArrangement = Arrangement.SpaceEvenly
745743
) {
746-
val buttonsModifier = Modifier
744+
val sideButtonsModifier = Modifier
747745
.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+
)
748758
.semantics { role = Role.Button }
749759

750760
Image(
751761
imageVector = Icons.Filled.SkipPrevious,
752762
contentDescription = stringResource(R.string.cd_skip_previous),
753-
contentScale = ContentScale.Fit,
754-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
755-
modifier = buttonsModifier
763+
contentScale = ContentScale.Inside,
764+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurfaceVariant),
765+
modifier = sideButtonsModifier
756766
.clickable(enabled = isPlaying, onClick = onPrevious)
757767
)
758768
Image(
759769
imageVector = Icons.Filled.Replay10,
760770
contentDescription = stringResource(R.string.cd_replay10),
761-
contentScale = ContentScale.Fit,
771+
contentScale = ContentScale.Inside,
762772
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
763-
modifier = buttonsModifier
773+
modifier = sideButtonsModifier
764774
.clickable {
765775
onRewindBy(Duration.ofSeconds(10))
766776
}
767777
)
768778
if (isPlaying) {
769779
Image(
770-
imageVector = Icons.Rounded.PauseCircleFilled,
780+
imageVector = Icons.Outlined.Pause,
771781
contentDescription = stringResource(R.string.cd_pause),
772782
contentScale = ContentScale.Fit,
773-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.primaryContainer),
774-
modifier = Modifier
775-
.size(playerButtonSize)
776-
.semantics { role = Role.Button }
783+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onPrimaryContainer),
784+
modifier = primaryButtonModifier
785+
.padding(8.dp)
777786
.clickable {
778787
onPausePress()
779788
}
780789
)
781790
} else {
782791
Image(
783-
imageVector = Icons.Rounded.PlayCircleFilled,
792+
imageVector = Icons.Outlined.PlayArrow,
784793
contentDescription = stringResource(R.string.cd_play),
785794
contentScale = ContentScale.Fit,
786-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.primaryContainer),
787-
modifier = Modifier
788-
.size(playerButtonSize)
789-
.semantics { role = Role.Button }
795+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onPrimaryContainer),
796+
modifier = primaryButtonModifier
797+
.padding(8.dp)
790798
.clickable {
791799
onPlayPress()
792800
}
@@ -795,19 +803,19 @@ private fun PlayerButtons(
795803
Image(
796804
imageVector = Icons.Filled.Forward10,
797805
contentDescription = stringResource(R.string.cd_forward10),
798-
contentScale = ContentScale.Fit,
806+
contentScale = ContentScale.Inside,
799807
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
800-
modifier = buttonsModifier
808+
modifier = sideButtonsModifier
801809
.clickable {
802810
onAdvanceBy(Duration.ofSeconds(10))
803811
}
804812
)
805813
Image(
806814
imageVector = Icons.Filled.SkipNext,
807815
contentDescription = stringResource(R.string.cd_skip_next),
808-
contentScale = ContentScale.Fit,
809-
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
810-
modifier = buttonsModifier
816+
contentScale = ContentScale.Inside,
817+
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurfaceVariant),
818+
modifier = sideButtonsModifier
811819
.clickable(enabled = hasNext, onClick = onNext)
812820
)
813821
}
@@ -873,6 +881,11 @@ fun PlayerScreenPreview() {
873881
podcastName = "Podcast",
874882
),
875883
isPlaying = false,
884+
queue = listOf(
885+
PlayerEpisode(),
886+
PlayerEpisode(),
887+
PlayerEpisode(),
888+
)
876889
),
877890
),
878891
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)