-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from sheikh-20/develop
Develop
- Loading branch information
Showing
13 changed files
with
457 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/application/moviesapp/data/mappers/TvSeriesFavouriteMappers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.application.moviesapp.data.mappers | ||
|
||
import com.application.moviesapp.data.remote.TvSeriesFavouriteDto | ||
import com.application.moviesapp.domain.model.TvSeriesFavourite | ||
|
||
fun TvSeriesFavouriteDto.Result.toDomain(): TvSeriesFavourite { | ||
return TvSeriesFavourite( | ||
adult, backdropPath, firstAirDate, genreIds, id, name, originCountry, originalLanguage, originalName, overview, popularity, posterPath, voteAverage, voteCount | ||
) | ||
} |
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/application/moviesapp/data/remote/TvSeriesFavouriteDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.application.moviesapp.data.remote | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.Serializer | ||
|
||
|
||
@Serializable | ||
data class TvSeriesFavouriteDto( | ||
@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("adult") | ||
val adult: Boolean?, | ||
|
||
@SerialName("backdrop_path") | ||
val backdropPath: String?, | ||
|
||
@SerialName("first_air_date") | ||
val firstAirDate: String?, | ||
|
||
@SerialName("genre_ids") | ||
val genreIds: List<Int?>?, | ||
|
||
@SerialName("id") | ||
val id: Int?, | ||
|
||
@SerialName("name") | ||
val name: String?, | ||
|
||
@SerialName("origin_country") | ||
val originCountry: List<String?>?, | ||
|
||
@SerialName("original_language") | ||
val originalLanguage: String?, | ||
|
||
@SerialName("original_name") | ||
val originalName: String?, | ||
|
||
@SerialName("overview") | ||
val overview: String?, | ||
|
||
@SerialName("popularity") | ||
val popularity: Double?, | ||
|
||
@SerialName("poster_path") | ||
val posterPath: String?, | ||
|
||
@SerialName("vote_average") | ||
val voteAverage: Double?, | ||
|
||
@SerialName("vote_count") | ||
val voteCount: Int? | ||
) | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/application/moviesapp/data/remote/TvSeriesFavouritePagingSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.application.moviesapp.data.remote | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.application.moviesapp.data.api.MoviesApi | ||
|
||
class TvSeriesFavouritePagingSource(private val moviesApi: MoviesApi): PagingSource<Int, TvSeriesFavouriteDto.Result>() { | ||
override fun getRefreshKey(state: PagingState<Int, TvSeriesFavouriteDto.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, TvSeriesFavouriteDto.Result> { | ||
|
||
return try { | ||
val page = params.key ?: 1 | ||
|
||
val apiResult = moviesApi.getTvSeriesFavourite(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 ?: TvSeriesFavouriteDto.Result(null, null, null, null, null, null, null, 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) { | ||
LoadResult.Error(throwable) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/application/moviesapp/domain/model/TvSeriesFavourite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.application.moviesapp.domain.model | ||
|
||
|
||
data class TvSeriesFavourite( | ||
val adult: Boolean?, | ||
val backdropPath: String?, | ||
val firstAirDate: String?, | ||
val genreIds: List<Int?>?, | ||
val id: Int?, | ||
val name: String?, | ||
val originCountry: List<String?>?, | ||
val originalLanguage: String?, | ||
val originalName: String?, | ||
val overview: String?, | ||
val popularity: Double?, | ||
val posterPath: String?, | ||
val voteAverage: Double?, | ||
val voteCount: Int? | ||
) |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesFavouriteUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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.remote.TvSeriesFavouriteDto | ||
import com.application.moviesapp.data.repository.MoviesRepository | ||
import com.application.moviesapp.domain.model.MovieFavourite | ||
import com.application.moviesapp.domain.model.TvSeriesFavourite | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
interface TvSeriesFavouriteUseCase { | ||
operator fun invoke(): Flow<PagingData<TvSeriesFavourite>> | ||
} | ||
|
||
class GetTvSeriesFavouriteInteractor @Inject constructor(private val repository: MoviesRepository): TvSeriesFavouriteUseCase { | ||
|
||
private companion object { | ||
const val TAG = "GetTvSeriesFavouriteInteractor" | ||
} | ||
|
||
override fun invoke(): Flow<PagingData<TvSeriesFavourite>> = repository.getFavouriteTvSeriesPagingFlow().map { | ||
it.map { tvSeries -> tvSeries.toDomain() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.