Skip to content

Commit

Permalink
Merge pull request #135 from VictorKabata/feat-tv-shows
Browse files Browse the repository at this point in the history
Feat tv shows
  • Loading branch information
VictorKabata authored Nov 23, 2024
2 parents 4f2bc0f + 776522b commit 428b4a0
Show file tree
Hide file tree
Showing 33 changed files with 771 additions and 169 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions composeApp/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
<string name="title_settings">Settings</string>
<string name="title_details">Details</string>

<string name="movies">Movies</string>
<string name="tv_shows">TV Shows</string>
<string name="categories">Categories</string>

<string name="trending_movies">Trending Movies</string>
<string name="popular_movies">Popular Movies</string>
<string name="upcoming_movies">Upcoming Movies</string>
<string name="view_all">View All</string>

<string name="trending_tv_shows">Trending TV Shows</string>
<string name="top_rated_tv_shows">Top Rated TV Shows</string>
<string name="popular_tv_shows">Popular TV Shows</string>

<string name="share">Share</string>

<!--Preference Titles-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.vickbt.composeApp.data.datasources

import app.cash.paging.Pager
import app.cash.paging.PagingConfig
import app.cash.paging.PagingData
import com.vickbt.composeApp.data.mappers.toDomain
import com.vickbt.composeApp.data.network.models.TvShowResultsDto
import com.vickbt.composeApp.data.network.utils.safeApiCall
import com.vickbt.composeApp.data.paging.BasePagingSource
import com.vickbt.composeApp.domain.models.TvShow
import com.vickbt.composeApp.domain.repositories.TvShowsRepository
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import kotlinx.coroutines.flow.Flow

class TvShowsRepositoryImpl(private val httpClient: HttpClient) : TvShowsRepository {

private val pagingConfig = PagingConfig(pageSize = 20, enablePlaceholders = false)

override suspend fun fetchAiringTodayTvShows(
language: String,
sortBy: String
): Result<Flow<List<TvShow>?>> {
return safeApiCall {
val response =
httpClient.get(urlString = "discover/tv?include_adult=true&language=$language&page=1&sort_by=$sortBy&air_date.lte={max_date}&air_date.gte={min_date}").body<TvShowResultsDto>()

response.tvShows?.map { it.toDomain() }
}
}

override suspend fun fetchTrendingTVShows(
timeWindow: String,
language: String
): Result<Flow<PagingData<TvShow>>> {
val pagingSource = BasePagingSource { page ->
val response =
httpClient.get(urlString = "trending/tv/$timeWindow?language=$language") {
parameter("page", page)
}.body<TvShowResultsDto>().tvShows

response?.map { it.toDomain() }
}

return runCatching {
Pager(config = pagingConfig, pagingSourceFactory = { pagingSource }).flow
}
}

override suspend fun fetchTopRatedTvShows(
language: String,
sortBy: String,
voteCount: String
): Result<Flow<PagingData<TvShow>>> {
val pagingSource = BasePagingSource { page ->
val response =
httpClient.get(urlString = "discover/tv?include_adult=true&language=$language&page=$page&sort_by=$sortBy&vote_count.gte=$voteCount")
.body<TvShowResultsDto>().tvShows

response?.map { it.toDomain() }
}

return runCatching {
Pager(config = pagingConfig, pagingSourceFactory = { pagingSource }).flow
}
}

override suspend fun fetchPopularTvShows(
language: String,
sortBy: String
): Result<Flow<PagingData<TvShow>>> {
val pagingSource = BasePagingSource { page ->
val response =
httpClient.get(urlString = "discover/tv?include_adult=true&language=$language&page=$page&sort_by=$sortBy")
.body<TvShowResultsDto>().tvShows

response?.map { it.toDomain() }
}

return runCatching {
Pager(config = pagingConfig, pagingSourceFactory = { pagingSource }).flow
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.vickbt.composeApp.data.network.models.CastDto
import com.vickbt.composeApp.data.network.models.ErrorResponseDto
import com.vickbt.composeApp.data.network.models.MovieDetailsDto
import com.vickbt.composeApp.data.network.models.MovieDto
import com.vickbt.composeApp.data.network.models.TvShowDto
import com.vickbt.composeApp.data.network.models.VideoDto
import com.vickbt.composeApp.domain.models.Actor
import com.vickbt.composeApp.domain.models.Cast
import com.vickbt.composeApp.domain.models.ErrorResponse
import com.vickbt.composeApp.domain.models.Movie
import com.vickbt.composeApp.domain.models.MovieDetails
import com.vickbt.composeApp.domain.models.TvShow
import com.vickbt.composeApp.domain.models.Video

fun MovieDto.toDomain(): Movie {
Expand All @@ -32,6 +34,24 @@ fun MovieDto.toDomain(): Movie {
)
}

fun TvShowDto.toDomain(): TvShow {
return TvShow(
adult = this.adult,
backdropPath = this.backdropPath,
id = this.id,
name = this.name,
overview = this.overview,
posterPath = this.posterPath,
mediaType = this.mediaType,
genreIds = this.genreIds,
popularity = this.popularity,
firstAirDate = this.firstAirDate,
voteAverage = this.voteAverage,
voteCount = this.voteCount,
originCountry = this.originCountry
)
}

fun MovieDetailsDto.toDomain(): MovieDetails {
return MovieDetails(
adult = this.adult,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.vickbt.composeApp.data.network.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TvShowDto(
val adult: Boolean? = null,

@SerialName("backdrop_path")
val backdropPath: String? = null,

val id: Int,

val name: String? = null,

val overview: String? = null,

@SerialName("poster_path")
val posterPath: String? = null,

@SerialName("media_type")
val mediaType: String? = null,

@SerialName("genre_ids")
val genreIds: List<Int>? = null,

val popularity: Double? = null,

@SerialName("first_air_date")
val firstAirDate: String? = null,

@SerialName("vote_average")
val voteAverage: Double? = null,

@SerialName("vote_count")
val voteCount: Int? = null,

@SerialName("origin_country")
val originCountry: List<String>? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.vickbt.composeApp.data.network.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TvShowResultsDto(
@SerialName("page")
val page: Int? = null,

@SerialName("results")
val tvShows: List<TvShowDto>? = null,

@SerialName("total_pages")
val totalPages: Int? = null,

@SerialName("total_results")
val totalResults: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import com.vickbt.composeApp.data.datasources.MovieDetailsRepositoryImpl
import com.vickbt.composeApp.data.datasources.MoviesRepositoryImpl
import com.vickbt.composeApp.data.datasources.SearchRepositoryImpl
import com.vickbt.composeApp.data.datasources.SettingsRepositoryImpl
import com.vickbt.composeApp.data.datasources.TvShowsRepositoryImpl
import com.vickbt.composeApp.domain.repositories.FavoritesRepository
import com.vickbt.composeApp.domain.repositories.MovieDetailsRepository
import com.vickbt.composeApp.domain.repositories.MoviesRepository
import com.vickbt.composeApp.domain.repositories.SearchRepository
import com.vickbt.composeApp.domain.repositories.SettingsRepository
import com.vickbt.composeApp.domain.repositories.TvShowsRepository
import com.vickbt.composeApp.domain.utils.Constants.BASE_URL
import com.vickbt.composeApp.domain.utils.Constants.URL_PATH
import com.vickbt.composeApp.ui.screens.details.DetailsViewModel
Expand Down Expand Up @@ -80,6 +82,7 @@ fun commonModule(enableNetworkLogs: Boolean) = module {
}

single<MoviesRepository> { MoviesRepositoryImpl(httpClient = get()) }
single<TvShowsRepository> { TvShowsRepositoryImpl(httpClient = get()) }
single<MovieDetailsRepository> {
MovieDetailsRepositoryImpl(httpClient = get(), appDatabase = get())
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.vickbt.composeApp.domain.models

data class TvShow(
val adult: Boolean? = null,
val backdropPath: String? = null,
val id: Int,
val name: String? = null,
val overview: String? = null,
val posterPath: String? = null,
val mediaType: String? = null,
val genreIds: List<Int>? = null,
val popularity: Double? = null,
val firstAirDate: String? = null,
val voteAverage: Double? = null,
val voteCount: Int? = null,
val originCountry: List<String>? = null,
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.vickbt.composeApp.domain.repositories

import app.cash.paging.PagingData
import com.vickbt.composeApp.domain.models.TvShow
import kotlinx.coroutines.flow.Flow

interface TvShowsRepository {
/** Fetch Tv Shows airing today from data source*/
suspend fun fetchAiringTodayTvShows(
language: String = "en-US",
sortBy: String = "popularity.desc"
): Result<Flow<List<TvShow>?>>

/** Fetch trending Tv Shows from data source*/
suspend fun fetchTrendingTVShows(
timeWindow: String = "week",
language: String = "en-US"
): Result<Flow<PagingData<TvShow>>>

/** Fetch top rated Tv Shows from data source*/
suspend fun fetchTopRatedTvShows(
language: String = "en-US",
sortBy: String = "vote_average.desc",
voteCount: String = "200"
): Result<Flow<PagingData<TvShow>>>

/** Fetch popular Tv Shows from data source*/
suspend fun fetchPopularTvShows(
language: String = "en-US",
sortBy: String = "popularity.desc"
): Result<Flow<PagingData<TvShow>>>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.vickbt.composeApp.domain.utils

object Enums {
enum class MovieCategories {
NOW_PLAYING, POPULAR, TRENDING, UPCOMING

enum class MediaType {
TV_SHOW, MOVIE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.vickbt.composeApp.ui.navigation.NavigationItem
Expand All @@ -23,7 +24,7 @@ fun BottomNavBar(
) {
NavigationBar(
modifier = modifier.fillMaxWidth(),
containerColor = MaterialTheme.colorScheme.surface.copy(alpha = .85f)
containerColor = MaterialTheme.colorScheme.background.copy(alpha = .85f)
) {
bottomNavItems.iterator().forEach { item ->

Expand All @@ -48,8 +49,9 @@ fun BottomNavBar(
},
alwaysShowLabel = true,
colors = NavigationBarItemDefaults.colors(
selectedIconColor = MaterialTheme.colorScheme.primary,
unselectedIconColor = Gray
selectedIconColor = MaterialTheme.colorScheme.onBackground,
unselectedIconColor = Gray,
indicatorColor = Color.Transparent
),
selected = isSelected,
onClick = {
Expand Down
Loading

0 comments on commit 428b4a0

Please sign in to comment.