Created
May 27, 2018 18:09
-
-
Save bltuckerdevblog/a39947c545a6f128b718a343718af5ca to your computer and use it in GitHub Desktop.
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
interface NamesApi { | |
@GET("names") | |
fun getNamesAfter(@Query("after") afterName : String, @Query("limit") limit: Int) : Call<Array<String>> | |
} |
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
class NamesDataSource constructor(private val namesApi: NamesApi) : ItemKeyedDataSource<String, String>() { | |
override fun loadInitial(params: LoadInitialParams<String>, callback: LoadInitialCallback<String>) { | |
val response = namesApi.getNamesAfter("", params.requestedLoadSize).execute() | |
val responseData = response.body()?.toList() ?: listOf() | |
callback.onResult(responseData) | |
} | |
override fun loadAfter(params: LoadParams<String>, callback: LoadCallback<String>) { | |
val response = namesApi.getNamesAfter(params.key, params.requestedLoadSize).execute() | |
val responseData = response.body()?.toList() ?: listOf() | |
callback.onResult(responseData) | |
} | |
override fun loadBefore(params: LoadParams<String>, callback: LoadCallback<String>) { | |
} | |
override fun getKey(item: String) = item | |
} |
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
class NamesDataSourceFactory @Inject constructor(private val namesApi: NamesApi) : DataSource.Factory<String, String>() { | |
override fun create(): DataSource<String, String> { | |
return NamesDataSource(namesApi) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment