Skip to content

Commit

Permalink
Implement cached pagination for now playing movies, now playing tv sh…
Browse files Browse the repository at this point in the history
…ows, top rated tv shows.
  • Loading branch information
mutkuensert committed Sep 11, 2023
1 parent b34346a commit 807b6da
Show file tree
Hide file tree
Showing 53 changed files with 762 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ import com.adesso.movee.data.local.database.dao.MovieGenreCrossRefDao
import com.adesso.movee.data.local.database.dao.MovieGenreDao
import com.adesso.movee.data.local.database.dao.NowPlayingMovieDao
import com.adesso.movee.data.local.database.dao.NowPlayingMovieIdPageDao
import com.adesso.movee.data.local.database.dao.NowPlayingTvShowIdDao
import com.adesso.movee.data.local.database.dao.NowPlayingTvShowDao
import com.adesso.movee.data.local.database.dao.NowPlayingTvShowIdPageDao
import com.adesso.movee.data.local.database.dao.PopularMovieDao
import com.adesso.movee.data.local.database.dao.PopularMovieIdPageDao
import com.adesso.movee.data.local.database.dao.TopRatedTvShowIdDao
import com.adesso.movee.data.local.database.dao.TvShowDao
import com.adesso.movee.data.local.database.dao.TopRatedTvShowDao
import com.adesso.movee.data.local.database.dao.TopRatedTvShowIdPageDao
import com.adesso.movee.data.local.database.dao.TvShowGenreCrossRefDao
import com.adesso.movee.data.local.database.dao.TvShowGenreDao
import com.adesso.movee.data.local.database.entity.MovieGenreCrossRefEntity
import com.adesso.movee.data.local.database.entity.MovieGenreEntity
import com.adesso.movee.data.local.database.entity.NowPlayingMovieEntity
import com.adesso.movee.data.local.database.entity.NowPlayingMovieIdPageEntity
import com.adesso.movee.data.local.database.entity.NowPlayingTvShowIdEntity
import com.adesso.movee.data.local.database.entity.NowPlayingTvShowEntity
import com.adesso.movee.data.local.database.entity.NowPlayingTvShowIdPageEntity
import com.adesso.movee.data.local.database.entity.PopularMovieEntity
import com.adesso.movee.data.local.database.entity.PopularMovieIdPageEntity
import com.adesso.movee.data.local.database.entity.TopRatedTvShowIdEntity
import com.adesso.movee.data.local.database.entity.TvShowEntity
import com.adesso.movee.data.local.database.entity.TopRatedTvShowEntity
import com.adesso.movee.data.local.database.entity.TopRatedTvShowIdPageEntity
import com.adesso.movee.data.local.database.entity.TvShowGenreCrossRefEntity
import com.adesso.movee.data.local.database.entity.TvShowGenreEntity
import com.adesso.movee.internal.util.typeconverter.DateTypeConverter
Expand All @@ -36,13 +38,14 @@ import com.adesso.movee.internal.util.typeconverter.GenreConverter
NowPlayingMovieIdPageEntity::class,
MovieGenreEntity::class,
MovieGenreCrossRefEntity::class,
TvShowEntity::class,
TopRatedTvShowIdEntity::class,
NowPlayingTvShowIdEntity::class,
NowPlayingTvShowEntity::class,
NowPlayingTvShowIdPageEntity::class,
TopRatedTvShowEntity::class,
TopRatedTvShowIdPageEntity::class,
TvShowGenreEntity::class,
TvShowGenreCrossRefEntity::class
],
version = 3
version = 4
)
@TypeConverters(
DateTypeConverter::class,
Expand All @@ -57,9 +60,10 @@ abstract class MainDatabase : RoomDatabase() {
abstract fun movieGenreDao(): MovieGenreDao
abstract fun movieGenreCrossRefDao(): MovieGenreCrossRefDao

abstract fun tvShowDao(): TvShowDao
abstract fun topRatedTvShowIdDao(): TopRatedTvShowIdDao
abstract fun nowPlayingTvShowIdDao(): NowPlayingTvShowIdDao
abstract fun topRatedTvShowDao(): TopRatedTvShowDao
abstract fun nowPlayingTvShowDao(): NowPlayingTvShowDao
abstract fun topRatedTvShowIdPageDao(): TopRatedTvShowIdPageDao
abstract fun nowPlayingTvShowIdPageDao(): NowPlayingTvShowIdPageDao
abstract fun tvShowGenreDao(): TvShowGenreDao
abstract fun tvShowGenreCrossRefDao(): TvShowGenreCrossRefDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ import com.adesso.movee.data.local.database.entity.NowPlayingMovieWithGenres
@Dao
abstract class NowPlayingMovieDao : BaseDao<NowPlayingMovieEntity> {

@Transaction
@Query("SELECT * FROM now_playing_movie WHERE id IN (:movieIds)")
abstract suspend fun getMoviesWithGenresByIds(movieIds: List<Long>):
List<NowPlayingMovieWithGenres>

@Transaction
@Query("SELECT * FROM now_playing_movie")
abstract fun getMoviesWithGenresPagingSource(): PagingSource<Int, NowPlayingMovieWithGenres>
abstract fun getPagingSource(): PagingSource<Int, NowPlayingMovieWithGenres>

@Transaction
@Query("DELETE FROM now_playing_movie")
abstract fun clearNowPlayingMoviesWithGenres()
abstract suspend fun clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.adesso.movee.data.local.database.entity.TABLE_NOW_PLAYING_MOVIE_ID_PA
@Dao
abstract class NowPlayingMovieIdPageDao : BaseDao<NowPlayingMovieIdPageEntity> {

@Query("SELECT id FROM $TABLE_NOW_PLAYING_MOVIE_ID_PAGE")
abstract suspend fun getIds(): List<Long>
@Query("SELECT page FROM $TABLE_NOW_PLAYING_MOVIE_ID_PAGE")
abstract suspend fun getPages(): List<Int>

@Query("DELETE FROM $TABLE_NOW_PLAYING_MOVIE_ID_PAGE")
abstract fun clearNowPlayingMovieIds()
abstract suspend fun clear()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.adesso.movee.data.local.database.dao

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import com.adesso.movee.data.local.database.entity.NowPlayingTvShowEntity
import com.adesso.movee.data.local.database.entity.NowPlayingTvShowWithGenres

@Dao
abstract class NowPlayingTvShowDao : BaseDao<NowPlayingTvShowEntity> {

@Transaction
@Query("SELECT * FROM now_playing_tv_show")
abstract fun getPagingSource(): PagingSource<Int, NowPlayingTvShowWithGenres>

@Transaction
@Query("DELETE FROM now_playing_tv_show")
abstract suspend fun clear()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.adesso.movee.data.local.database.dao

import androidx.room.Dao
import androidx.room.Query
import com.adesso.movee.data.local.database.entity.NowPlayingTvShowIdPageEntity
import com.adesso.movee.data.local.database.entity.TABLE_NOW_PLAYING_TV_SHOW_ID_PAGE

@Dao
abstract class NowPlayingTvShowIdPageDao : BaseDao<NowPlayingTvShowIdPageEntity> {

@Query("SELECT page FROM $TABLE_NOW_PLAYING_TV_SHOW_ID_PAGE")
abstract suspend fun getPages(): List<Int>

@Query("DELETE FROM $TABLE_NOW_PLAYING_TV_SHOW_ID_PAGE")
abstract suspend fun clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ import com.adesso.movee.data.local.database.entity.PopularMovieWithGenres
@Dao
abstract class PopularMovieDao : BaseDao<PopularMovieEntity> {

@Transaction
@Query("SELECT * FROM popular_movie WHERE id IN (:movieIds)")
abstract suspend fun getMoviesWithGenresByIds(movieIds: List<Long>):
List<PopularMovieWithGenres>

@Transaction
@Query("SELECT * FROM popular_movie")
abstract fun getMoviesWithGenresPagingSource(): PagingSource<Int, PopularMovieWithGenres>
abstract fun getPagingSource(): PagingSource<Int, PopularMovieWithGenres>

@Transaction
@Query("DELETE FROM popular_movie")
abstract fun clearPopularMoviesWithGenres()
abstract suspend fun clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import com.adesso.movee.data.local.database.entity.TABLE_POPULAR_MOVIE_ID_PAGE
@Dao
abstract class PopularMovieIdPageDao : BaseDao<PopularMovieIdPageEntity> {

@Query("SELECT id FROM $TABLE_POPULAR_MOVIE_ID_PAGE")
abstract suspend fun getIds(): List<Long>

@Query("SELECT page FROM $TABLE_POPULAR_MOVIE_ID_PAGE")
abstract suspend fun getPopularMoviePages(): List<Int>
abstract suspend fun getPages(): List<Int>

@Query("DELETE FROM $TABLE_POPULAR_MOVIE_ID_PAGE")
abstract fun clearPopularMovieIds()
abstract suspend fun clear()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.adesso.movee.data.local.database.dao

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import com.adesso.movee.data.local.database.entity.TopRatedTvShowEntity
import com.adesso.movee.data.local.database.entity.TopRatedTvShowWithGenres

@Dao
abstract class TopRatedTvShowDao : BaseDao<TopRatedTvShowEntity> {

@Transaction
@Query("SELECT * FROM top_rated_tv_show")
abstract fun getPagingSource(): PagingSource<Int, TopRatedTvShowWithGenres>

@Transaction
@Query("DELETE FROM top_rated_tv_show")
abstract suspend fun clear()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adesso.movee.data.local.database.dao

import androidx.room.Dao
import androidx.room.Query
import com.adesso.movee.data.local.database.entity.TABLE_TOP_RATED_TV_SHOW_ID_PAGE
import com.adesso.movee.data.local.database.entity.TopRatedTvShowIdPageEntity

@Dao
abstract class TopRatedTvShowIdPageDao : BaseDao<TopRatedTvShowIdPageEntity> {
@Query("SELECT page FROM $TABLE_TOP_RATED_TV_SHOW_ID_PAGE")
abstract suspend fun getPages(): List<Int>

@Query("DELETE FROM $TABLE_TOP_RATED_TV_SHOW_ID_PAGE")
abstract suspend fun clear()
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.adesso.movee.internal.util.Image
import com.adesso.movee.uimodel.MovieGenreUiModel
import com.adesso.movee.uimodel.MovieUiModel
import java.util.Date

@Entity(tableName = "now_playing_movie")
data class NowPlayingMovieEntity(
@ColumnInfo(name = "id") @PrimaryKey val id: Long,
@ColumnInfo(name = "id") val id: Long,
@ColumnInfo(name = "title") val title: String,
@ColumnInfo(name = "overview") val overview: String,
@ColumnInfo(name = "genres") val genreIds: List<Long>,
Expand All @@ -21,17 +19,6 @@ data class NowPlayingMovieEntity(
@ColumnInfo(name = "adult") val isAdult: Boolean,
@ColumnInfo(name = "release_date") val releaseDate: Date?
) {

fun toUiModel(genres: List<MovieGenreUiModel>) = MovieUiModel(
id = id,
title = title,
overview = overview,
genres = genres,
posterPath = posterPath,
backdropPath = backdropPath,
popularity = popularity,
average = average,
isAdult = isAdult,
releaseDate = releaseDate
)
@PrimaryKey(autoGenerate = true)
var uId: Int = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.adesso.movee.internal.util.Image
import com.adesso.movee.uimodel.TvShowGenreUiModel
import com.adesso.movee.uimodel.TvShowUiModel
import java.util.Date

@Entity(tableName = "tv_show")
data class TvShowEntity(
@ColumnInfo(name = "id") @PrimaryKey val id: Long,
@Entity(tableName = "now_playing_tv_show")
data class NowPlayingTvShowEntity(
@ColumnInfo(name = "id") val id: Long,
@ColumnInfo(name = "name") val title: String,
@ColumnInfo(name = "overview") val overview: String,
@ColumnInfo(name = "genre_ids") val genreIds: List<Long>,
Expand All @@ -20,15 +18,6 @@ data class TvShowEntity(
@ColumnInfo(name = "vote_average") val average: Double,
@ColumnInfo(name = "first_air_date") val releaseDate: Date?
) {
fun toUiModel(genres: List<TvShowGenreUiModel>) = TvShowUiModel(
id = id,
title = title,
overview = overview,
genres = genres,
posterPath = posterPath,
backdropPath = backdropPath,
popularity = popularity,
average = average,
releaseDate = releaseDate
)
@PrimaryKey(autoGenerate = true)
var uId: Int = 0
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.adesso.movee.data.local.database.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

const val TABLE_NOW_PLAYING_TV_SHOW_ID_PAGE = "now_playing_tv_show_id_page"

@Entity(tableName = TABLE_NOW_PLAYING_TV_SHOW_ID_PAGE)
class NowPlayingTvShowIdPageEntity(
@ColumnInfo(name = "id") val id: Long,
@ColumnInfo(name = "page") val page: Int
) {
@PrimaryKey(autoGenerate = true)
var uId: Int = 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.adesso.movee.data.local.database.entity

import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
import com.adesso.movee.internal.extension.convertTvShowGenres
import com.adesso.movee.uimodel.TvShowUiModel

data class NowPlayingTvShowWithGenres(
@Embedded val tvShow: NowPlayingTvShowEntity,
@Relation(
parentColumn = "id",
entityColumn = "genre_id",
associateBy = Junction(
value = TvShowGenreCrossRefEntity::class
)
)
val genres: List<TvShowGenreEntity>
) {
fun toUiModel() = TvShowUiModel(
id = tvShow.id,
title = tvShow.title,
overview = tvShow.overview,
genres = genres.convertTvShowGenres(),
posterPath = tvShow.posterPath,
backdropPath = tvShow.backdropPath,
popularity = tvShow.popularity,
average = tvShow.average,
releaseDate = tvShow.releaseDate
)
}
Loading

0 comments on commit 807b6da

Please sign in to comment.