diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..f95ad5f --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/api/cinema/CinemaRemoteMediator.kt b/app/src/main/java/com/example/myapplication/api/cinema/CinemaRemoteMediator.kt index 1fe6059..aaf45dd 100644 --- a/app/src/main/java/com/example/myapplication/api/cinema/CinemaRemoteMediator.kt +++ b/app/src/main/java/com/example/myapplication/api/cinema/CinemaRemoteMediator.kt @@ -55,9 +55,6 @@ class CinemaRemoteMediator( try { val cinemas = service.getCinemas(page, state.config.pageSize).map { it.toCinema() } - val sessionsFromCinemas = cinemas.flatMap { cinema -> - service.getCinemaWithSessions(cinema.uid).toSessions() - } val endOfPaginationReached = cinemas.isEmpty() database.withTransaction { if (loadType == LoadType.REFRESH) { @@ -77,7 +74,6 @@ class CinemaRemoteMediator( } dbRemoteKeyRepository.createRemoteKeys(keys) dbCinemaRepository.insertCinemas(cinemas) - dbSessionRepository.insertSessions(sessionsFromCinemas) } return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) } catch (exception: IOException) { diff --git a/app/src/main/java/com/example/myapplication/api/cinema/RestCinemaRepository.kt b/app/src/main/java/com/example/myapplication/api/cinema/RestCinemaRepository.kt index 813bf62..91178f1 100644 --- a/app/src/main/java/com/example/myapplication/api/cinema/RestCinemaRepository.kt +++ b/app/src/main/java/com/example/myapplication/api/cinema/RestCinemaRepository.kt @@ -5,11 +5,13 @@ import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData import com.example.myapplication.api.MyServerService +import com.example.myapplication.api.session.toSessionFromCinema import com.example.myapplication.database.AppContainer import com.example.myapplication.database.AppDatabase import com.example.myapplication.database.entities.model.Cinema import com.example.myapplication.database.entities.model.CinemaWithSessions import com.example.myapplication.database.entities.model.SessionFromCinema +import com.example.myapplication.database.entities.model.toSession import com.example.myapplication.database.entities.repository.CinemaRepository import com.example.myapplication.database.entities.repository.OfflineCinemaRepository import com.example.myapplication.database.entities.repository.OfflineSessionRepository @@ -65,6 +67,9 @@ class RestCinemaRepository( uid ) } + dbSessionRepository.insertSessions(cinemaWithSessions.sessions.map { + it.toSessionFromCinema().toSession() + }) return CinemaWithSessions(cinemaWithSessions.toCinema(), sessions) }