Last active
July 27, 2019 10:05
-
-
Save Audhil/6659a3491b471f2fd27f9f9f83ca957f 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
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