Skip to content

Commit

Permalink
Revert "#495 - Workaround to fix play item by index until fix is made…
Browse files Browse the repository at this point in the history
… in media3 (#494)"

This reverts commit f5b3b08.
  • Loading branch information
luizgrp authored Aug 16, 2022
1 parent 958ecae commit 540b17d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,28 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.wear.compose.material.ScalingLazyListState
import com.google.android.horologist.compose.layout.StateUtils
import com.google.android.horologist.media.ui.screens.entity.EntityScreen
import com.google.android.horologist.media.ui.state.model.DownloadMediaUiModel
import com.google.android.horologist.media.ui.state.model.PlaylistUiModel

@Composable
fun UampEntityScreen(
uampEntityScreenViewModel: UampEntityScreenViewModel,
onDownloadItemClick: () -> Unit,
onDownloadItemClick: (DownloadMediaUiModel) -> Unit,
onShuffleClick: (PlaylistUiModel) -> Unit,
onPlayClick: (PlaylistUiModel) -> Unit,
focusRequester: FocusRequester,
scalingLazyListState: ScalingLazyListState
) {
val uiState by StateUtils.rememberStateWithLifecycle(flow = uampEntityScreenViewModel.uiState)

// https://github.com/google/horologist/issues/496
val finishedPlayExecution by StateUtils.rememberStateWithLifecycle(flow = uampEntityScreenViewModel.finishedPlayExecution)
if (finishedPlayExecution) {
onDownloadItemClick()
}

EntityScreen(
entityScreenState = uiState,
onDownloadClick = {
uampEntityScreenViewModel.download()
},
onDownloadItemClick = {
uampEntityScreenViewModel.play(it.mediaUiModel.id)
onDownloadItemClick(it)
},
onShuffleClick = {
uampEntityScreenViewModel.shufflePlay()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ import com.google.android.horologist.mediasample.domain.model.PlaylistDownload
import com.google.android.horologist.mediasample.ui.mapper.DownloadMediaUiModelMapper
import com.google.android.horologist.mediasample.ui.mapper.PlaylistUiModelMapper
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -66,9 +63,6 @@ class UampEntityScreenViewModel @Inject constructor(
EntityScreenState.Loading(playlistName)
)

// https://github.com/google/horologist/issues/496
val finishedPlayExecution: MutableStateFlow<Boolean> = MutableStateFlow(false)

fun play(mediaId: String? = null) {
play(shuffled = false, mediaId = mediaId)
}
Expand All @@ -84,18 +78,11 @@ class UampEntityScreenViewModel @Inject constructor(
.coerceAtLeast(0)

playerRepository.setShuffleModeEnabled(shuffled)
playerRepository.setMediaList(playlistDownload.playlist.mediaList)

// https://github.com/google/horologist/issues/496
viewModelScope.launch {
delay(100)

playerRepository.seekToDefaultPosition(index)
playerRepository.prepare()
playerRepository.play()

finishedPlayExecution.value = true
}
playerRepository.setMediaList(playlistDownload.playlist.mediaList)
playerRepository.seekToDefaultPosition(index)
playerRepository.prepare()
playerRepository.play()
}
}

Expand Down

0 comments on commit 540b17d

Please sign in to comment.