Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurupreet committed Sep 25, 2020
1 parent 14a0287 commit a3dadf9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MovieRepositoryImpl(
}

override suspend fun addToMyWatchlist(movie: Movie) {
moviesDao.addToWatchList(movie)
moviesDao.addToWatchList(movie)
}

override suspend fun removeFromMyWatchlist(movie: Movie) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import androidx.compose.foundation.lazy.LazyRowFor
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.IconButton
import androidx.compose.material.IconToggleButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LibraryAdd
import androidx.compose.material.icons.outlined.LibraryAdd
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
Expand Down Expand Up @@ -73,6 +71,7 @@ class MovieDetailActivity : AppCompatActivity() {
Intent(context, MovieDetailActivity::class.java).apply {
putExtra(MOVIE, movie)
}

fun newIntent(context: Context, movie: Movie, imageId: Int) =
Intent(context, MovieDetailActivity::class.java).apply {
putExtra(MOVIE, movie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fun MoviePagerItem(
val animateElevation = if (isSelected) 12.dp else 2.dp
val posterFullPath = "https://image.tmdb.org/t/p/w500/${movie.poster_path}"

val movieGenres = movie.genre_ids?.let {
movieGenreIds -> genres.filter { movieGenreIds.contains(it.id) }.take(3)
val movieGenres = movie.genre_ids?.let { movieGenreIds ->
genres.filter { movieGenreIds.contains(it.id) }.take(3)
}

Card(
Expand Down Expand Up @@ -87,8 +87,10 @@ fun MoviePagerItem(
asset = Icons.Default.LibraryAdd,
tint = MaterialTheme.colors.primary,
modifier = Modifier
.drawLayer(rotationY = animate(
if (clicked.value) 720f else 0f, tween(400))
.drawLayer(
rotationY = animate(
if (clicked.value) 720f else 0f, tween(400)
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material.Scaffold
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.LibraryAdd
import androidx.compose.material.icons.outlined.MovieCreation
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Subscriptions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand All @@ -30,7 +29,9 @@ import com.guru.composecookbook.ui.moviesappmvi.data.models.Movie
import com.guru.composecookbook.ui.moviesappmvi.ui.details.MovieDetailActivity

sealed class MoviesHomeInteractionEvents {
data class OpenMovieDetail(val movie: Movie, val imageId: Int = 0) : MoviesHomeInteractionEvents()
data class OpenMovieDetail(val movie: Movie, val imageId: Int = 0) :
MoviesHomeInteractionEvents()

data class AddToMyWatchlist(val movie: Movie) : MoviesHomeInteractionEvents()
data class RemoveFromMyWatchlist(val movie: Movie) : MoviesHomeInteractionEvents()
}
Expand Down Expand Up @@ -59,7 +60,7 @@ class MoviesHomeActivity : AppCompatActivity() {
}
)
MovieNavType.WATCHLIST -> WatchlistScreen(
moviesHomeInteractionEvents = {
moviesHomeInteractionEvents = {
handleInteractionEvents(it, viewModel)
}
)
Expand All @@ -78,8 +79,11 @@ class MoviesHomeActivity : AppCompatActivity() {
) {
when (interactionEvents) {
is MoviesHomeInteractionEvents.OpenMovieDetail -> {
startActivity(MovieDetailActivity.newIntent(
this, interactionEvents.movie, interactionEvents.imageId))
startActivity(
MovieDetailActivity.newIntent(
this, interactionEvents.movie, interactionEvents.imageId
)
)
overridePendingTransition(0, 0)
}
is MoviesHomeInteractionEvents.AddToMyWatchlist -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ fun MoviesPager(
{ moviesHomeInteractionEvents(MoviesHomeInteractionEvents.AddToMyWatchlist(movie)) }
) {
moviesHomeInteractionEvents(
MoviesHomeInteractionEvents.OpenMovieDetail(movie, imageId.value))
MoviesHomeInteractionEvents.OpenMovieDetail(movie, imageId.value)
)
}
}
} else {
Expand All @@ -100,7 +101,6 @@ fun MoviesPager(
}
}


val imageIds =
listOf(
R.drawable.camelia,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class MoviesHomeViewModel(
}

fun addToMyWatchlist(movie: Movie) = viewModelScope.launch(Dispatchers.IO) {
movieRepository.addToMyWatchlist(movie)
}
movieRepository.addToMyWatchlist(movie)
}

fun removeFromMyWatchlist(movie: Movie) = viewModelScope.launch(Dispatchers.IO) {
movieRepository.removeFromMyWatchlist(movie)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
package com.guru.composecookbook.ui.moviesappmvi.ui.home

import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.ColumnScope.align
import androidx.compose.foundation.layout.RowScope.align
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.LazyColumnForIndexed
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.IconButton
import androidx.compose.material.Surface
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.RemoveCircleOutline
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.draw.drawOpacity
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.viewModel
import com.guru.composecookbook.theme.graySurface
import com.guru.composecookbook.theme.typography
import com.guru.composecookbook.ui.demoui.spotify.data.SpotifyDataProvider
import com.guru.composecookbook.ui.moviesappmvi.data.models.Movie
import com.guru.composecookbook.ui.utils.horizontalGradientBackground
import com.guru.composecookbook.ui.utils.verticalGradientBackground
import dev.chrisbanes.accompanist.coil.CoilImage

@Composable
Expand All @@ -47,14 +36,18 @@ fun WatchlistScreen(moviesHomeInteractionEvents: (MoviesHomeInteractionEvents) -
) { index, movie ->
MovieWatchlistItem(
movie,
{ moviesHomeInteractionEvents(
MoviesHomeInteractionEvents.OpenMovieDetail(movie))
{
moviesHomeInteractionEvents(
MoviesHomeInteractionEvents.OpenMovieDetail(movie)
)
},
{ moviesHomeInteractionEvents(
MoviesHomeInteractionEvents.RemoveFromMyWatchlist(movie))
{
moviesHomeInteractionEvents(
MoviesHomeInteractionEvents.RemoveFromMyWatchlist(movie)
)
}
)
if (index == myWatchlist.size -1) {
if (index == myWatchlist.size - 1) {
Spacer(modifier = Modifier.padding(30.dp))
}
}
Expand Down

0 comments on commit a3dadf9

Please sign in to comment.