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
object DependencyContainer { | |
val jobRepository: JobRepository | |
init { | |
val retrofit = Retrofit.Builder() | |
// ... | |
.build() | |
val stuartApi = retrofit.create(StuartApi::class.java) |
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
object FirebasePushUpdates : PushUpdates { | |
val jobSubject = PublishSubject.create<Job>().toSerialized() | |
override val jobs: Observable<Job> = jobSubject | |
} | |
class FirebaseMessagingService : FirebaseMessagingService() { |
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 WebSocketPushUpdates(private val context: Context) : PushUpdates { | |
private val jobSubject = PublishSubject.create<Job>().toSerialized() | |
override val jobs: Observable<Job> = jobSubject | |
.doOnSubscribe { bindService() } | |
.doOnDispose { unbindService() } | |
private val connection = ServiceConnection() |
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 PushUpdates { | |
val jobs: Observable<Job> | |
} | |
class SubscribedJobRepository( | |
private val delegate: JobRepository, | |
private val pushUpdates: PushUpdates | |
) : JobRepository by delegate { |
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 JobCache { | |
fun getJob(jobId: String): Maybe<Job> | |
fun putJob(job: Job) | |
} | |
class CachedJobRepository( | |
private val delegate: JobRepository, |
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 StuartApi { | |
@GET("/v2/jobs/{id}") | |
fun getJob(@Path("id") jobId: String): Single<ApiJob> | |
@GET("/v2/jobs") | |
fun getJobs( | |
@Query("page") page: Int, | |
@Query("per_page") perPage: Int | |
): Single<List<ApiJob>> |
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 JobRepository { | |
fun getJob(jobId: String): Observable<Job> | |
fun getJobs(page: Int = 0): Single<List<Job>> | |
} |
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
jobRepository.getJob("001").subscribe({ job -> | |
Log.d("Got a Job #${job.id}") | |
}) |