Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flickering in message list due to paging (AR-2848) #1235

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ android {

packagingOptions {
resources.pickFirsts.add("google/protobuf/*.proto")
jniLibs.pickFirsts.add("**/libsodium.so")
}

// sourceSets { map { it.java.srcDir("src/${it.name}/kotlin") } }
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ sql-android-cipher = { module = "net.zetetic:android-database-sqlcipher", versio
sqldelight-runtime = { module = "app.cash.sqldelight:runtime", version.ref = "sqldelight" }
sqldelight-coroutinesExtension = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
sqldelight-androidDriver = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
sqldelight-androidPaging = { module = "app.cash.sqldelight:android-paging3-extensions", version.ref = "sqldelight" }
sqldelight-androidxPaging = { module = "app.cash.sqldelight:androidx-paging3-extensions", version.ref = "sqldelight" }
sqldelight-nativeDriver = { module = "app.cash.sqldelight:native-driver", version.ref = "sqldelight" }
sqldelight-jvmDriver = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
sqldelight-jsDriver = { module = "app.cash.sqldelight:sqljs-driver", version.ref = "sqldelight" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import org.junit.Test

class MessageRepositoryExtensionsTest {

private val fakePagingSource = object : PagingSource<Long, MessageEntity>() {
override fun getRefreshKey(state: PagingState<Long, MessageEntity>): Long? = null
private val fakePagingSource = object : PagingSource<Int, MessageEntity>() {
override fun getRefreshKey(state: PagingState<Int, MessageEntity>): Int? = null

override suspend fun load(params: LoadParams<Long>): LoadResult<Long, MessageEntity> =
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MessageEntity> =
LoadResult.Error(NotImplementedError("STUB for tests. Not implemented."))
}

Expand Down
1 change: 1 addition & 0 deletions persistence/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ kotlin {
dependencies {
implementation(libs.securityCrypto)
implementation(libs.sqldelight.androidDriver)
implementation(libs.sqldelight.androidxPaging)
implementation(libs.paging3)
implementation(libs.sqlite.androidx)
implementation(libs.sql.android.cipher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MessageExtensionsTest : BaseDatabaseTest() {

val result = getPager().pagingSource.refresh()

assertIs<PagingSource.LoadResult.Page<Long, MessageEntity>>(result)
assertIs<PagingSource.LoadResult.Page<Int, MessageEntity>>(result)
// Assuming the first page was fetched, itemsAfter should be the remaining ones
assertEquals(MESSAGE_COUNT - PAGE_SIZE, result.itemsAfter)
// No items before the first page
Expand All @@ -73,19 +73,19 @@ class MessageExtensionsTest : BaseDatabaseTest() {

val result = getPager().pagingSource.refresh()

assertIs<PagingSource.LoadResult.Page<Long, MessageEntity>>(result)
assertIs<PagingSource.LoadResult.Page<Int, MessageEntity>>(result)
// First page fetched, second page starts at the end of the first one
assertEquals(PAGE_SIZE.toLong(), result.nextKey)
assertEquals(PAGE_SIZE, result.nextKey)
}

@Test
fun givenInsertedMessages_whenGettingSecondPage_thenShouldContainTheCorrectItems() = runTest {
populateMessageData()

val pagingSource = getPager().pagingSource
val secondPageResult = pagingSource.nextPageForOffset(PAGE_SIZE.toLong())
val secondPageResult = pagingSource.nextPageForOffset(PAGE_SIZE)

assertIs<PagingSource.LoadResult.Page<Long, MessageEntity>>(secondPageResult)
assertIs<PagingSource.LoadResult.Page<Int, MessageEntity>>(secondPageResult)

secondPageResult.data.forEachIndexed { index, message ->
assertEquals((index + PAGE_SIZE).toString(), message.id)
Expand All @@ -98,11 +98,11 @@ class MessageExtensionsTest : BaseDatabaseTest() {
pagingConfig = PagingConfig(PAGE_SIZE)
)

private suspend fun PagingSource<Long, MessageEntity>.refresh() = load(
private suspend fun PagingSource<Int, MessageEntity>.refresh() = load(
PagingSource.LoadParams.Refresh(null, PAGE_SIZE, true)
)

private suspend fun PagingSource<Long, MessageEntity>.nextPageForOffset(key: Long) = load(
private suspend fun PagingSource<Int, MessageEntity>.nextPageForOffset(key: Int) = load(
PagingSource.LoadParams.Append(key, PAGE_SIZE, true)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import kotlinx.coroutines.flow.Flow
* Exposes a [pagingDataFlow] that can be used in Android UI components to display paginated data.
*/
class KaliumPager<EntityType : Any>(
private val pager: Pager<Long, EntityType>,
internal val pagingSource: PagingSource<Long, EntityType>
private val pager: Pager<Int, EntityType>,
internal val pagingSource: PagingSource<Int, EntityType>
) {
val pagingDataFlow: Flow<PagingData<EntityType>>
get() = pager.flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.wire.kalium.persistence.dao.message

import androidx.paging.Pager
import androidx.paging.PagingConfig
import app.cash.sqldelight.paging3.QueryPagingSource
import com.wire.kalium.persistence.MessagesQueries
import com.wire.kalium.persistence.dao.ConversationIDEntity
import com.wire.kalium.persistence.paging.QueryPagingSource

actual interface MessageExtensions {
fun getPagerForConversation(
Expand Down

This file was deleted.

This file was deleted.