Skip to content

Commit

Permalink
Merge pull request #28 from sdeparte/sylvain-fix-issue-20
Browse files Browse the repository at this point in the history
Add movie budget in MovieScreen
  • Loading branch information
Ribesg authored May 24, 2024
2 parents a1781cc + a74b937 commit 68a818f
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DefaultTmdbRepository(
if (tmdbMovieRecord == null) return@map null
TmdbMovie(
backdropPath = tmdbMovieRecord.backdropPath,
budget = tmdbMovieRecord.budget,
id = tmdbMovieRecord.id,
overview = tmdbMovieRecord.overview,
posterPath = tmdbMovieRecord.posterPath,
Expand All @@ -52,6 +53,7 @@ class DefaultTmdbRepository(
tmdbApiDataSource.getMovieDetails(id, language).let { details ->
TmdbMovie(
backdropPath = details.backdropPath,
budget = details.budget,
id = details.id,
overview = details.overview,
posterPath = details.posterPath,
Expand All @@ -69,6 +71,7 @@ class DefaultTmdbRepository(
override suspend fun setLocalTmdbMovie(tmdbMovie: TmdbMovie, fetchDate: Instant, language: String) {
tmdbMoviesQueries.createOrUpdateTmdbMovie(
backdropPath = tmdbMovie.backdropPath,
budget = tmdbMovie.budget,
fetchDate = fetchDate,
id = tmdbMovie.id,
language = language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class TmdbApiDataSource {
@Serializable
data class TmdbMovieDetails(
val backdropPath: String?,
val budget: Long?,
val id: TmdbMovieId,
val overview: String?,
val posterPath: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class Movie(
val backdropPath: String?,
val budget: Int?,
val id: MovieId,
val overview: String?,
val posterPath: String?,
Expand All @@ -22,6 +23,7 @@ data class Movie(

constructor(localMovie: LocalMovie, tmdbMovie: TmdbMovie?) : this(
backdropPath = tmdbMovie?.backdropPath,
budget = tmdbMovie?.budget?.toInt(),
id = localMovie.id,
overview = tmdbMovie?.overview,
posterPath = tmdbMovie?.posterPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlin.time.Duration.Companion.days
@Serializable
data class TmdbMovie(
val backdropPath: String?,
val budget: Long?,
val id: TmdbMovieId,
val overview: String?,
val posterPath: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Wallet
import androidx.compose.material.icons.automirrored.outlined.StarHalf
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Visibility
Expand Down Expand Up @@ -54,6 +57,7 @@ import com.wizbii.cinematic.journey.presentation.component.MovieListItem
import com.wizbii.cinematic.journey.presentation.component.RemoteImage
import com.wizbii.cinematic.journey.presentation.component.scrollbar.ColumnWithScrollbar
import com.wizbii.cinematic.journey.presentation.component.top.bar.TopBarContent
import com.wizbii.cinematic.journey.presentation.util.formatHumanReadable
import com.wizbii.cinematic.journey.presentation.util.performHaptic
import com.wizbii.cinematic.journey.presentation.util.toString
import com.wizbii.cinematic.journey.whenPlatform
Expand Down Expand Up @@ -412,8 +416,10 @@ private fun TitleColumn(
textAlign = TextAlign.Center,
)

Row(
@OptIn(ExperimentalLayoutApi::class)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally),
verticalArrangement = Arrangement.spacedBy(4.dp),
modifier = Modifier.fillMaxWidth(),
) {

Expand All @@ -440,6 +446,15 @@ private fun TitleColumn(

}

movie.budget?.let { budget ->

Chip(
icon = Icons.Filled.Wallet,
text = "${budget.formatHumanReadable()}\$",
)

}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PreviewMovieComponent : MovieComponent {
override val movie = MutableStateFlow(
Movie(
backdropPath = null,
budget = 1000,
id = MovieId("id"),
overview = "Harley Quinn joins forces with a singer, an assassin and a police detective to help a young girl who had a hit placed on her after she stole a rare diamond from a crime lord.",
posterPath = null,
Expand All @@ -35,6 +36,7 @@ class PreviewMovieComponent : MovieComponent {
List(5) { index ->
Movie(
backdropPath = null,
budget = 1000,
id = MovieId(index.toString()),
overview = null,
posterPath = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PreviewMoviesComponent : MoviesComponent {
List(10) { index ->
Movie(
backdropPath = null,
budget = 1000,
id = MovieId(index.toString()),
overview = null,
posterPath = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ package com.wizbii.cinematic.journey.presentation.util

import kotlin.math.roundToLong

fun Number.formatHumanReadable(): String {
val suffix = arrayOf("", "K", "M", "G", "T", "P", "E", "Z", "Y")

var suffixIndex = 0
var value = toDouble()

while (value > 1000 && suffixIndex in suffix.indices) {
value /= 1000
suffixIndex++
}

return "$value ${suffix[suffixIndex]}"
}

fun Number.toString(maxDecimals: Int = 1): String {

require(maxDecimals >= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE tmdbMovieRecord (

-- TMDB Data
backdropPath TEXT,
budget INTEGER,
fetchDate INTEGER AS Instant NOT NULL,
overview TEXT,
posterPath TEXT,
Expand All @@ -33,6 +34,7 @@ createOrUpdateTmdbMovie {
-- Does nothing if missing
UPDATE tmdbMovieRecord
SET backdropPath = :backdropPath,
budget = :budget,
fetchDate = :fetchDate,
overview = :overview,
posterPath = :posterPath,
Expand All @@ -50,6 +52,7 @@ createOrUpdateTmdbMovie {
id,
language,
backdropPath,
budget,
fetchDate,
overview,
posterPath,
Expand All @@ -63,6 +66,7 @@ createOrUpdateTmdbMovie {
:id,
:language,
:backdropPath,
:budget,
:fetchDate,
:overview,
:posterPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE tmdbMovieRecord ADD COLUMN budget INTEGER;

0 comments on commit 68a818f

Please sign in to comment.