-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement pagination on premium leaderboard (#306)
* Add new `premiumSince` order by to PremiumLeaderboard; * Store profiles returned by leaderboard endpoints in database; * Migrate `donatedBtc` to `donatedSats` in legends leaderboard; * Implement pagination on premium leaderboard; * Increase limit on legend leaderboard from 200 to 300;
- Loading branch information
Showing
15 changed files
with
165 additions
and
77 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
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
41 changes: 41 additions & 0 deletions
41
app/src/main/kotlin/net/primal/android/premium/api/paging/PremiumLeaderboardPagingSource.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,41 @@ | ||
package net.primal.android.premium.api.paging | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import net.primal.android.networking.sockets.errors.WssException | ||
import net.primal.android.premium.leaderboard.domain.OGLeaderboardEntry | ||
import net.primal.android.premium.repository.PremiumRepository | ||
|
||
class PremiumLeaderboardPagingSource( | ||
private val premiumRepository: PremiumRepository, | ||
private val pageSize: Int, | ||
) : PagingSource<Long, OGLeaderboardEntry>() { | ||
|
||
override fun getRefreshKey(state: PagingState<Long, OGLeaderboardEntry>): Long? { | ||
return state.anchorPosition?.let { position -> | ||
state.closestItemToPosition(position)?.premiumSince?.minus(1) | ||
?: state.closestPageToPosition(position)?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Long>): LoadResult<Long, OGLeaderboardEntry> { | ||
val currentUntil = params.key | ||
|
||
return try { | ||
val response = premiumRepository.fetchPremiumLeaderboard( | ||
until = currentUntil, | ||
limit = pageSize, | ||
) | ||
|
||
val nextUntil = if (response.isEmpty()) null else response.last().premiumSince?.minus(1) | ||
|
||
LoadResult.Page( | ||
data = response, | ||
prevKey = null, | ||
nextKey = nextUntil, | ||
) | ||
} catch (e: WssException) { | ||
LoadResult.Error(e) | ||
} | ||
} | ||
} |
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
8 changes: 3 additions & 5 deletions
8
app/src/main/kotlin/net/primal/android/premium/leaderboard/ogs/OGLeaderboardContract.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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
package net.primal.android.premium.leaderboard.ogs | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import net.primal.android.premium.leaderboard.domain.OGLeaderboardEntry | ||
|
||
interface OGLeaderboardContract { | ||
data class UiState( | ||
val leaderboardEntries: List<OGLeaderboardEntry> = emptyList(), | ||
val leaderboardEntries: Flow<PagingData<OGLeaderboardEntry>>, | ||
val loading: Boolean = true, | ||
val error: Throwable? = null, | ||
val isActiveAccountPremium: Boolean = false, | ||
) | ||
|
||
sealed class UiEvent { | ||
data object RetryFetch : UiEvent() | ||
} | ||
} |
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.