diff --git a/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt b/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt
index 7161d52..3aee24c 100644
--- a/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt
+++ b/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt
@@ -1,7 +1,9 @@
package ch.srgssr.dataprovider.demo
import android.os.Bundle
-import android.util.Log
+import android.view.View
+import android.widget.ProgressBar
+import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import androidx.lifecycle.Lifecycle
@@ -12,13 +14,16 @@ import ch.srg.dataProvider.integrationlayer.dependencies.modules.OkHttpModule
import ch.srg.dataProvider.integrationlayer.request.IlHost
import ch.srg.dataProvider.integrationlayer.request.IlService
import ch.srg.dataProvider.integrationlayer.request.parameters.Bu
-import kotlinx.coroutines.flow.collectLatest
+import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
class MainActivity : ComponentActivity(R.layout.activity_main) {
+ private lateinit var loadingProgressBar: ProgressBar
+ private lateinit var messageTextView: TextView
+
private lateinit var okHttp: OkHttpClient
private lateinit var ilService: IlService
@@ -27,18 +32,37 @@ class MainActivity : ComponentActivity(R.layout.activity_main) {
super.onCreate(savedInstanceState)
+ loadingProgressBar = findViewById(R.id.loading_pb)
+ messageTextView = findViewById(R.id.message_tv)
+
okHttp = OkHttpModule.createOkHttpClient(this)
ilService = IlServiceModule.createIlService(okHttp, ilHost = IlHost.PROD)
- val flowData = flow {
+ getTvLatestEpisodes()
+ }
+
+ private fun getTvLatestEpisodes() {
+ val tvLatestEpisodesFlow = flow {
emit(ilService.getTvLatestEpisodes(Bu.RTS))
}
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
- flowData.collectLatest {
- Log.d("Coucou", "${it.list}")
- }
+ tvLatestEpisodesFlow
+ .catch { exception ->
+ loadingProgressBar.visibility = View.GONE
+ messageTextView.text = exception.message
+ messageTextView.visibility = View.VISIBLE
+ }
+ .collect { tvLatestEpisodes ->
+ val episodesNames = tvLatestEpisodes.list.joinToString(separator = "\n") {
+ "${it.show?.title} - ${it.title}"
+ }
+
+ loadingProgressBar.visibility = View.GONE
+ messageTextView.text = episodesNames
+ messageTextView.visibility = View.VISIBLE
+ }
}
}
}
diff --git a/dataproviderdemo/src/main/res/layout/activity_main.xml b/dataproviderdemo/src/main/res/layout/activity_main.xml
index 5e8e3dd..3655fe9 100644
--- a/dataproviderdemo/src/main/res/layout/activity_main.xml
+++ b/dataproviderdemo/src/main/res/layout/activity_main.xml
@@ -3,11 +3,22 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:fitsSystemWindows="true"
tools:context=".MainActivity">
+
+
+ android:indeterminate="true" />