-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pagination to history screen (#37)
* feat: add pagination to HistoryScreen * refactor: update PullToRefresh * fix warnings
- Loading branch information
Showing
12 changed files
with
250 additions
and
229 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
...va/in/iot/lab/teacherreview/feature_teacherlist/data/paging_source/ReviewHistorySource.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,42 @@ | ||
package `in`.iot.lab.teacherreview.feature_teacherlist.data.paging_source | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import `in`.iot.lab.teacherreview.core.utils.Constants | ||
import `in`.iot.lab.teacherreview.feature_authentication.domain.repository.AuthRepository | ||
import `in`.iot.lab.teacherreview.feature_teacherlist.data.remote.ReviewsApi | ||
import `in`.iot.lab.teacherreview.feature_teacherlist.domain.models.remote.IndividualReviewData | ||
|
||
class ReviewHistorySource ( | ||
private val studentId: String, | ||
private val authRepository: AuthRepository, | ||
private val reviewsApi: ReviewsApi | ||
) : PagingSource<Int, IndividualReviewData>() { | ||
override fun getRefreshKey(state: PagingState<Int, IndividualReviewData>): Int? { | ||
return state.anchorPosition | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, IndividualReviewData> { | ||
return try { | ||
val page = params.key ?: 0 | ||
val skip = page * Constants.ITEMS_PER_PAGE | ||
|
||
val response = reviewsApi.getStudentReviewHistory( | ||
token = authRepository.getUserIdToken().getOrDefault(""), | ||
studentId = studentId, | ||
limitValue = Constants.ITEMS_PER_PAGE, | ||
skip = skip | ||
) | ||
|
||
val data = response.body()!!.individualReviewData ?: emptyList() | ||
|
||
LoadResult.Page( | ||
data = data, | ||
prevKey = if (page == 0) null else page - 1, | ||
nextKey = if (data.isEmpty()) null else page + 1 | ||
) | ||
} catch (e: Exception) { | ||
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
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.