diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4779559..23cf02b 100755 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,8 +53,8 @@ android { applicationId = "com.application.moviesapp" minSdk = 24 targetSdk = 33 - versionCode = 21 - versionName = "1.0.20" + versionCode = 22 + versionName = "1.0.21" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/com/application/moviesapp/data/api/MoviesApi.kt b/app/src/main/java/com/application/moviesapp/data/api/MoviesApi.kt index 5b8f1ed..ed437a8 100755 --- a/app/src/main/java/com/application/moviesapp/data/api/MoviesApi.kt +++ b/app/src/main/java/com/application/moviesapp/data/api/MoviesApi.kt @@ -11,7 +11,7 @@ import com.application.moviesapp.data.api.response.MovieDetailsDto import com.application.moviesapp.data.remote.MovieFavouriteDto import com.application.moviesapp.data.api.response.MovieGenreResponse import com.application.moviesapp.data.api.response.MovieNowPlayingDto -import com.application.moviesapp.data.api.response.MovieReviewDto +import com.application.moviesapp.data.api.response.UserReviewDto import com.application.moviesapp.data.api.response.MovieSearchDto import com.application.moviesapp.data.api.response.MovieSimpleResponse import com.application.moviesapp.data.api.response.MovieStateDto @@ -23,7 +23,6 @@ import com.application.moviesapp.data.api.response.TvSeriesDetailsDto import com.application.moviesapp.data.api.response.TvSeriesDiscoverDto import com.application.moviesapp.data.api.response.TvSeriesEpisodesDto import com.application.moviesapp.data.api.response.TvSeriesNowPlayingDto -import com.application.moviesapp.data.api.response.TvSeriesReviewDto import com.application.moviesapp.data.api.response.TvSeriesSearchDto import com.application.moviesapp.data.api.response.TvSeriesTrailerDto import com.application.moviesapp.data.remote.MovieNewReleasesDto @@ -131,8 +130,8 @@ interface MoviesApi { suspend fun getTvSeriesBySearch(@Query("language") language: String = "en-US", @Query("query") query: String = "", @Query("page") page: Int = 1): Response @GET("/3/movie/{movie_id}/reviews") - suspend fun getMovieReview(@Path("movie_id") movieId: Int, @Query("language") language: String = "en-US", @Query("page") page: Int = 1): Response + suspend fun getMovieReview(@Path("movie_id") movieId: Int, @Query("language") language: String = "en-US", @Query("page") page: Int = 1): Response @GET("/3/tv/{series_id}/reviews") - suspend fun getTvSeriesReview(@Path("series_id") seriesId: Int, @Query("language") language: String = "en-US", @Query("page") page: Int = 1): Response + suspend fun getTvSeriesReview(@Path("series_id") seriesId: Int, @Query("language") language: String = "en-US", @Query("page") page: Int = 1): Response } \ No newline at end of file diff --git a/app/src/main/java/com/application/moviesapp/data/api/response/TvSeriesReviewDto.kt b/app/src/main/java/com/application/moviesapp/data/api/response/TvSeriesReviewDto.kt deleted file mode 100644 index f794137..0000000 --- a/app/src/main/java/com/application/moviesapp/data/api/response/TvSeriesReviewDto.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.application.moviesapp.data.api.response - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class TvSeriesReviewDto( - - @SerialName("id") - val id: Int?, - - @SerialName("page") - val page: Int?, - - @SerialName("results") - val results: List?, - - @SerialName("total_pages") - val totalPages: Int?, - - @SerialName("total_results") - val totalResults: Int? -) { - - @Serializable - data class Result( - - @SerialName("author") - val author: String?, - - @SerialName("author_details") - val authorDetails: AuthorDetails?, - - @SerialName("content") - val content: String?, - - @SerialName("created_at") - val createdAt: String?, - - @SerialName("id") - val id: String?, - - @SerialName("updated_at") - val updatedAt: String?, - - @SerialName("url") - val url: String? - ) { - - @Serializable - data class AuthorDetails( - - @SerialName("avatar_path") - val avatarPath: String?, - - @SerialName("name") - val name: String?, - - @SerialName("rating") - val rating: Double?, - - @SerialName("username") - val username: String? - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/application/moviesapp/data/api/response/MovieReviewDto.kt b/app/src/main/java/com/application/moviesapp/data/api/response/UserReviewDto.kt similarity index 97% rename from app/src/main/java/com/application/moviesapp/data/api/response/MovieReviewDto.kt rename to app/src/main/java/com/application/moviesapp/data/api/response/UserReviewDto.kt index cf8c282..b550f18 100644 --- a/app/src/main/java/com/application/moviesapp/data/api/response/MovieReviewDto.kt +++ b/app/src/main/java/com/application/moviesapp/data/api/response/UserReviewDto.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class MovieReviewDto( +data class UserReviewDto( @SerialName("id") val id: Int?, diff --git a/app/src/main/java/com/application/moviesapp/data/mappers/TvSeriesMappers.kt b/app/src/main/java/com/application/moviesapp/data/mappers/TvSeriesMappers.kt old mode 100755 new mode 100644 diff --git a/app/src/main/java/com/application/moviesapp/data/mappers/TvSeriesReviewMappers.kt b/app/src/main/java/com/application/moviesapp/data/mappers/TvSeriesReviewMappers.kt deleted file mode 100644 index da5ba66..0000000 --- a/app/src/main/java/com/application/moviesapp/data/mappers/TvSeriesReviewMappers.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.application.moviesapp.data.mappers - -import com.application.moviesapp.data.api.response.TvSeriesReviewDto -import com.application.moviesapp.domain.model.MovieReview -import com.application.moviesapp.domain.model.TvSeriesReview - -fun TvSeriesReviewDto.Result.toDomain(): TvSeriesReview { - return TvSeriesReview( - author = this.author, - content = this.content, - createdAt = this.createdAt, - id = this.id, - updatedAt = this.updatedAt, - url = this.url, - authorDetails = TvSeriesReview.AuthorDetails( - avatarPath = this.authorDetails?.avatarPath, - name = this.authorDetails?.name, - username = this.authorDetails?.username, - rating = this.authorDetails?.rating - ) - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/application/moviesapp/data/mappers/MovieReviewMappers.kt b/app/src/main/java/com/application/moviesapp/data/mappers/UserReviewMappers.kt similarity index 64% rename from app/src/main/java/com/application/moviesapp/data/mappers/MovieReviewMappers.kt rename to app/src/main/java/com/application/moviesapp/data/mappers/UserReviewMappers.kt index fec9581..5df1906 100644 --- a/app/src/main/java/com/application/moviesapp/data/mappers/MovieReviewMappers.kt +++ b/app/src/main/java/com/application/moviesapp/data/mappers/UserReviewMappers.kt @@ -1,17 +1,17 @@ package com.application.moviesapp.data.mappers -import com.application.moviesapp.data.api.response.MovieReviewDto -import com.application.moviesapp.domain.model.MovieReview +import com.application.moviesapp.data.api.response.UserReviewDto +import com.application.moviesapp.domain.model.UserReview -fun MovieReviewDto.Result.toDomain(): MovieReview { - return MovieReview( +fun UserReviewDto.Result.toDomain(): UserReview { + return UserReview( author = this.author, content = this.content, createdAt = this.createdAt, id = this.id, updatedAt = this.updatedAt, url = this.url, - authorDetails = MovieReview.AuthorDetails( + authorDetails = UserReview.AuthorDetails( avatarPath = this.authorDetails?.avatarPath, name = this.authorDetails?.name, username = this.authorDetails?.username, diff --git a/app/src/main/java/com/application/moviesapp/data/remote/MovieReviewPagingSource.kt b/app/src/main/java/com/application/moviesapp/data/remote/MovieReviewPagingSource.kt index dd95770..f894825 100644 --- a/app/src/main/java/com/application/moviesapp/data/remote/MovieReviewPagingSource.kt +++ b/app/src/main/java/com/application/moviesapp/data/remote/MovieReviewPagingSource.kt @@ -3,24 +3,23 @@ package com.application.moviesapp.data.remote import androidx.paging.PagingSource import androidx.paging.PagingState import com.application.moviesapp.data.api.MoviesApi -import com.application.moviesapp.data.api.response.MovieReviewDto -import com.application.moviesapp.data.api.response.MovieSearchDto +import com.application.moviesapp.data.api.response.UserReviewDto import timber.log.Timber -class MovieReviewPagingSource(private val moviesApi: MoviesApi, private val movieId: Int): PagingSource() { +class MovieReviewPagingSource(private val moviesApi: MoviesApi, private val movieId: Int): PagingSource() { private companion object { const val TAG = "MovieReviewPagingSource" } - override fun getRefreshKey(state: PagingState): Int? { + override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { anchorPosition -> state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) ?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1) } } - override suspend fun load(params: LoadParams): LoadResult { + override suspend fun load(params: LoadParams): LoadResult { Timber.tag(TAG).d("%s Called!", TAG) @@ -37,7 +36,7 @@ class MovieReviewPagingSource(private val moviesApi: MoviesApi, private val movi } LoadResult.Page( - data = movies?.results?.map { it ?: MovieReviewDto.Result(null, null, null, null, null, null, null)} ?: listOf(), + data = movies?.results?.map { it ?: UserReviewDto.Result(null, null, null, null, null, null, null)} ?: listOf(), prevKey = if (page == 1) null else page.minus(1), nextKey = if (movies?.results?.isEmpty() == true) null else page.plus(1), ) diff --git a/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesPagingSource.kt b/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesPagingSource.kt index 5f0677c..d0776d1 100644 --- a/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesPagingSource.kt +++ b/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesPagingSource.kt @@ -3,24 +3,23 @@ package com.application.moviesapp.data.remote import androidx.paging.PagingSource import androidx.paging.PagingState import com.application.moviesapp.data.api.MoviesApi -import com.application.moviesapp.data.api.response.MovieReviewDto -import com.application.moviesapp.data.api.response.TvSeriesReviewDto +import com.application.moviesapp.data.api.response.UserReviewDto import timber.log.Timber -class TvSeriesReviewPagingSource(private val moviesApi: MoviesApi, private val seriesId: Int): PagingSource() { +class TvSeriesReviewPagingSource(private val moviesApi: MoviesApi, private val seriesId: Int): PagingSource() { private companion object { const val TAG = "TvSeriesReviewPagingSource" } - override fun getRefreshKey(state: PagingState): Int? { + override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { anchorPosition -> state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) ?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1) } } - override suspend fun load(params: LoadParams): LoadResult { + override suspend fun load(params: LoadParams): LoadResult { Timber.tag(TAG).d("%s Called!", TAG) @@ -37,7 +36,7 @@ class TvSeriesReviewPagingSource(private val moviesApi: MoviesApi, private val s } LoadResult.Page( - data = movies?.results?.map { it ?: TvSeriesReviewDto.Result(null, null, null, null, null, null, null)} ?: listOf(), + data = movies?.results?.map { it ?: UserReviewDto.Result(null, null, null, null, null, null, null)} ?: listOf(), prevKey = if (page == 1) null else page.minus(1), nextKey = if (movies?.results?.isEmpty() == true) null else page.plus(1), ) diff --git a/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt b/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt index 3c8585b..22e36bb 100755 --- a/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt +++ b/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt @@ -16,7 +16,7 @@ import com.application.moviesapp.data.api.response.MovieDetailsDto import com.application.moviesapp.data.remote.MovieFavouriteDto import com.application.moviesapp.data.api.response.MovieGenreResponse import com.application.moviesapp.data.api.response.MovieNowPlayingDto -import com.application.moviesapp.data.api.response.MovieReviewDto +import com.application.moviesapp.data.api.response.UserReviewDto import com.application.moviesapp.data.api.response.MovieSearchDto import com.application.moviesapp.data.api.response.MovieStateDto import com.application.moviesapp.data.api.response.MovieTopRatedResponse @@ -27,7 +27,6 @@ import com.application.moviesapp.data.api.response.TvSeriesDetailsDto import com.application.moviesapp.data.api.response.TvSeriesDiscoverDto import com.application.moviesapp.data.api.response.TvSeriesEpisodesDto import com.application.moviesapp.data.api.response.TvSeriesNowPlayingDto -import com.application.moviesapp.data.api.response.TvSeriesReviewDto import com.application.moviesapp.data.api.response.TvSeriesSearchDto import com.application.moviesapp.data.api.response.TvSeriesTrailerDto import com.application.moviesapp.data.local.MoviesDatabase @@ -46,7 +45,6 @@ import com.application.moviesapp.data.remote.TvSeriesFavouritePagingSource import com.application.moviesapp.data.remote.TvSeriesNowPlayingPagingSource import com.application.moviesapp.data.remote.TvSeriesReviewPagingSource import com.application.moviesapp.data.remote.TvSeriesSearchPagingSource -import com.application.moviesapp.domain.model.TvSeriesReview import kotlinx.coroutines.flow.Flow import okhttp3.RequestBody import retrofit2.Response @@ -125,9 +123,9 @@ interface MoviesRepository { suspend fun getTvSeriesEpisodes(seriesId: Int, seasonNumber: Int = 1): Response - fun getMovieReviewPagingFlow(movieId: Int): Flow> + fun getMovieReviewPagingFlow(movieId: Int): Flow> - fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow> + fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow> } @OptIn(ExperimentalPagingApi::class) @@ -247,14 +245,14 @@ class MoviesRepositoryImpl @Inject constructor(private val movies: MoviesApi, override suspend fun getTvSeriesNowPlayingList(): Response = movies.getNowPlayingSeriesList() override suspend fun getTvSeriesEpisodes(seriesId: Int, seasonNumber: Int): Response = movies.getTvSeriesEpisodes(seriesId = seriesId, seasonNumber = seasonNumber) - override fun getMovieReviewPagingFlow(movieId: Int): Flow> = Pager( + override fun getMovieReviewPagingFlow(movieId: Int): Flow> = Pager( config = PagingConfig(pageSize = 20), pagingSourceFactory = { MovieReviewPagingSource(movies, movieId) } ).flow - override fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow> = Pager( + override fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow> = Pager( config = PagingConfig(pageSize = 20), pagingSourceFactory = { TvSeriesReviewPagingSource(movies, seriesId) diff --git a/app/src/main/java/com/application/moviesapp/domain/model/TvSeriesReview.kt b/app/src/main/java/com/application/moviesapp/domain/model/TvSeriesReview.kt deleted file mode 100644 index 665d2a8..0000000 --- a/app/src/main/java/com/application/moviesapp/domain/model/TvSeriesReview.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.application.moviesapp.domain.model - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class TvSeriesReview( - - @SerialName("author") - val author: String?, - - @SerialName("author_details") - val authorDetails: AuthorDetails?, - - @SerialName("content") - val content: String?, - - @SerialName("created_at") - val createdAt: String?, - - @SerialName("id") - val id: String?, - - @SerialName("updated_at") - val updatedAt: String?, - - @SerialName("url") - val url: String? -) { - - @Serializable - data class AuthorDetails( - - @SerialName("avatar_path") - val avatarPath: String?, - - @SerialName("name") - val name: String?, - - @SerialName("rating") - val rating: Double?, - - @SerialName("username") - val username: String? - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/application/moviesapp/domain/model/MovieReview.kt b/app/src/main/java/com/application/moviesapp/domain/model/UserReview.kt similarity index 78% rename from app/src/main/java/com/application/moviesapp/domain/model/MovieReview.kt rename to app/src/main/java/com/application/moviesapp/domain/model/UserReview.kt index d7f4976..0cabc35 100644 --- a/app/src/main/java/com/application/moviesapp/domain/model/MovieReview.kt +++ b/app/src/main/java/com/application/moviesapp/domain/model/UserReview.kt @@ -1,9 +1,6 @@ package com.application.moviesapp.domain.model -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -data class MovieReview( +data class UserReview( val author: String?, val authorDetails: AuthorDetails?, val content: String?, diff --git a/app/src/main/java/com/application/moviesapp/domain/usecase/MovieReviewUseCase.kt b/app/src/main/java/com/application/moviesapp/domain/usecase/MovieReviewUseCase.kt index 003ef22..30102ed 100644 --- a/app/src/main/java/com/application/moviesapp/domain/usecase/MovieReviewUseCase.kt +++ b/app/src/main/java/com/application/moviesapp/domain/usecase/MovieReviewUseCase.kt @@ -3,20 +3,18 @@ package com.application.moviesapp.domain.usecase import androidx.paging.PagingData import androidx.paging.map import com.application.moviesapp.data.mappers.toDomain -import com.application.moviesapp.data.mappers.toMovie import com.application.moviesapp.data.repository.MoviesRepository -import com.application.moviesapp.domain.model.MovieReview -import com.application.moviesapp.domain.model.MovieSearch +import com.application.moviesapp.domain.model.UserReview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import javax.inject.Inject interface MovieReviewUseCase { - operator fun invoke(movieId: Int): Flow> + operator fun invoke(movieId: Int): Flow> } class GetMovieReviewInteractor @Inject constructor(private val repository: MoviesRepository): MovieReviewUseCase { - override fun invoke(movieId: Int): Flow> = repository.getMovieReviewPagingFlow(movieId).map { + override fun invoke(movieId: Int): Flow> = repository.getMovieReviewPagingFlow(movieId).map { it.map { movie -> movie.toDomain() } diff --git a/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesReviewUseCase.kt b/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesReviewUseCase.kt index c82091d..e9046ab 100644 --- a/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesReviewUseCase.kt +++ b/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesReviewUseCase.kt @@ -2,21 +2,20 @@ package com.application.moviesapp.domain.usecase import androidx.paging.PagingData import androidx.paging.map +import com.application.moviesapp.data.api.response.UserReviewDto import com.application.moviesapp.data.mappers.toDomain -import com.application.moviesapp.data.remote.TvSeriesReviewPagingSource import com.application.moviesapp.data.repository.MoviesRepository -import com.application.moviesapp.domain.model.MovieReview -import com.application.moviesapp.domain.model.TvSeriesReview +import com.application.moviesapp.domain.model.UserReview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import javax.inject.Inject interface TvSeriesReviewUseCase { - operator fun invoke(seriesId: Int): Flow> + operator fun invoke(seriesId: Int): Flow> } class GetTvSeriesReviewInteractor @Inject constructor(private val repository: MoviesRepository): TvSeriesReviewUseCase { - override fun invoke(seriesId: Int): Flow> = repository.getTvSeriesReviewPagingFlow(seriesId).map { + override fun invoke(seriesId: Int): Flow> = repository.getTvSeriesReviewPagingFlow(seriesId).map { it.map { tvSeries -> tvSeries.toDomain() } diff --git a/app/src/main/java/com/application/moviesapp/ui/detail/CommentsScreen.kt b/app/src/main/java/com/application/moviesapp/ui/detail/CommentsScreen.kt index 5679221..05ab9f0 100644 --- a/app/src/main/java/com/application/moviesapp/ui/detail/CommentsScreen.kt +++ b/app/src/main/java/com/application/moviesapp/ui/detail/CommentsScreen.kt @@ -1,7 +1,6 @@ package com.application.moviesapp.ui.detail import android.content.res.Configuration -import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -11,32 +10,24 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.requiredHeight import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.grid.GridCells -import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.FloatingActionButton import androidx.compose.material.FloatingActionButtonDefaults -import androidx.compose.material.FloatingActionButtonElevation import androidx.compose.material.TextButton import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Comment import androidx.compose.material.icons.rounded.EmojiEmotions import androidx.compose.material.icons.rounded.Favorite -import androidx.compose.material.icons.rounded.Search import androidx.compose.material.icons.rounded.Send -import androidx.compose.material3.ButtonColors -import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card -import androidx.compose.material3.ElevatedButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -49,7 +40,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalFocusManager @@ -67,18 +57,16 @@ import coil.compose.AsyncImage import coil.request.ImageRequest import com.application.moviesapp.R import com.application.moviesapp.domain.model.Comment -import com.application.moviesapp.domain.model.CommentRepository -import com.application.moviesapp.domain.model.MovieReview +import com.application.moviesapp.domain.model.UserReview import com.application.moviesapp.ui.theme.MoviesAppTheme import com.application.moviesapp.ui.utility.toImageUrl -import com.application.moviesapp.ui.utility.toOneDecimal import kotlinx.coroutines.flow.flowOf @Composable fun CommentsScreen( modifier: Modifier = Modifier, paddingValues: PaddingValues = PaddingValues(), - movieReviewFlow: LazyPagingItems = flowOf(PagingData.empty()).collectAsLazyPagingItems(), + userReviewFlow: LazyPagingItems = flowOf(PagingData.empty()).collectAsLazyPagingItems(), ) { val focusRequest = remember { FocusRequester() } @@ -97,8 +85,8 @@ fun CommentsScreen( contentPadding = PaddingValues(horizontal = 16.dp), ) { - items(movieReviewFlow.itemCount) { index -> - CommentsPeopleCompose(review = movieReviewFlow[index] ?: return@items) + items(userReviewFlow.itemCount) { index -> + CommentsPeopleCompose(review = userReviewFlow[index] ?: return@items) } } @@ -136,7 +124,7 @@ fun CommentsScreen( } @Composable -fun CommentsPeopleCompose(modifier: Modifier = Modifier, comment: Comment = Comment(), review: MovieReview = MovieReview(null, null, null, null, null, null, null)) { +fun CommentsPeopleCompose(modifier: Modifier = Modifier, comment: Comment = Comment(), review: UserReview = UserReview(null, null, null, null, null, null, null)) { Column( modifier = modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(16.dp) diff --git a/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreen.kt b/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreen.kt index 6f19ad3..109e711 100755 --- a/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreen.kt +++ b/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreen.kt @@ -2,7 +2,6 @@ package com.application.moviesapp.ui.detail import android.app.Activity import android.content.res.Configuration.UI_MODE_NIGHT_YES -import android.widget.Toast import androidx.compose.foundation.clickable import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.interaction.MutableInteractionSource @@ -18,7 +17,6 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.requiredHeight import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.lazy.LazyColumn @@ -34,19 +32,14 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.LocalContentAlpha import androidx.compose.material.TextButton import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ExpandMore import androidx.compose.material.icons.outlined.FileDownload import androidx.compose.material.icons.rounded.ArrowForwardIos import androidx.compose.material.icons.rounded.Bookmark import androidx.compose.material.icons.rounded.BookmarkBorder -import androidx.compose.material.icons.rounded.Comment import androidx.compose.material.icons.rounded.ExpandMore -import androidx.compose.material.icons.rounded.Favorite import androidx.compose.material.icons.rounded.PlayCircle -import androidx.compose.material.icons.rounded.Settings import androidx.compose.material.icons.rounded.Share import androidx.compose.material.icons.rounded.StarHalf -import androidx.compose.material3.AssistChip import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults @@ -77,7 +70,6 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource @@ -98,18 +90,14 @@ import coil.request.ImageRequest import com.application.moviesapp.R import com.application.moviesapp.data.common.Resource import com.application.moviesapp.data.local.entity.MovieDownloadEntity -import com.application.moviesapp.domain.model.Comment -import com.application.moviesapp.domain.model.CommentRepository import com.application.moviesapp.domain.model.MovieNowPlaying -import com.application.moviesapp.domain.model.MovieReview +import com.application.moviesapp.domain.model.UserReview import com.application.moviesapp.domain.model.MovieState import com.application.moviesapp.domain.model.MovieTrailerWithYoutube import com.application.moviesapp.domain.model.MoviesDetail -import com.application.moviesapp.domain.model.MoviesDiscover import com.application.moviesapp.domain.model.Stream import com.application.moviesapp.domain.model.TvSeriesDetail import com.application.moviesapp.domain.model.TvSeriesEpisodes -import com.application.moviesapp.domain.model.TvSeriesReview import com.application.moviesapp.domain.model.TvSeriesTrailerWithYoutube import com.application.moviesapp.ui.play.PlayActivity import com.application.moviesapp.ui.play.Screen @@ -134,8 +122,8 @@ fun DetailScreen(modifier: Modifier = Modifier, moviesTrailerUiState: Resource> = Resource.Loading, tvSeriesTrailerUiState: Resource> = Resource.Loading, moviesFlow: LazyPagingItems, - movieReviewFlow: LazyPagingItems, - tvSeriesReviewFlow: LazyPagingItems, + moviesReviewFlow: LazyPagingItems, + tvSeriesReviewFlow: LazyPagingItems, onBookmarkClicked: (String, Int, Boolean) -> Unit = { _, _, _ -> }, snackbarHostState: SnackbarHostState = SnackbarHostState(), onBookmark: (Int) -> Unit = { _ -> }, @@ -464,7 +452,7 @@ fun DetailScreen(modifier: Modifier = Modifier, } } 2 -> { - CommentsCompose(onCommentsClick = onCommentsClick, movieReviewFlow = movieReviewFlow) + CommentsCompose(onCommentsClick = onCommentsClick, userReviewFlow = moviesReviewFlow) } } } @@ -854,7 +842,7 @@ fun DetailScreen(modifier: Modifier = Modifier, } } 2 -> { - CommentsCompose(onCommentsClick = onCommentsClick, movieReviewFlow = movieReviewFlow) + CommentsCompose(onCommentsClick = onCommentsClick, userReviewFlow = tvSeriesReviewFlow) } } } @@ -1031,7 +1019,7 @@ private fun TvSeriesTrailerCard(modifier: Modifier = Modifier, @Composable fun CommentsCompose(modifier: Modifier = Modifier, onCommentsClick: (Int) -> Unit = { _ -> }, - movieReviewFlow: LazyPagingItems = flowOf(PagingData.empty()).collectAsLazyPagingItems()) { + userReviewFlow: LazyPagingItems = flowOf(PagingData.empty()).collectAsLazyPagingItems()) { Column(modifier = modifier @@ -1042,7 +1030,7 @@ fun CommentsCompose(modifier: Modifier = Modifier, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween) { - Text(text = "${movieReviewFlow.itemCount} Comments", + Text(text = "${userReviewFlow.itemCount} Comments", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold) @@ -1061,50 +1049,8 @@ fun CommentsCompose(modifier: Modifier = Modifier, contentPadding = PaddingValues(horizontal = 16.dp), ) { - items(movieReviewFlow.itemCount) { index -> - CommentsPeopleCompose(review = movieReviewFlow[index] ?: return@items) - } - } - } -} - - -@Preview -@Composable -fun CommentsTvSeriesCompose(modifier: Modifier = Modifier, - onCommentsClick: (Int) -> Unit = { _ -> }, - tvSeriesReviewFlow: LazyPagingItems = flowOf(PagingData.empty()).collectAsLazyPagingItems()) { - - - Column(modifier = modifier - .fillMaxWidth() - .padding(horizontal = 16.dp), - verticalArrangement = Arrangement.spacedBy(16.dp)) { - Row(modifier = modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween) { - - Text(text = "${tvSeriesReviewFlow.itemCount} Comments", - style = MaterialTheme.typography.titleMedium, - fontWeight = FontWeight.SemiBold) - - TextButton(onClick = { onCommentsClick(0) }) { - Text(text = "See all", - color = MaterialTheme.colorScheme.primary, - style = MaterialTheme.typography.titleSmall, - fontWeight = FontWeight.SemiBold) - } - } - - LazyColumn( - modifier = modifier - .fillMaxSize(), - verticalArrangement = Arrangement.spacedBy(8.dp), - contentPadding = PaddingValues(horizontal = 16.dp), - ) { - - items(tvSeriesReviewFlow.itemCount) { index -> -// CommentsPeopleCompose(review = tvSeriesReviewFlow[index] ?: return@items) + items(userReviewFlow.itemCount) { index -> + CommentsPeopleCompose(review = userReviewFlow[index] ?: return@items) } } } diff --git a/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreenApp.kt b/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreenApp.kt index ebabe1c..c0d748c 100755 --- a/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreenApp.kt +++ b/app/src/main/java/com/application/moviesapp/ui/detail/DetailScreenApp.kt @@ -53,16 +53,14 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController -import androidx.paging.PagingData import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import com.application.moviesapp.R import com.application.moviesapp.data.common.Resource -import com.application.moviesapp.domain.model.MovieReview +import com.application.moviesapp.domain.model.UserReview import com.application.moviesapp.domain.model.TvSeriesDetail import com.application.moviesapp.ui.viewmodel.DetailsViewModel import com.application.moviesapp.ui.viewmodel.HomeViewModel -import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.launch @Composable @@ -108,7 +106,16 @@ fun DetailScreenApp(modifier: Modifier = Modifier, var selectedImage by remember { mutableStateOf(Pair?>("", emptyList())) } Scaffold( - topBar = { DetailTopAppbar(navController = navController, movieReviewFlow = movieReviewFlowState) }, + topBar = { DetailTopAppbar( + navController = navController, + userReviewFlow = when ((context as Activity).intent.getStringExtra(DetailActivity.TYPE)) { + IS_TYPE.Movie.name -> { + movieReviewFlowState + } + else -> { + tvSeriesReviewFlowState + } + }) }, snackbarHost = { SnackbarHost(snackbarHostState) { androidx.compose.material3.Snackbar( modifier = modifier.padding(8.dp), @@ -129,7 +136,7 @@ fun DetailScreenApp(modifier: Modifier = Modifier, moviesTrailerUiState = movieTrailerUiState, tvSeriesTrailerUiState = tvSeriesTrailerUiState, moviesFlow = moviesFlow, - movieReviewFlow = movieReviewFlowState, + moviesReviewFlow = movieReviewFlowState, tvSeriesReviewFlow = tvSeriesReviewFlowState, onBookmark = { viewModel.getMovieState(it) @@ -175,11 +182,22 @@ fun DetailScreenApp(modifier: Modifier = Modifier, } composable(route = DetailScreen.Comments.name) { - CommentsScreen( - modifier = modifier, - paddingValues = paddingValues, - movieReviewFlow = movieReviewFlowState - ) + when ((context as Activity).intent.getStringExtra(DetailActivity.TYPE)) { + IS_TYPE.Movie.name -> { + CommentsScreen( + modifier = modifier, + paddingValues = paddingValues, + userReviewFlow = movieReviewFlowState + ) + } + IS_TYPE.TvSeries.name -> { + CommentsScreen( + modifier = modifier, + paddingValues = paddingValues, + userReviewFlow = tvSeriesReviewFlowState + ) + } + } } } } @@ -191,7 +209,9 @@ enum class DetailScreen { @OptIn(ExperimentalMaterial3Api::class) @Composable -private fun DetailTopAppbar(modifier: Modifier = Modifier, navController: NavHostController, movieReviewFlow: LazyPagingItems) { +private fun DetailTopAppbar(modifier: Modifier = Modifier, + navController: NavHostController, + userReviewFlow: LazyPagingItems) { val context = LocalContext.current @@ -237,7 +257,7 @@ private fun DetailTopAppbar(modifier: Modifier = Modifier, navController: NavHos DetailScreen.Comments.name -> { TopAppBar( title = { - Text(text = "${movieReviewFlow.itemCount} Comments", fontWeight = FontWeight.SemiBold) + Text(text = "${userReviewFlow.itemCount} Comments", fontWeight = FontWeight.SemiBold) }, navigationIcon = { IconButton(onClick = { navController.navigateUp() }) {