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
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 | |
} |
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
import androidx.work.* | |
class GetReposManagedRestRequest(origin: ManagedRestRequest) : ManagedRestRequest.Wrap(origin) { | |
constructor( | |
workManager: WorkManager, | |
worker: OneTimeWorkRequest | |
) : this( | |
SimpleOneTimeWorkRequest(workManager, worker) | |
) |
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
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 { |
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
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( |
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
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 { |
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
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' |
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
RxGetReposRequest( | |
restRequest = WithBodyRestRequest( | |
SuccessfulRestRequest( | |
LoggableRequest( | |
GetReposRequest( | |
client = client, | |
baseUrl = "https://api.github.com/", | |
user = "RoRoche" | |
) | |
) |
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
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) |
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
import io.reactivex.Single | |
interface RxRestRequest<T> { | |
fun single(): Single<T> | |
abstract class WrapSyncRequest<T>(protected val restRequest: RestRequest) : RxRestRequest<T> | |
} |
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 NoBodyRestResponseException : RuntimeException() |
NewerOlder