Skip to content

Commit ae99c21

Browse files
committed
[ISSUE-25] - Integrating data with ui + Removing mocks
1 parent 8ab5c36 commit ae99c21

File tree

5 files changed

+57
-65
lines changed

5 files changed

+57
-65
lines changed

feature-list-streams/src/main/java/com/codandotv/streamplayerapp/feature_list_streams/domain/ListStreamMapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fun ListStreamResponse.toListStream(): ListStream =
1010
Stream(
1111
description = it.overview,
1212
name = it.title,
13-
posterPathUrl = it.poster_path
13+
posterPathUrl = "https://image.tmdb.org/t/p/w300${it.poster_path}"
1414
)
1515
}
1616
)
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
package com.codandotv.streamplayerapp.feature_list_streams.presentation
22

33
import android.content.res.Resources
4+
import com.codandotv.streamplayerapp.feature_list_streams.domain.model.ListStream
5+
import com.codandotv.streamplayerapp.feature_list_streams.presentation.screens.CarouselData
6+
import com.codandotv.streamplayerapp.feature_list_streams.presentation.screens.ListStreamsUIState
7+
import com.codandotv.streamplayerapp.feature_list_streams.presentation.widgets.StreamsCardContent
48

59
interface ListStreamUimodel {
10+
fun convertToCardContent(listStream: ListStream): ListStreamsUIState
611
}
712

813
class ListStreamUiModelImpl(
9-
private val resources : Resources
14+
private val resources: Resources
1015
) : ListStreamUimodel {
11-
12-
13-
14-
15-
16+
override fun convertToCardContent(listStream: ListStream): ListStreamsUIState {
17+
return ListStreamsUIState(
18+
carousels = listOf(
19+
CarouselData(
20+
categoryName = "",
21+
cards = listStream.streams.map {
22+
StreamsCardContent(
23+
contentDescription = it.name,
24+
url = it.posterPathUrl
25+
)
26+
}
27+
)
28+
)
29+
)
30+
}
1631
}

feature-list-streams/src/main/java/com/codandotv/streamplayerapp/feature_list_streams/presentation/screens/ListStreamViewModel.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.codandotv.streamplayerapp.feature_list_streams.presentation.screens
22

3+
import androidx.compose.runtime.State
4+
import androidx.compose.runtime.mutableStateOf
35
import androidx.lifecycle.ViewModel
46
import androidx.lifecycle.viewModelScope
57
import com.codandotv.streamplayerapp.core_networking.handleError.catchFailure
@@ -18,14 +20,22 @@ class ListStreamViewModel(
1820
private val useCase: ListStreamUseCase,
1921
private val analytics: ListStreamAnalytics
2022
) : ViewModel() {
23+
24+
private val _uiState = mutableStateOf(
25+
ListStreamsUIState(
26+
emptyList()
27+
)
28+
)
29+
val uiState : State<ListStreamsUIState> = _uiState
30+
2131
init {
2232
viewModelScope.launch {
2333
useCase.getMovies()
2434
.catchFailure {
2535
println(">>>> ${it.errorMessage}")
2636
}
2737
.collect {
28-
println(">>> $it")
38+
_uiState.value = uiModel.convertToCardContent(it)
2939
}
3040
}
3141
}

feature-list-streams/src/main/java/com/codandotv/streamplayerapp/feature_list_streams/presentation/screens/ListStreamsScreen.kt

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,34 @@ import androidx.compose.foundation.layout.height
88
import androidx.compose.foundation.layout.padding
99
import androidx.compose.material3.MaterialTheme
1010
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.remember
1112
import androidx.compose.ui.Modifier
1213
import androidx.compose.ui.unit.dp
1314
import com.codandotv.streamplayerapp.core_shared_ui.theme.ThemePreview
1415
import com.codandotv.streamplayerapp.core_shared_ui.theme.ThemePreviews
15-
import com.codandotv.streamplayerapp.feature_list_streams.presentation.widgets.StreamsCardContent
1616
import com.codandotv.streamplayerapp.feature_list_streams.presentation.widgets.StreamsCarousel
1717
import org.koin.androidx.compose.koinViewModel
1818

19-
val streamsCategoryX = listOf(
20-
StreamsCardContent(
21-
contentDescription = "test",
22-
url = "https://image.tmdb.org/t/p/w300/gU84Leiw6dYyxcx3S7kfneLnVJH.jpg"
23-
),
24-
StreamsCardContent(
25-
contentDescription = "test",
26-
url = "https://image.tmdb.org/t/p/w300/evgwd37VHBJhXvSr88Mrx5riFil.jpg"
27-
),
28-
StreamsCardContent(
29-
contentDescription = "test",
30-
url = "https://image.tmdb.org/t/p/w300/wAKExQIBBiApsucimUIv6aiJsWF.jpg"
31-
),
32-
StreamsCardContent(
33-
contentDescription = "test",
34-
url = "https://image.tmdb.org/t/p/w300/mKEDE9r2ggqtGv5krCFLuELh7ED.jpg"
35-
),
36-
StreamsCardContent(
37-
contentDescription = "test",
38-
url = "https://image.tmdb.org/t/p/w300/ojCfQ8syImYWJ38sta46BOz00PC.jpg"
39-
)
40-
)
41-
42-
val streamsCategoryY = listOf(
43-
StreamsCardContent(
44-
contentDescription = "test",
45-
url = "https://image.tmdb.org/t/p/w300/lOrPcXLAfdtWFSeMPdMiBLwlvtv.jpg"
46-
),
47-
StreamsCardContent(
48-
contentDescription = "test",
49-
url = "https://image.tmdb.org/t/p/w300/yjs9NikrKZUmIX3ou3J9QiUcQUP.jpg"
50-
), StreamsCardContent(
51-
contentDescription = "test",
52-
url = "https://image.tmdb.org/t/p/w300/vfdO4lUxZaUrRhI60Gvf5WEqdhY.jpg"
53-
),
54-
StreamsCardContent(
55-
contentDescription = "test",
56-
url = "https://image.tmdb.org/t/p/w300/qdzIpsDH1D0uiFTvFQL9WW4MEZ4.jpg"
57-
),
58-
StreamsCardContent(
59-
contentDescription = "test",
60-
url = "https://image.tmdb.org/t/p/w300/i17CbxJ8GrGvPneiknjGyJrbqvp.jpg"
61-
)
62-
)
63-
6419
@Composable
6520
fun ListStreamsScreen(viewModel: ListStreamViewModel = koinViewModel()) {
21+
22+
val uiState = remember {
23+
viewModel.uiState
24+
}
25+
6626
Column(
6727
modifier = Modifier
6828
.background(MaterialTheme.colorScheme.background)
6929
.fillMaxSize()
7030
) {
71-
StreamsCarousel(
72-
title = "Category X",
73-
contentList = streamsCategoryX,
74-
modifier = Modifier.padding(vertical = 8.dp)
75-
)
31+
uiState.value.carousels.forEach {
32+
StreamsCarousel(
33+
title = "Category do Server",
34+
contentList = it.cards
35+
)
36+
}
7637

7738
Spacer(modifier = Modifier.height(12.dp))
78-
79-
StreamsCarousel(
80-
title = "Category Y",
81-
contentList = streamsCategoryY,
82-
modifier = Modifier.padding(vertical = 8.dp)
83-
)
8439
}
8540
}
8641

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codandotv.streamplayerapp.feature_list_streams.presentation.screens
2+
3+
import com.codandotv.streamplayerapp.feature_list_streams.presentation.widgets.StreamsCardContent
4+
5+
data class CarouselData(
6+
val categoryName: String,
7+
val cards: List<StreamsCardContent>
8+
)
9+
10+
data class ListStreamsUIState(
11+
val carousels: List<CarouselData>
12+
)

0 commit comments

Comments
 (0)