Skip to content

Commit

Permalink
Merge pull request #88 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jun 24, 2024
2 parents 6e2f6fd + 516762f commit 563b5e0
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 271 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<TvSeriesSearchDto>

@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<MovieReviewDto>
suspend fun getMovieReview(@Path("movie_id") movieId: Int, @Query("language") language: String = "en-US", @Query("page") page: Int = 1): Response<UserReviewDto>

@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<TvSeriesReviewDto>
suspend fun getTvSeriesReview(@Path("series_id") seriesId: Int, @Query("language") language: String = "en-US", @Query("page") page: Int = 1): Response<UserReviewDto>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MovieReviewDto(
data class UserReviewDto(

@SerialName("id")
val id: Int?,
Expand Down
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, MovieReviewDto.Result>() {
class MovieReviewPagingSource(private val moviesApi: MoviesApi, private val movieId: Int): PagingSource<Int, UserReviewDto.Result>() {

private companion object {
const val TAG = "MovieReviewPagingSource"
}

override fun getRefreshKey(state: PagingState<Int, MovieReviewDto.Result>): Int? {
override fun getRefreshKey(state: PagingState<Int, UserReviewDto.Result>): Int? {
return state.anchorPosition?.let { anchorPosition ->
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1)
}
}

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MovieReviewDto.Result> {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, UserReviewDto.Result> {

Timber.tag(TAG).d("%s Called!", TAG)

Expand All @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, TvSeriesReviewDto.Result>() {
class TvSeriesReviewPagingSource(private val moviesApi: MoviesApi, private val seriesId: Int): PagingSource<Int, UserReviewDto.Result>() {

private companion object {
const val TAG = "TvSeriesReviewPagingSource"
}

override fun getRefreshKey(state: PagingState<Int, TvSeriesReviewDto.Result>): Int? {
override fun getRefreshKey(state: PagingState<Int, UserReviewDto.Result>): Int? {
return state.anchorPosition?.let { anchorPosition ->
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1)
}
}

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, TvSeriesReviewDto.Result> {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, UserReviewDto.Result> {

Timber.tag(TAG).d("%s Called!", TAG)

Expand All @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -125,9 +123,9 @@ interface MoviesRepository {

suspend fun getTvSeriesEpisodes(seriesId: Int, seasonNumber: Int = 1): Response<TvSeriesEpisodesDto>

fun getMovieReviewPagingFlow(movieId: Int): Flow<PagingData<MovieReviewDto.Result>>
fun getMovieReviewPagingFlow(movieId: Int): Flow<PagingData<UserReviewDto.Result>>

fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow<PagingData<TvSeriesReviewDto.Result>>
fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow<PagingData<UserReviewDto.Result>>
}

@OptIn(ExperimentalPagingApi::class)
Expand Down Expand Up @@ -247,14 +245,14 @@ class MoviesRepositoryImpl @Inject constructor(private val movies: MoviesApi,
override suspend fun getTvSeriesNowPlayingList(): Response<TvSeriesNowPlayingDto> = movies.getNowPlayingSeriesList()

override suspend fun getTvSeriesEpisodes(seriesId: Int, seasonNumber: Int): Response<TvSeriesEpisodesDto> = movies.getTvSeriesEpisodes(seriesId = seriesId, seasonNumber = seasonNumber)
override fun getMovieReviewPagingFlow(movieId: Int): Flow<PagingData<MovieReviewDto.Result>> = Pager(
override fun getMovieReviewPagingFlow(movieId: Int): Flow<PagingData<UserReviewDto.Result>> = Pager(
config = PagingConfig(pageSize = 20),
pagingSourceFactory = {
MovieReviewPagingSource(movies, movieId)
}
).flow

override fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow<PagingData<TvSeriesReviewDto.Result>> = Pager(
override fun getTvSeriesReviewPagingFlow(seriesId: Int): Flow<PagingData<UserReviewDto.Result>> = Pager(
config = PagingConfig(pageSize = 20),
pagingSourceFactory = {
TvSeriesReviewPagingSource(movies, seriesId)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PagingData<MovieReview>>
operator fun invoke(movieId: Int): Flow<PagingData<UserReview>>
}

class GetMovieReviewInteractor @Inject constructor(private val repository: MoviesRepository): MovieReviewUseCase {
override fun invoke(movieId: Int): Flow<PagingData<MovieReview>> = repository.getMovieReviewPagingFlow(movieId).map {
override fun invoke(movieId: Int): Flow<PagingData<UserReview>> = repository.getMovieReviewPagingFlow(movieId).map {
it.map { movie ->
movie.toDomain()
}
Expand Down
Loading

0 comments on commit 563b5e0

Please sign in to comment.