Skip to content

Instantly share code, notes, and snippets.

Romain Rochegude RoRoche

View GitHub Profile
View GetReposManagedRestRequest_usage.kt
GetReposManagedRestRequest(
workManager = workManager,
baseUrl = "https://api.github.com/",
user = "RoRoche"
).liveData().observe(
lifecycleOwner,
Observer { workInfo ->
if (workInfo != null) {
// check with workInfo.state and deal with it
}
View GetReposManagedRestRequest.kt
import androidx.work.*
class GetReposManagedRestRequest(origin: ManagedRestRequest) : ManagedRestRequest.Wrap(origin) {
constructor(
workManager: WorkManager,
worker: OneTimeWorkRequest
) : this(
SimpleOneTimeWorkRequest(workManager, worker)
)
View SimpleOneTimeWorkRequest.kt
import androidx.work.OneTimeWorkRequest
import androidx.work.Operation
import androidx.work.WorkManager
class SimpleOneTimeWorkRequest(
private val workManager: WorkManager,
private val worker: OneTimeWorkRequest,
private val operation: Operation
) : ManagedRestRequest {
View ManagedRestRequest.kt
import androidx.lifecycle.LiveData
import androidx.work.Operation
import androidx.work.WorkInfo
interface ManagedRestRequest {
fun operation(): Operation
fun liveData(): LiveData<WorkInfo>
fun cancel(): Operation
abstract class Wrap protected constructor(
View GetReposWorker.kt
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import okhttp3.OkHttpClient
class GetReposWorker(
appContext: Context,
workerParams: WorkerParameters
) : Worker(appContext, workerParams) {
override fun doWork(): Result {
View build_rx.gradle
implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.2.14'
implementation group: 'io.reactivex.rxjava2', name: 'rxandroid', version: '2.1.1'
implementation group: 'io.reactivex.rxjava2', name: 'rxkotlin', version: '2.4.0'
View RxGetReposRequest_usage.kt
RxGetReposRequest(
restRequest = WithBodyRestRequest(
SuccessfulRestRequest(
LoggableRequest(
GetReposRequest(
client = client,
baseUrl = "https://api.github.com/",
user = "RoRoche"
)
)
View RxGetReposRequest.kt
import io.reactivex.Single
import okhttp3.OkHttpClient
class RxGetReposRequest(
restRequest: RestRequest
) : RxRestRequest.WrapSyncRequest<List<Repo>>(restRequest) {
override fun single(): Single<List<Repo>> {
return Single.create { emitter ->
try {
val repos = JsonRepos(restRequest)
View RxRestRequest.kt
import io.reactivex.Single
interface RxRestRequest<T> {
fun single(): Single<T>
abstract class WrapSyncRequest<T>(protected val restRequest: RestRequest) : RxRestRequest<T>
}
View NoBodyRestResponseException.kt
class NoBodyRestResponseException : RuntimeException()
You can’t perform that action at this time.