zt
05/20/2022, 4:31 AMBen Trengrove [G]
05/20/2022, 4:32 AMzt
05/20/2022, 4:32 AMBen Trengrove [G]
05/20/2022, 4:33 AMzt
05/20/2022, 4:38 AMAndrey Kulikov
05/20/2022, 12:41 PMzt
05/20/2022, 8:50 PMvar results by mutableStateOf<Flow<PagingData<DomainSearch.Result>>>(emptyFlow())
private set
fun getResults() {
results = Pager(PagingConfig(10)) {
object : PagingSource<String, DomainSearch.Result>() {
override suspend fun load(params: LoadParams<String>): LoadResult<String, DomainSearch.Result> {
return try {
val searchResults = repository.getSearchResults(search, params.key)
LoadResult.Page(
data = searchResults.items,
prevKey = null,
nextKey = searchResults.continuation
)
} catch (e: Exception) {
e.printStackTrace()
LoadResult.Error(e)
}
}
override fun getRefreshKey(state: PagingState<String, DomainSearch.Result>): String? =
null
}
}.flow.cachedIn(viewModelScope)
}