-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from dead8309/master
Add Pagination to for Showing Reviews
- Loading branch information
Showing
12 changed files
with
303 additions
and
381 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
41 changes: 41 additions & 0 deletions
41
...ain/java/in/iot/lab/teacherreview/feature_teacherlist/data/paging_source/ReviewsSource.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 `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 ReviewsSource ( | ||
private val facultyId: 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.getIndividualTeacherReviews( | ||
token = authRepository.getUserIdToken().getOrDefault(""), | ||
facultyId = facultyId, | ||
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
5 changes: 4 additions & 1 deletion
5
...n/java/in/iot/lab/teacherreview/feature_teacherlist/domain/repository/ReviewRepository.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
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.