Skip to content

Commit

Permalink
#82 Using slot for loading credits in movie details
Browse files Browse the repository at this point in the history
  • Loading branch information
moallemi committed Jun 16, 2024
1 parent de9d6ea commit 75a299c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import io.filmtime.core.designsystem.composable.FilmTimeFilledTonalButton
import io.filmtime.core.designsystem.theme.FilmTimeTheme
import io.filmtime.core.designsystem.theme.PreviewFilmTimeTheme
import io.filmtime.core.designsystem.theme.ThemePreviews
import io.filmtime.core.ui.common.componnents.CreditsRow
import io.filmtime.core.ui.common.componnents.ErrorContent
import io.filmtime.core.ui.common.componnents.VideoSectionRow
import io.filmtime.data.model.Person
Expand All @@ -46,6 +45,7 @@ import io.filmtime.data.model.PreviewCast
import io.filmtime.data.model.PreviewCrew
import io.filmtime.data.model.VideoDetail
import io.filmtime.data.model.VideoType
import io.filmtime.feature.credits.components.CreditsRow
import io.filmtime.feature.movie.detail.components.VideoDescription
import io.filmtime.feature.movie.detail.components.VideoInfo
import io.filmtime.feature.movie.detail.components.VideoThumbnailInfo
Expand Down Expand Up @@ -89,10 +89,15 @@ fun MovieDetailScreen(
creditState = creditState,
similarState = similarState,
onSimilarItemClick = onMovieClick,
onCreditsRetry = viewModel::loadCredits,
onSimilarRetry = viewModel::loadSimilar,
onAddBookmark = viewModel::addBookmark,
onRemoveBookmark = viewModel::removeBookmark,
credits = {
CreditsRow(
tmdbId = videoDetail.ids.tmdbId ?: 0,
videoType = VideoType.Movie,
)
},
traktHistoryButton = {
TraktAddRemoveHistoryButton(
modifier = Modifier
Expand All @@ -112,10 +117,10 @@ private fun MovieDetailScreen(
isBookmarked: Boolean,
similarState: MovieDetailSimilarState,
onSimilarItemClick: (Int) -> Unit,
onCreditsRetry: () -> Unit,
onSimilarRetry: () -> Unit,
onAddBookmark: () -> Unit,
onRemoveBookmark: () -> Unit,
credits: @Composable () -> Unit,
traktHistoryButton: @Composable RowScope.() -> Unit,
) {
var imageHeight by remember { mutableIntStateOf(4000) }
Expand Down Expand Up @@ -177,12 +182,7 @@ private fun MovieDetailScreen(
}
}
item {
CreditsRow(
isLoading = creditState.isLoading,
credits = creditState.credit,
error = creditState.error,
onRetryClick = onCreditsRetry,
)
credits()
}
item {
VideoSectionRow(
Expand Down Expand Up @@ -227,10 +227,12 @@ private fun MovieDetailScreenPreview() {
videoItems = listOf(),
),
onSimilarItemClick = {},
onCreditsRetry = {},
onSimilarRetry = {},
onAddBookmark = {},
onRemoveBookmark = {},
credits = {
Text("Credit goes here")
},
traktHistoryButton = {
FilmTimeFilledTonalButton(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.filmtime.domain.bookmarks.AddBookmarkUseCase
import io.filmtime.domain.bookmarks.DeleteBookmarkUseCase
import io.filmtime.domain.bookmarks.ObserveBookmarkUseCase
import io.filmtime.domain.stream.GetStreamInfoUseCase
import io.filmtime.domain.tmdb.movies.GetMovieCreditsUseCase
import io.filmtime.domain.tmdb.movies.GetMovieDetailsUseCase
import io.filmtime.domain.tmdb.movies.GetSimilarUseCase
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -29,7 +28,6 @@ class MovieDetailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val getMovieDetail: GetMovieDetailsUseCase,
private val getStreamInfo: GetStreamInfoUseCase,
private val getCredit: GetMovieCreditsUseCase,
private val getSimilar: GetSimilarUseCase,
private val addBookmark: AddBookmarkUseCase,
private val deleteBookmark: DeleteBookmarkUseCase,
Expand All @@ -51,7 +49,6 @@ class MovieDetailViewModel @Inject constructor(

init {
load()
loadCredits()
loadSimilar()
observeBookmark()
}
Expand Down Expand Up @@ -94,24 +91,6 @@ class MovieDetailViewModel @Inject constructor(
}
}

fun loadCredits() = viewModelScope.launch {
_creditState.value = _creditState.value.copy(isLoading = true, error = null)

when (val result = getCredit(videoId)) {
is Success -> {
_creditState.update { state ->
state.copy(credit = result.data, isLoading = false, error = null)
}
}

is Failure -> {
_creditState.update { state ->
state.copy(error = result.error.toUiMessage(), isLoading = false)
}
}
}
}

fun loadStreamInfo() = viewModelScope.launch {
_state.value = _state.value.copy(isStreamLoading = true)
getStreamInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.AsyncImage
import io.filmtime.core.ui.common.componnents.CreditRowItem
import io.filmtime.core.ui.common.componnents.ErrorContent
import io.filmtime.core.ui.common.componnents.LoadingCastSectionRow
import io.filmtime.core.ui.common.componnents.VideoThumbnailCard
Expand Down Expand Up @@ -203,7 +202,7 @@ fun ShowDetailContent(
} else if (creditState.credit.isNotEmpty()) {
LazyRow() {
items(creditState.credit) { item ->
CreditRowItem(item = item)
// TODO: Add PeopleInCreditsRow
}
}
}
Expand Down

0 comments on commit 75a299c

Please sign in to comment.