немного изменения медиатора

This commit is contained in:
dasha 2023-12-24 17:54:20 +04:00
parent 4bf7ebb6bf
commit c8f8b59672
3 changed files with 22 additions and 4 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="KFRSEQ6DTWWWQOE6" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-12-24T13:45:26.698560500Z" />
</component>
</project>

View File

@ -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) {

View File

@ -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)
}