Skip to content

Commit dc6f4d6

Browse files
committed
Add common pagination config interface
* Make TasksPaginationConfig implement this interface
1 parent 06807e6 commit dc6f4d6

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.edricchan.studybuddy.domain.common.paging
2+
3+
import com.edricchan.studybuddy.domain.common.sorting.OrderSpec
4+
import kotlinx.coroutines.CoroutineScope
5+
6+
/**
7+
* Interface holding shared pagination options.
8+
* @param OS Desired subclass [OrderSpec] generic for [orderByFields].
9+
*/
10+
interface CommonPagingConfig<OS : OrderSpec<*>> {
11+
/** Desired [CoroutineScope] to cache the paging data in (see [androidx.paging.cachedIn] for more info). */
12+
val cachedCoroutineScope: CoroutineScope
13+
14+
/** Number of items to be shown per page. */
15+
val pageSize: Int
16+
17+
/** The set of [OS] configurations to order the resulting data by, */
18+
val orderByFields: Set<OS>
19+
}

features/tasks/domain/src/main/kotlin/com/edricchan/studybuddy/features/tasks/domain/repo/TasksPaginationConfig.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.edricchan.studybuddy.features.tasks.domain.repo
22

3+
import com.edricchan.studybuddy.domain.common.paging.CommonPagingConfig
34
import com.edricchan.studybuddy.domain.common.sorting.OrderSpec
45
import com.edricchan.studybuddy.domain.common.sorting.SortDirection
56
import com.edricchan.studybuddy.features.tasks.domain.model.TaskItem
@@ -16,12 +17,12 @@ import kotlinx.coroutines.CoroutineScope
1617
* applied sequentially in-order.
1718
*/
1819
data class TasksPaginationConfig(
19-
val cachedCoroutineScope: CoroutineScope,
20+
override val cachedCoroutineScope: CoroutineScope,
2021
val includeArchived: Boolean = false,
2122
val excludeCompleted: Boolean = false,
22-
val pageSize: Int = 30,
23-
val orderByFields: Set<TaskOrderSpec> = setOf(TaskOrderSpec())
24-
) {
23+
override val pageSize: Int = 30,
24+
override val orderByFields: Set<TaskOrderSpec> = setOf(TaskOrderSpec())
25+
) : CommonPagingConfig<TasksPaginationConfig.TaskOrderSpec> {
2526
data class TaskOrderSpec(
2627
override val field: TaskItem.Field = TaskItem.Field.CreatedAt,
2728
override val direction: SortDirection = SortDirection.Descending

0 commit comments

Comments
 (0)