Skip to content

Commit

Permalink
Merge pull request #14 from jhg3410/videoPlayer
Browse files Browse the repository at this point in the history
Detail UI 수정 (Teaser 영상 추가)
  • Loading branch information
jhg3410 authored Aug 23, 2023
2 parents 1771141 + f0dbfbb commit 739bffc
Show file tree
Hide file tree
Showing 29 changed files with 560 additions and 26 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.chaquopy) apply false
}

buildscript {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@ class MovieRepositoryImpl @Inject constructor(
override suspend fun getMovieInfo(id: Long): Result<MovieInfo> {
val movieInfo = movieRemoteDataSource.getMovieInfo(id = id)
val movieCredits = movieRemoteDataSource.getMovieCredits(id = id)
val movieVideo = movieRemoteDataSource.getMovieVideo(id = id)

val result = movieInfo.fold(
onSuccess = { movieInfoData ->
movieCredits.fold(
onSuccess = { movieCreditsData ->
Result.success(movieInfoData.copy(cast = movieCreditsData))
},
onFailure = { movieCreditsException ->
Result.failure(movieCreditsException)
}
)
},
onFailure = { movieInfoException ->
Result.failure(movieInfoException)
}
)
val result = movieInfo.mapCatching {
it.copy(
cast = movieCredits.getOrThrow(),
video = movieVideo.getOrNull()
)
}

return result
}
Expand Down
12 changes: 10 additions & 2 deletions core-model/src/main/java/com/jik/core/model/MovieInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ data class MovieInfo(
val title: String,
val genres: List<Genre>,
val overview: String,
@Json(ignore = true) val cast: List<CastItem> = emptyList(),
@Json(name = "release_date") val releaseDate: String,
@Json(name = "poster_path") val posterPath: String,
@Json(name = "backdrop_path") val backdropPath: String,
@Json(name = "vote_average") val rating: Double,
@Json(ignore = true) val cast: List<CastItem> = emptyList(),
@Json(ignore = true) val video: VideoInfo? = null
) {

fun getReleaseDateString(): String = "release: $releaseDate"
fun getPosterUrl() = "https://image.tmdb.org/t/p/w500$posterPath"
fun getBackdropUrl() = "https://image.tmdb.org/t/p/w500$backdropPath"


Expand All @@ -35,4 +35,12 @@ data class MovieInfo(
) {
fun getProfileUrl() = "https://image.tmdb.org/t/p/w500$profilePath"
}

@JsonClass(generateAdapter = true)
data class VideoInfo(
@Json(name = "key") val videoId: String,
val site: String,
val type: String,
val official: Boolean
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jik.core.network.model

import com.jik.core.model.MovieInfo
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class VideosResponse(
val id: Int,
val results: List<MovieInfo.VideoInfo>
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jik.core.network.service
import com.jik.core.model.MovieInfo
import com.jik.core.network.model.CreditsResponse
import com.jik.core.network.model.MovieResponse
import com.jik.core.network.model.VideosResponse
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
Expand All @@ -24,4 +25,9 @@ interface MovieService {
suspend fun getMovieCredits(
@Path("movie_id") id: Long
): Result<CreditsResponse>

@GET("movie/{movie_id}/videos")
suspend fun getMovieVideo(
@Path("movie_id") id: Long
): Result<VideosResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface MovieRemoteDataSource {
suspend fun getMovieInfo(id: Long): Result<MovieInfo>

suspend fun getMovieCredits(id: Long): Result<List<MovieInfo.CastItem>>

suspend fun getMovieVideo(id: Long): Result<MovieInfo.VideoInfo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MovieRemoteDataSourceImpl @Inject constructor(
) : MovieRemoteDataSource {

override suspend fun getPopularMovies(page: Int): Result<List<Movie>> {
return movieService.getPopularMovieList(page).mapCatching {
return movieService.getPopularMovieList(page).map {
it.results
}
}
Expand All @@ -20,10 +20,20 @@ class MovieRemoteDataSourceImpl @Inject constructor(
}

override suspend fun getMovieCredits(id: Long): Result<List<MovieInfo.CastItem>> {
return movieService.getMovieCredits(id).mapCatching {
return movieService.getMovieCredits(id).map {
it.cast.filter { castItem ->
castItem.knownForDepartment == "Acting"
}
}
}

override suspend fun getMovieVideo(id: Long): Result<MovieInfo.VideoInfo> {
return movieService.getMovieVideo(id).mapCatching { response ->
response.results.find {
it.site == "YouTube" && it.type == "Teaser" && it.official
} ?: response.results.find {
it.site == "YouTube"
} ?: throw Exception("No video found")
}
}
}
1 change: 1 addition & 0 deletions feature-detail/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation(projects.coreUi)
implementation(projects.coreModel)
implementation(projects.coreData)
implementation(projects.libVideoplayer)

implementation(libs.androidx.ktx)
implementation(libs.androidx.runtime.ktx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.jik.core.designsystem.icon.MovieIcons
import com.jik.core.model.MovieInfo
import com.jik.core.ui.state.UiState
import com.jik.core.ui.util.MovieGenreUtils
import com.jik.lib.videoplayer.ui.VideoPlayer


@Composable
Expand Down Expand Up @@ -97,11 +98,17 @@ private fun Content(
) {

Column(modifier = modifier) {
PosterCard(
posterPath = movieInfo.getBackdropUrl(),
VideoPlayer(
modifier = Modifier.aspectRatio(500f / 281f),
roundedCornerSize = 0.dp,
clickable = false,
Thumbnail = {
PosterCard(
posterPath = movieInfo.getBackdropUrl(),
modifier = Modifier.fillMaxSize(),
roundedCornerSize = 0.dp,
clickable = false,
)
},
videoUrl = movieInfo.video?.videoId
)
Spacer(modifier = Modifier.height(24.dp))
MovieInformation(movieInfo = movieInfo)
Expand Down Expand Up @@ -257,7 +264,7 @@ private fun CastItem(castItem: MovieInfo.CastItem, modifier: Modifier = Modifier
.size(80.dp)
.clip(CircleShape),
contentScale = ContentScale.Crop,
error = painterResource(id = com.jik.core.ui.R.drawable.default_profile)
error = painterResource(id = com.jik.core.designsystem.R.drawable.default_profile)
)
Spacer(modifier = Modifier.height(8.dp))
Text(
Expand Down
9 changes: 7 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ retrofit = "2.9.0"
logging-interceptor = "4.11.0"
ksp = "1.8.10-1.0.9"
splashscreen = "1.0.0"

media3 = "1.1.0"
chaquopy = "15.0.0"

androidGradlePlugin = "7.4.2"

Expand Down Expand Up @@ -87,11 +88,15 @@ logging-interceptor = { group = "com.squareup.okhttp3", name = "logging-intercep
# Splash
splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "splashscreen" }

# Media3
media3-exoplayer = { group = "androidx.media3", name = "media3-exoplayer", version.ref = "media3" }
media3-ui = { group = "androidx.media3", name = "media3-ui", version.ref = "media3" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
hilt-plugin = { id = "dagger.hilt.android.plugin", version.ref = "hilt" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
chaquopy = { id = "com.chaquo.python", version.ref = "chaquopy" }
1 change: 1 addition & 0 deletions lib-videoplayer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
75 changes: 75 additions & 0 deletions lib-videoplayer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.chaquopy)
}

android {
namespace = "com.jik.lib.videoplayer"
compileSdk = 33

defaultConfig {
minSdk = 24
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")

ndk {
abiFilters += listOf("armeabi-v7a", "arm64-v8a")
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
}

chaquopy {
defaultConfig {
pip {
install("pytube")
}
}
}

dependencies {

implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

// compose
implementation(libs.compose.ui)
implementation(libs.compose.material3)
implementation(libs.compose.material.icons)

// exoplayer
implementation(libs.media3.exoplayer)
implementation(libs.media3.ui)


}
Empty file.
21 changes: 21 additions & 0 deletions lib-videoplayer/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jik.lib.videoplayer

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.jik.lib.videoplayer.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions lib-videoplayer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jik.lib.videoplayer

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow

object VideoPlayerIcons {

val Play = Icons.Filled.PlayArrow
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jik.lib.videoplayer

sealed interface VideoPlayerState {

object Initial : VideoPlayerState
object Loading : VideoPlayerState
class GetError(val errorMessage: String) : VideoPlayerState
object NoVideo : VideoPlayerState
object CanPlay : VideoPlayerState
}
Loading

0 comments on commit 739bffc

Please sign in to comment.