public class LoadWeatherForecastTask
extends AsyncTask < String,
Integer,
Forecast > {
public void onPostExecute(Forecast forecast) {
mTemperatureView.setText(forecast.getTemp());
}
}
class WeatherForecastLoader(context: Context) : AsyncTaskLoader < WeatherForecast > (context) {
override fun loadInBackground() : WeatherForecast {
try {
Thread.sleep(5000)
} catch(e: InterruptedException) {
return WeatherForecast("", 0F, "")
}
return WeatherForecast("Saint-Petersburg", 20F, "Sunny")
}
}
public class Background {
private val mService = ScheduledThreadPoolExecutor(5)
fun execute(runnable: Runnable) : Future < *>{
return mService.submit(runnable)
}
fun < T > submit(runnable: Callable < T > ) : Future < T > {
return mService.submit(runnable)
}
}
public class Background {…private lateinit
var mUiHandler: Handler
public fun postOnUiThread(runnable: Runnable) {
mUiHandler.post(runnable)
}
}
interface ApiClientRx {
fun login(auth: Authorization)
: Single < GithubUser >
fun getRepositories(reposUrl: String, auth: Authorization)
: Single < List < GithubRepository >>
}
private fun attemptLogin() {
launch(UI) {
val auth = BasicAuthorization(login, pass) try {
showProgress(true) val userInfo = login(auth).await() val repoUrl = userInfo.repos_url val list = getRepositories(repoUrl, auth).await() showRepositories(this@LoginActivity, list.map {
it - >it.full_name
})
} catch(e: RuntimeException) {
Toast.makeText(this@LoginActivity, e.message, LENGTH_LONG).show()
} finally {
showProgress(false)
}
}
}