Skip to content

Commit

Permalink
Merge pull request #86 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jun 23, 2024
2 parents e6715b6 + 19caea3 commit 6e2f6fd
Show file tree
Hide file tree
Showing 18 changed files with 612 additions and 66 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 = 20
versionName = "1.0.19"
versionCode = 21
versionName = "1.0.20"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +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.MovieSearchDto
import com.application.moviesapp.data.api.response.MovieSimpleResponse
import com.application.moviesapp.data.api.response.MovieStateDto
Expand All @@ -22,6 +23,7 @@ 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 @@ -128,4 +130,9 @@ interface MoviesApi {
@GET("/3/search/tv")
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>

@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>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.application.moviesapp.data.api.response

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

@Serializable
data class MovieReviewDto(

@SerialName("id")
val id: Int?,

@SerialName("page")
val page: Int?,

@SerialName("results")
val results: List<Result?>?,

@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?
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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<Result?>?,

@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?
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.application.moviesapp.data.mappers

import com.application.moviesapp.data.api.response.MovieReviewDto
import com.application.moviesapp.domain.model.MovieReview

fun MovieReviewDto.Result.toDomain(): MovieReview {
return MovieReview(
author = this.author,
content = this.content,
createdAt = this.createdAt,
id = this.id,
updatedAt = this.updatedAt,
url = this.url,
authorDetails = MovieReview.AuthorDetails(
avatarPath = this.authorDetails?.avatarPath,
name = this.authorDetails?.name,
username = this.authorDetails?.username,
rating = this.authorDetails?.rating
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 timber.log.Timber

class MovieReviewPagingSource(private val moviesApi: MoviesApi, private val movieId: Int): PagingSource<Int, MovieReviewDto.Result>() {

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

override fun getRefreshKey(state: PagingState<Int, MovieReviewDto.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> {

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

return try {
val page = params.key ?: 1

val apiResult = moviesApi.getMovieReview(movieId = movieId, page = page)
val movies = if (apiResult.isSuccessful) {
apiResult.body()
} else if (apiResult.code() == 400 || apiResult.code() == 401 || apiResult.code() == 403) {
throw Throwable()
} else {
throw Throwable()
}

LoadResult.Page(
data = movies?.results?.map { it ?: MovieReviewDto.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),
)
} catch (throwable: Throwable) {
Timber.tag(TAG).e(throwable)
LoadResult.Error(throwable)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 timber.log.Timber

class TvSeriesReviewPagingSource(private val moviesApi: MoviesApi, private val seriesId: Int): PagingSource<Int, TvSeriesReviewDto.Result>() {

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

override fun getRefreshKey(state: PagingState<Int, TvSeriesReviewDto.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> {

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

return try {
val page = params.key ?: 1

val apiResult = moviesApi.getTvSeriesReview(seriesId = seriesId, page = page)
val movies = if (apiResult.isSuccessful) {
apiResult.body()
} else if (apiResult.code() == 400 || apiResult.code() == 401 || apiResult.code() == 403) {
throw Throwable()
} else {
throw Throwable()
}

LoadResult.Page(
data = movies?.results?.map { it ?: TvSeriesReviewDto.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),
)
} catch (throwable: Throwable) {
Timber.tag(TAG).e(throwable)
LoadResult.Error(throwable)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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.MovieSearchDto
import com.application.moviesapp.data.api.response.MovieStateDto
import com.application.moviesapp.data.api.response.MovieTopRatedResponse
Expand All @@ -26,13 +27,15 @@ 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
import com.application.moviesapp.data.local.entity.MovieDownloadEntity
import com.application.moviesapp.data.remote.MovieFavouritePagingSource
import com.application.moviesapp.data.remote.MovieNewReleasesDto
import com.application.moviesapp.data.remote.MovieNowPlayingPagingSource
import com.application.moviesapp.data.remote.MovieReviewPagingSource
import com.application.moviesapp.data.remote.MovieSearchPagingSource
import com.application.moviesapp.data.remote.MovieUpcomingDto
import com.application.moviesapp.data.remote.MoviesDiscoverDto
Expand All @@ -41,7 +44,9 @@ import com.application.moviesapp.data.remote.TvSeriesDiscoverPagingSource
import com.application.moviesapp.data.remote.TvSeriesFavouriteDto
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 @@ -119,6 +124,10 @@ interface MoviesRepository {
suspend fun getTvSeriesNowPlayingList(): Response<TvSeriesNowPlayingDto>

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

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

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

@OptIn(ExperimentalPagingApi::class)
Expand Down Expand Up @@ -238,4 +247,17 @@ 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(
config = PagingConfig(pageSize = 20),
pagingSourceFactory = {
MovieReviewPagingSource(movies, movieId)
}
).flow

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

0 comments on commit 6e2f6fd

Please sign in to comment.