mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 00:57:02 +05:30
all: use retrofit suspend support to hide implementation details of API
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
a3b1e02783
commit
a66186adc3
3 changed files with 3 additions and 20 deletions
|
@ -20,9 +20,6 @@ import dev.msfjarvis.lobsters.ui.LobstersItem
|
|||
import dev.msfjarvis.lobsters.ui.LobstersTheme
|
||||
import dev.msfjarvis.lobsters.urllauncher.UrlLauncher
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import javax.inject.Inject
|
||||
|
||||
val UrlLauncherAmbient = ambientOf<UrlLauncher> { error("Needs to be provided") }
|
||||
|
@ -40,20 +37,7 @@ class MainActivity : AppCompatActivity() {
|
|||
val coroutineScope = rememberCoroutineScope()
|
||||
val posts = mutableStateListOf<LobstersPost>()
|
||||
coroutineScope.launch {
|
||||
apiClient.getHottestPosts().enqueue(object : Callback<List<LobstersPost>> {
|
||||
override fun onResponse(
|
||||
call: Call<List<LobstersPost>>,
|
||||
response: Response<List<LobstersPost>>
|
||||
) {
|
||||
if (response.isSuccessful) {
|
||||
response.body()?.let { posts.addAll(it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<List<LobstersPost>>, t: Throwable) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
})
|
||||
posts.addAll(apiClient.getHottestPosts())
|
||||
}
|
||||
LobstersApp(posts)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue