-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#115 Display trailers for movies and shows
Feature Movie/Show trailers
- Loading branch information
Showing
29 changed files
with
502 additions
and
3 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
core/ui/common/src/main/java/io/filmtime/core/ui/common/componnents/VideoCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.filmtime.core.ui.common.componnents | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.unit.dp | ||
import coil.compose.AsyncImage | ||
import io.filmtime.core.designsystem.theme.PreviewFilmTimeTheme | ||
import io.filmtime.core.designsystem.theme.ThemePreviews | ||
import io.filmtime.core.ui.common.componnents.placeholder.PlaceholderHighlight | ||
import io.filmtime.core.ui.common.componnents.placeholder.fade | ||
import io.filmtime.core.ui.common.componnents.placeholder.placeholder | ||
import io.filmtime.data.model.MovieVideo | ||
import io.filmtime.data.model.VideoSource.YouTube | ||
|
||
@Composable | ||
fun VideoCard( | ||
video: MovieVideo, | ||
placeHolderVisible: Boolean, | ||
onClick: ((String) -> Unit)? = null, | ||
) { | ||
val placeholderHighlight = PlaceholderHighlight.fade() | ||
Box( | ||
modifier = Modifier | ||
.aspectRatio(16f / 9f) | ||
.clip(RoundedCornerShape(8.dp)) | ||
.then( | ||
if (video.link != null && onClick != null) { | ||
Modifier.clickable { | ||
onClick.invoke(video.link!!) | ||
} | ||
} else { | ||
Modifier | ||
}, | ||
), | ||
) { | ||
AsyncImage( | ||
modifier = Modifier | ||
.aspectRatio(16f / 9f) | ||
.placeholder( | ||
visible = placeHolderVisible, | ||
highlight = placeholderHighlight, | ||
), | ||
model = video.posterUrl, | ||
contentDescription = video.link, | ||
contentScale = ContentScale.Crop, | ||
) | ||
} | ||
} | ||
|
||
@ThemePreviews | ||
@Composable | ||
private fun PreviewVideoCard() { | ||
PreviewFilmTimeTheme { | ||
VideoCard( | ||
video = MovieVideo( | ||
name = "The Batman", | ||
posterUrl = "https://image.tmdb.org/t/p/w500/5VJSIAhSn4qUq3FjV3j6Uz5Zc4c.jpg", | ||
link = "https://www.youtube.com/watch?v=IhYDiZ0fF5Y", | ||
source = YouTube, | ||
key = "", | ||
), | ||
placeHolderVisible = false, | ||
) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
core/ui/common/src/main/java/io/filmtime/core/ui/common/componnents/VideoTrailerRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.filmtime.core.ui.common.componnents | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import io.filmtime.core.ui.common.R | ||
import io.filmtime.data.model.MovieVideo | ||
|
||
@Composable | ||
fun VideoTrailerRow( | ||
modifier: Modifier = Modifier, | ||
onClick: ((String) -> Unit)?, | ||
items: List<MovieVideo>, | ||
isLoading: Boolean, | ||
) { | ||
Column( | ||
modifier = modifier, | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.core_ui_trailers_title), | ||
style = MaterialTheme.typography.titleMedium, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(16.dp), | ||
) | ||
if (isLoading) { | ||
CircularProgressIndicator( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.wrapContentSize(), | ||
) | ||
} else if (items.isNotEmpty()) { | ||
LazyRow( | ||
modifier = Modifier | ||
.height(180.dp) | ||
.fillMaxWidth(), | ||
contentPadding = PaddingValues(horizontal = 16.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
) { | ||
items(items) { item -> | ||
VideoCard( | ||
video = item, | ||
placeHolderVisible = false, | ||
onClick = onClick, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
data/api/tmdb/src/main/java/io/filmtime/data/api/tmdb/MovieVideoExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.filmtime.data.api.tmdb | ||
|
||
import io.filmtime.data.model.MovieVideo | ||
import io.filmtime.data.model.VideoSource | ||
import io.filmtime.data.network.model.Site | ||
import io.filmtime.data.network.model.Site.YouTube | ||
import io.filmtime.data.network.model.VideoData | ||
|
||
fun VideoData.toVideos(): MovieVideo = | ||
MovieVideo( | ||
key = key, | ||
name = name, | ||
source = site.toSource(), | ||
) | ||
|
||
fun Site.toSource(): VideoSource = | ||
when (this) { | ||
YouTube -> VideoSource.YouTube | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
data/model/src/main/java/io/filmtime/data/model/MovieVideo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.filmtime.data.model | ||
|
||
data class MovieVideo( | ||
val name: String, | ||
val link: String? = null, | ||
val source: VideoSource? = null, | ||
val key: String, | ||
val posterUrl: String? = null, | ||
) | ||
|
||
enum class VideoSource { | ||
YouTube, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
data/network/src/main/java/io/filmtime/data/network/model/TmdbVideoResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.filmtime.data.network.model | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TmdbVideosResponse( | ||
val id: Long, | ||
val results: List<VideoData>, | ||
) | ||
|
||
@Serializable | ||
data class VideoData( | ||
@SerialName("iso_639_1") | ||
val iso639_1: String, | ||
@SerialName("iso_3166_1") | ||
val iso3166_1: String, | ||
val name: String, | ||
val key: String, | ||
val site: Site, | ||
val size: Long, | ||
val type: Type, | ||
val official: Boolean, | ||
@SerialName("published_at") | ||
val publishedAt: String, | ||
val id: String, | ||
) | ||
|
||
@Serializable | ||
enum class Site(val value: String) { | ||
@SerialName("YouTube") | ||
YouTube("YouTube"), | ||
} | ||
|
||
@Serializable | ||
enum class Type(val value: String) { | ||
@SerialName("Behind the Scenes") | ||
BehindTheScenes("Behind the Scenes"), | ||
|
||
@SerialName("Clip") | ||
Clip("Clip"), | ||
|
||
@SerialName("Featurette") | ||
Featurette("Featurette"), | ||
|
||
@SerialName("Teaser") | ||
Teaser("Teaser"), | ||
|
||
@SerialName("Trailer") | ||
Trailer("Trailer"), | ||
} |
Oops, something went wrong.