Skip to content

Commit

Permalink
Merge pull request #81 from Divinelink/feature/all-ratings
Browse files Browse the repository at this point in the history
Introduce Ratings from IMDb & Trakt
  • Loading branch information
Divinelink authored Dec 25, 2024
2 parents f164e64 + 3835f54 commit fac19f6
Show file tree
Hide file tree
Showing 89 changed files with 2,131 additions and 352 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ jobs:
- name: Auth token to local.properties
env:
TMDB_AUTH_TOKEN: ${{ secrets.TMDB_AUTH_TOKEN }}
run: echo "TMDB_AUTH_TOKEN=${TMDB_AUTH_TOKEN}" >> local.properties
OMDB_API_KEY: ${{ secrets.OMDB_API_KEY }}
TRAKT_API_KEY: ${{ secrets.TRAKT_API_KEY }}
run:
echo "TMDB_AUTH_TOKEN=${TMDB_AUTH_TOKEN}" >> local.properties
echo "OMDB_API_KEY=${OMDB_API_KEY}" >> local.properties
echo "TRAKT_API_KEY=${TRAKT_API_KEY}" >> local.properties

- name: Decode and create google-services.json
env:
Expand All @@ -63,6 +68,8 @@ jobs:
SIGNING_KEY_PASSWORD: ${{ secrets.STORE_PASSWORD }}
SIGNING_STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
TMDB_AUTH_TOKEN: ${{ secrets.TMDB_AUTH_TOKEN }}
OMDB_API_KEY: ${{ secrets.OMDB_API_KEY }}
TRAKT_API_KEY: ${{ secrets.TRAKT_API_KEY }}
- name: Upload
uses: actions/upload-artifact@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import androidx.room.Room
import com.divinelink.core.database.AppDatabase
import com.divinelink.core.database.AppDatabase.Companion.DB_NAME
import com.divinelink.core.database.media.dao.MediaDao
import com.divinelink.core.network.client.RestClient
import com.divinelink.scenepeek.ui.ThemedActivityDelegate
import com.divinelink.scenepeek.ui.ThemedActivityDelegateImpl
import com.google.firebase.ktx.BuildConfig
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
import com.google.firebase.remoteconfig.ktx.remoteConfig
import io.ktor.client.engine.HttpClientEngine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.koin.core.module.dsl.bind
Expand All @@ -30,9 +28,6 @@ val appModule = module {

single<MediaDao> { get<AppDatabase>().mediaDao() }

// Transfer to network module
single<RestClient> { RestClient(get<HttpClientEngine>()) }

single {
Firebase.remoteConfig.apply {
setConfigSettingsAsync(get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object DetailsResponseApiFactory {
genres = GenreFactory.all(),
homepage = null,
id = 1123,
imdbId = null,
imdbId = "tt0137523",
originalLanguage = "",
originalTitle = "",
overview = "This movie is good.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import app.cash.turbine.test
import com.divinelink.core.data.details.model.MediaDetailsException
import com.divinelink.core.data.details.model.SimilarException
import com.divinelink.core.data.details.model.VideosException
import com.divinelink.core.fixtures.model.details.MediaDetailsFactory
import com.divinelink.core.model.details.DetailsMenuOptions
import com.divinelink.core.model.details.Movie
import com.divinelink.core.model.details.Review
import com.divinelink.core.model.details.rating.RatingCount
import com.divinelink.core.model.details.rating.RatingSource
import com.divinelink.core.model.details.video.Video
import com.divinelink.core.model.details.video.VideoSite
Expand Down Expand Up @@ -51,19 +50,7 @@ class GetMediaDetailsUseCaseTest {
private lateinit var preferenceStorage: FakePreferenceStorage

private val request = DetailsRequestApi.Movie(movieId = 555)
private val movieDetails = Movie(
id = 0,
title = "",
posterPath = "",
overview = null,
director = null,
genres = listOf(),
cast = listOf(),
releaseDate = "",
ratingCount = RatingCount.initial(0.0, 0),
isFavorite = false,
runtime = "50m",
)
private val movieDetails = MediaDetailsFactory.FightClub()

private val reviewsList = (1..10).map {
Review(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package com.divinelink.scenepeek.details.ui
import androidx.compose.material3.SnackbarResult
import androidx.lifecycle.SavedStateHandle
import com.divinelink.core.domain.credits.SpoilersObfuscationUseCase
import com.divinelink.core.model.details.rating.RatingDetails
import com.divinelink.core.model.details.rating.RatingSource
import com.divinelink.core.model.jellyseerr.request.JellyseerrMediaRequest
import com.divinelink.core.model.media.MediaItem
import com.divinelink.core.model.media.MediaType
import com.divinelink.core.navigation.arguments.DetailsNavArguments
import com.divinelink.core.testing.MainDispatcherRule
import com.divinelink.core.testing.ViewModelTestRobot
import com.divinelink.core.testing.storage.FakePreferenceStorage
import com.divinelink.core.testing.usecase.FakeRequestMediaUseCase
import com.divinelink.core.testing.usecase.TestFetchAllRatingsUseCase
import com.divinelink.feature.details.media.ui.DetailsViewModel
import com.divinelink.feature.details.media.ui.DetailsViewState
import com.divinelink.feature.details.media.ui.MediaDetailsResult
Expand All @@ -18,13 +23,18 @@ import com.divinelink.scenepeek.fakes.usecase.details.FakeAddToWatchlistUseCase
import com.divinelink.scenepeek.fakes.usecase.details.FakeDeleteRatingUseCase
import com.divinelink.scenepeek.fakes.usecase.details.FakeSubmitRatingUseCase
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import org.junit.Rule

class DetailsViewModelRobot {
class DetailsViewModelRobot : ViewModelTestRobot<DetailsViewState>() {

private lateinit var navArgs: DetailsNavArguments
private lateinit var viewModel: DetailsViewModel

override val actualUiState: Flow<DetailsViewState>
get() = viewModel.viewState

@get:Rule
val mainDispatcherRule = MainDispatcherRule()

Expand All @@ -34,15 +44,13 @@ class DetailsViewModelRobot {
private val fakeDeleteRatingUseCase = FakeDeleteRatingUseCase()
private val fakeAddToWatchListUseCase = FakeAddToWatchlistUseCase()
private val fakeRequestMediaUseCase = FakeRequestMediaUseCase()
private val testFetchAllRatingsUseCase = TestFetchAllRatingsUseCase()
private val spoilersObfuscationUseCase = SpoilersObfuscationUseCase(
preferenceStorage = FakePreferenceStorage(),
dispatcherProvider = mainDispatcherRule.testDispatcher,
)

fun buildViewModel(
id: Int,
mediaType: MediaType,
) = apply {
override fun buildViewModel() = apply {
viewModel = DetailsViewModel(
onMarkAsFavoriteUseCase = fakeMarkAsFavoriteUseCase,
getMediaDetailsUseCase = fakeGetMovieDetailsUseCase.mock,
Expand All @@ -51,10 +59,11 @@ class DetailsViewModelRobot {
addToWatchlistUseCase = fakeAddToWatchListUseCase.mock,
requestMediaUseCase = fakeRequestMediaUseCase.mock,
spoilersObfuscationUseCase = spoilersObfuscationUseCase,
fetchAllRatingsUseCase = testFetchAllRatingsUseCase.mock,
savedStateHandle = SavedStateHandle(
mapOf(
"id" to id,
"mediaType" to mediaType.value,
"id" to navArgs.id,
"mediaType" to navArgs.mediaType,
"isFavorite" to false,
),
),
Expand Down Expand Up @@ -109,6 +118,10 @@ class DetailsViewModelRobot {
viewModel.onRequestMedia(seasons)
}

fun onFetchAllRating() = apply {
viewModel.onFetchAllRating()
}

fun onObfuscateSpoilers() = apply {
viewModel.onObfuscateSpoilers()
}
Expand All @@ -121,6 +134,18 @@ class DetailsViewModelRobot {
viewModel.consumeNavigateToLogin()
}

fun withNavArguments(
id: Int,
mediaType: MediaType,
isFavorite: Boolean = false,
) = apply {
navArgs = DetailsNavArguments(
id = id,
mediaType = mediaType.value,
isFavorite = isFavorite,
)
}

// Mock Functions

fun mockMarkAsFavoriteUseCase(
Expand Down Expand Up @@ -154,5 +179,8 @@ class DetailsViewModelRobot {
suspend fun mockSpoilersObfuscation(obfuscated: Boolean) = apply {
spoilersObfuscationUseCase.setSpoilersObfuscation(obfuscated)
}

fun mockFetchAllRatingsUseCase(response: Channel<Result<Pair<RatingSource, RatingDetails>>>) =
apply { testFetchAllRatingsUseCase.mockSuccess(response) }
// End Mock Functions
}
Loading

0 comments on commit fac19f6

Please sign in to comment.