-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
44 changed files
with
994 additions
and
103 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
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
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
14 changes: 0 additions & 14 deletions
14
...ndar/data-public/main/ru/pixnews/feature/calendar/data/domain/upcoming/UpcomingRelease.kt
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
feature/calendar/data-public/main/ru/pixnews/feature/calendar/data/model/GameModeIgdbDto.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,15 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.model | ||
|
||
import kotlinx.datetime.Instant | ||
import ru.pixnews.domain.model.game.GameMode | ||
|
||
public data class GameModeIgdbDto( | ||
val mode: GameMode, | ||
val igdbSlug: String, | ||
val updatedAt: Instant, | ||
) |
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
75 changes: 75 additions & 0 deletions
75
...e/calendar/data/src/main/kotlin/ru/pixnews/feature/calendar/data/DefaultRemoteMediator.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,75 @@ | ||
/* | ||
* Copyright (c) 2023, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data | ||
|
||
import androidx.paging.ExperimentalPagingApi | ||
import androidx.paging.LoadType | ||
import androidx.paging.LoadType.APPEND | ||
import androidx.paging.LoadType.PREPEND | ||
import androidx.paging.LoadType.REFRESH | ||
import androidx.paging.PagingState | ||
import androidx.paging.RemoteMediator | ||
import androidx.paging.RemoteMediator.InitializeAction.LAUNCH_INITIAL_REFRESH | ||
import androidx.paging.RemoteMediator.InitializeAction.SKIP_INITIAL_REFRESH | ||
import co.touchlab.kermit.Logger | ||
import kotlinx.datetime.Instant | ||
import ru.pixnews.domain.model.game.Game | ||
import ru.pixnews.domain.model.game.GameField | ||
import ru.pixnews.feature.calendar.data.repository.upcoming.IgdbPagingSourceKey | ||
import ru.pixnews.feature.calendar.data.sync.SyncService | ||
|
||
@OptIn(ExperimentalPagingApi::class) | ||
internal class DefaultRemoteMediator( | ||
private val startDate: Instant, | ||
private val requiredFields: Set<GameField>, | ||
private val syncService: SyncService, | ||
logger: Logger = Logger, | ||
) : RemoteMediator<IgdbPagingSourceKey, Game>() { | ||
private val logger = logger.withTag("DefaultRemoteMediator") | ||
|
||
override suspend fun initialize(): InitializeAction { | ||
return if (syncService.isDataStale()) { | ||
LAUNCH_INITIAL_REFRESH | ||
} else { | ||
SKIP_INITIAL_REFRESH | ||
} | ||
} | ||
|
||
// TODO: tests | ||
override suspend fun load( | ||
loadType: LoadType, | ||
state: PagingState<IgdbPagingSourceKey, Game>, | ||
): MediatorResult { | ||
logger.d { "load() with loadType: $loadType" } | ||
if (loadType == PREPEND) { | ||
logger.d { "PREPEND: nothing to prepend (we refresh always from first page)" } | ||
return MediatorResult.Success(endOfPaginationReached = true) | ||
} | ||
if (loadType == APPEND && state.lastItemOrNull() == null) { | ||
logger.d { "APPEND: Last item is null. No more items after initial REFRESH, nothing to load" } | ||
return MediatorResult.Success(endOfPaginationReached = true) | ||
} | ||
|
||
val loadKey = if (loadType == APPEND) { | ||
state.lastItemOrNull()!!.id | ||
} else { | ||
null | ||
} | ||
return try { | ||
syncService.syncGameModes(false, true) | ||
|
||
val result = syncService.syncGames( | ||
fullRefresh = loadType == REFRESH, | ||
startDate = startDate, | ||
minimumRequiredFields = requiredFields, | ||
earlierThanGameId = loadKey, | ||
) | ||
MediatorResult.Success(endOfPaginationReached = !result.hasMorePagesToLoad) | ||
} catch (@Suppress("TooGenericExceptionCaught") e: Exception) { | ||
MediatorResult.Error(e) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...lin/ru/pixnews/feature/calendar/data/repository/status/DefaultIgdbSyncStatusRepository.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,35 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.repository.status | ||
|
||
import com.squareup.anvil.annotations.ContributesBinding | ||
import dagger.Reusable | ||
import kotlinx.datetime.Instant | ||
import ru.pixnews.foundation.database.PixnewsDatabase | ||
import ru.pixnews.foundation.database.dao.IgdbSyncStatusDao | ||
import ru.pixnews.foundation.database.entity.sync.IgdbSyncStatusEntity | ||
import ru.pixnews.foundation.di.base.scopes.AppScope | ||
import javax.inject.Inject | ||
|
||
@ContributesBinding(AppScope::class, boundType = IgdbSyncStatusRepository::class) | ||
@Reusable | ||
public class DefaultIgdbSyncStatusRepository( | ||
private val dao: IgdbSyncStatusDao, | ||
) : IgdbSyncStatusRepository { | ||
@Inject | ||
public constructor( | ||
database: PixnewsDatabase, | ||
) : this(dao = database.igdbSyncStatusDao()) | ||
|
||
override suspend fun getInstantKey(key: String): Instant { | ||
val epoch = dao.get(key)?.toLongOrNull() ?: 0 | ||
return Instant.fromEpochSeconds(epoch) | ||
} | ||
|
||
override suspend fun setInstantKey(key: String, value: Instant) { | ||
dao.set(IgdbSyncStatusEntity(key, value.epochSeconds.toString())) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ain/kotlin/ru/pixnews/feature/calendar/data/repository/status/IgdbSyncStatusRepository.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,16 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.repository.status | ||
|
||
import kotlinx.datetime.Instant | ||
|
||
public const val IGDB_GAME_MODE_MAX_UPDATED_AT_KEY: String = "igdb_game_mode_max_updated_at" | ||
public const val IGDB_GAME_MODE_LAST_SYNC_KEY: String = "igdb_game_mode_last_sync" | ||
|
||
public interface IgdbSyncStatusRepository { | ||
public suspend fun getInstantKey(key: String): Instant | ||
public suspend fun setInstantKey(key: String, value: Instant) | ||
} |
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
11 changes: 11 additions & 0 deletions
11
...c/main/kotlin/ru/pixnews/feature/calendar/data/repository/upcoming/IgdbPagingSourceKey.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,11 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.repository.upcoming | ||
|
||
@JvmInline | ||
public value class IgdbPagingSourceKey( | ||
public val offset: Int, | ||
) |
16 changes: 16 additions & 0 deletions
16
.../kotlin/ru/pixnews/feature/calendar/data/repository/upcoming/UpcomingReleaseRepository.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,16 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.repository.upcoming | ||
|
||
import kotlinx.datetime.Instant | ||
import ru.pixnews.domain.model.game.GameField | ||
|
||
public interface UpcomingReleaseRepository { | ||
public fun createUpcomingReleasesPagingSource( | ||
startDate: Instant, | ||
requiredFields: Set<GameField>, | ||
): UpcomingReleasesPagingSource | ||
} |
11 changes: 11 additions & 0 deletions
11
...tlin/ru/pixnews/feature/calendar/data/repository/upcoming/UpcomingReleasesPagingSource.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,11 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.repository.upcoming | ||
|
||
import androidx.paging.PagingSource | ||
import ru.pixnews.domain.model.game.Game | ||
|
||
public abstract class UpcomingReleasesPagingSource : PagingSource<IgdbPagingSourceKey, Game>() |
Oops, something went wrong.