Skip to content

Instantly share code, notes, and snippets.

@Audhil
Last active July 27, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Audhil/6659a3491b471f2fd27f9f9f83ca957f to your computer and use it in GitHub Desktop.
Save Audhil/6659a3491b471f2fd27f9f9f83ca957f to your computer and use it in GitHub Desktop.
class DummyActivity : AppCompatActivity() {
// it'll be passed from TestCases
private val mockUrl by lazy {
intent?.extras?.getString(ConstantsUtil.MOCK_URL, null)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dummy)
fetchFromServer("https://jsonplaceholder.typicode.com/todos/1")
}
// make server query
private fun fetchFromServer(url: String) {
val disp = GitHubDelegate.INSTANCE.appAPIs.getSampleJson(mockUrl ?: url)
.compose(AppRxSchedulers.applyFlowableSchedulers())
.subscribeWith(object : DisposableSubscriber<SampleJson>() {
override fun onComplete() {
showVLog("FFFF onComplete()")
}
override fun onNext(t: SampleJson?) {
showVLog("FFFF onNext() t?.completed: ${t?.completed}")
dddd.text = "success!!!"
}
override fun onError(t: Throwable?) {
showVLog("FFFF onError()")
dddd.text = "somethingWentWrong!!!"
}
})
}
}
data class SampleJson(
@SerializedName("userId")
val userId: Int? = null,
@SerializedName("id")
val id: Int? = null,
@SerializedName("title")
val title: String? = null,
@SerializedName("completed")
val completed: Boolean? = null
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment