-
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.
- Loading branch information
Showing
18 changed files
with
112 additions
and
51 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
19 changes: 19 additions & 0 deletions
19
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/paging/PagingConfig.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,19 @@ | ||
package com.stslex.core.ui.base.paging | ||
|
||
import androidx.compose.runtime.Stable | ||
import com.stslex.core.core.paging.PagingCoreData | ||
|
||
@Stable | ||
data class PagingConfig( | ||
val pageSize: Int, | ||
val pageOffset: Float = PagingCoreData.DEFAULT_PAGE_OFFSET | ||
) { | ||
|
||
companion object { | ||
|
||
val DEFAULT = PagingConfig( | ||
pageSize = PagingCoreData.DEFAULT_PAGE_SIZE, | ||
pageOffset = PagingCoreData.DEFAULT_PAGE_OFFSET | ||
) | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/paging/PagingUiState.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,36 @@ | ||
package com.stslex.core.ui.base.paging | ||
|
||
import androidx.compose.runtime.Stable | ||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlin.math.roundToInt | ||
|
||
@Stable | ||
data class PagingUiState<out T : PagingItem>( | ||
val items: ImmutableList<T>, | ||
val hasMore: Boolean, | ||
val total: Int, | ||
val config: PagingConfig | ||
) { | ||
|
||
val pageOffset: Int = (config.pageSize * config.pageOffset).roundToInt() | ||
|
||
companion object { | ||
|
||
fun <T : PagingItem> default(config: PagingConfig) = PagingUiState( | ||
items = persistentListOf<T>(), | ||
total = 0, | ||
hasMore = true, | ||
config = config | ||
) | ||
} | ||
} | ||
|
||
fun <T : PagingItem> PagingState<T>.toUi( | ||
pagingConfig: PagingConfig | ||
): PagingUiState<T> = PagingUiState( | ||
items = result, | ||
hasMore = hasMore, | ||
total = total, | ||
config = pagingConfig | ||
) |
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
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
Oops, something went wrong.