Skip to content

Commit 0a6cbb0

Browse files
committed
feat: add ProfilePicker screen
1 parent 70b950b commit 0a6cbb0

File tree

20 files changed

+654
-8
lines changed

20 files changed

+654
-8
lines changed

app/src/main/java/com/codandotv/streamplayerapp/navigation/NavigationGraph.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
55
import androidx.compose.material3.Scaffold
66
import androidx.compose.material3.Text
77
import androidx.compose.runtime.Composable
8-
import androidx.compose.runtime.saveable.rememberSaveable
98
import androidx.compose.ui.graphics.Color
109
import androidx.navigation.NavController
1110
import androidx.navigation.NavGraphBuilder
@@ -17,6 +16,7 @@ import com.codandotv.streamplayerapp.core_navigation.routes.BottomNavRoutes
1716
import com.codandotv.streamplayerapp.core_navigation.routes.Routes
1817
import com.codandotv.streamplayerapp.feature_list_streams.detail.presentation.navigation.detailStreamNavGraph
1918
import com.codandotv.streamplayerapp.feature_list_streams.list.presentation.navigation.listStreamsNavGraph
19+
import com.codandotv.streamplayerapp.feature_list_streams.profile.presentation.navigation.profilePickerStreamNavGraph
2020
import com.codandotv.streamplayerapp.splah.presentation.navigation.splashNavGraph
2121

2222
@Composable
@@ -29,6 +29,7 @@ fun NavigationGraph(navController: NavHostController) {
2929
temporaryFun(BottomNavRoutes.NEWS, navController)
3030
temporaryFun(BottomNavRoutes.SCENES, navController)
3131
temporaryFun(BottomNavRoutes.DOWNLOADS, navController)
32+
profilePickerStreamNavGraph(navController = navController)
3233
}
3334
}
3435

core-navigation/src/main/java/com/codandotv/streamplayerapp/core_navigation/routes/Routes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ object Routes {
66
const val DETAIL = "DetailList/"
77
const val DETAIL_COMPLETE = "${DETAIL}{${ID}}"
88
const val Splash = "splash"
9+
const val PROFILE_PICKER = "profilePicker"
910

1011
object PARAM {
1112
const val ID = "id"

core-shared-ui/src/main/java/com/codandotv/streamplayerapp/core_shared_ui/widget/StreamPlayerTopBar.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ import com.codandotv.streamplayerapp.core_shared_ui.theme.ThemePreviews
3434

3535
@OptIn(ExperimentalMaterial3Api::class)
3636
@Composable
37-
fun StreamPlayerTopBar(scrollBehavior: TopAppBarScrollBehavior) {
37+
fun StreamPlayerTopBar(
38+
scrollBehavior: TopAppBarScrollBehavior,
39+
onNavigateProfilePicker: () -> Unit = {}
40+
) {
3841
Box(modifier = Modifier.background(color = Colors.Dark10)) {
39-
StreamPlayerTopBar()
42+
StreamPlayerTopBar(
43+
onNavigateProfilePicker = { onNavigateProfilePicker() },
44+
)
4045
StreamPlayerOptionsTopBar(modifier = Modifier.padding(top = 50.dp), scrollBehavior)
4146
}
4247
}
4348

4449
@Composable
45-
private fun StreamPlayerTopBar() {
50+
private fun StreamPlayerTopBar(onNavigateProfilePicker: () -> Unit = {}) {
4651
Row(
4752
modifier = Modifier
4853
.height(50.dp)
@@ -75,7 +80,7 @@ private fun StreamPlayerTopBar() {
7580

7681
IconButton(
7782
modifier = Modifier.fillMaxHeight(),
78-
onClick = { /* todo */ }
83+
onClick = { onNavigateProfilePicker() }
7984
) {
8085
Icon(
8186
modifier = Modifier

feature-list-streams/src/main/java/com/codandotv/streamplayerapp/feature_list_streams/list/presentation/navigation/ListStreamsNavigation.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package com.codandotv.streamplayerapp.feature_list_streams.list.presentation.nav
22

33
import androidx.activity.compose.BackHandler
44
import androidx.lifecycle.Lifecycle
5-
import androidx.navigation.NavGraph.Companion.findStartDestination
65
import androidx.navigation.NavGraphBuilder
76
import androidx.navigation.NavHostController
87
import androidx.navigation.compose.composable
98
import com.codandotv.streamplayerapp.core_navigation.routes.BottomNavRoutes
109
import com.codandotv.streamplayerapp.core_navigation.routes.Routes.DETAIL
10+
import com.codandotv.streamplayerapp.core_navigation.routes.Routes.PROFILE_PICKER
1111
import com.codandotv.streamplayerapp.feature_list_streams.list.di.ListStreamModule
1212
import com.codandotv.streamplayerapp.feature_list_streams.list.presentation.screens.ListStreamsScreen
1313
import org.koin.core.context.loadKoinModules
@@ -22,7 +22,11 @@ fun NavGraphBuilder.listStreamsNavGraph(navController: NavHostController) {
2222
ListStreamsScreen(navController = navController,
2323
onNavigateDetailList = { id ->
2424
navController.navigate("${DETAIL}${id}")
25-
}, disposable = {
25+
},
26+
onNavigateProfilePicker = {
27+
navController.navigate(PROFILE_PICKER)
28+
},
29+
disposable = {
2630
unloadKoinModules(ListStreamModule.module)
2731
})
2832
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fun ListStreamsScreen(
3434
viewModel: ListStreamViewModel = koinViewModel(),
3535
navController: NavController,
3636
onNavigateDetailList: (String) -> Unit = {},
37+
onNavigateProfilePicker: () -> Unit = {},
3738
disposable: () -> Unit = {}
3839
) {
3940
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
@@ -56,7 +57,10 @@ fun ListStreamsScreen(
5657
Scaffold(
5758
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
5859
topBar = {
59-
StreamPlayerTopBar(scrollBehavior)
60+
StreamPlayerTopBar(
61+
scrollBehavior = scrollBehavior,
62+
onNavigateProfilePicker = onNavigateProfilePicker
63+
)
6064
},
6165
bottomBar = {
6266
StreamPlayerBottomNavigation(navController = navController)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.codandotv.streamplayerapp.feature_list_streams.profile.data
2+
3+
import com.codandotv.streamplayerapp.core_networking.handleError.toFlow
4+
import com.codandotv.streamplayerapp.feature_list_streams.profile.domain.ProfileStream
5+
import com.codandotv.streamplayerapp.feature_list_streams.profile.domain.toProfiles
6+
import kotlinx.coroutines.flow.Flow
7+
import kotlinx.coroutines.flow.flowOf
8+
import kotlinx.coroutines.flow.map
9+
10+
interface ProfilePickerStreamRepository {
11+
suspend fun getProfiles(): Flow<List<ProfileStream>>
12+
}
13+
14+
class ProfilePickerStreamRepositoryImpl(
15+
private val service: ProfilePickerStreamService
16+
) : ProfilePickerStreamRepository {
17+
18+
override suspend fun getProfiles(): Flow<List<ProfileStream>> {
19+
val remoteProfiles = service.getProfiles().toFlow().map { it.toProfiles() }
20+
val localProfiles = flowOf(mockProfiles)
21+
22+
// ideal solution, but as remote profiles is not working to profiles, I'm using mockProfiles
23+
// return combine(remoteProfiles, localProfiles) { remote, local -> remote + local }
24+
25+
return localProfiles
26+
}
27+
}
28+
29+
30+
private val mockProfiles = listOf(
31+
ProfileStream(
32+
name = "Chapei de Palha",
33+
imageUrl = "https://raw.githubusercontent.com/git-jr/sample-files/main/profile%20pics/netflix_profile_pic_1.png"
34+
),
35+
ProfileStream(
36+
name = "Jonas",
37+
imageUrl = "https://raw.githubusercontent.com/git-jr/sample-files/main/profile%20pics/netflix_profile_pic_2.png"
38+
),
39+
ProfileStream(
40+
name = "Random name 1",
41+
imageUrl = "https://raw.githubusercontent.com/git-jr/sample-files/main/profile%20pics/netflix_profile_pic_3.png"
42+
),
43+
ProfileStream(
44+
name = "Random name 3",
45+
imageUrl = "https://raw.githubusercontent.com/git-jr/sample-files/main/profile%20pics/netflix_profile_pic_4.png"
46+
),
47+
ProfileStream(
48+
name = "Random name 2",
49+
imageUrl = "https://raw.githubusercontent.com/git-jr/sample-files/main/profile%20pics/netflix_profile_pic_5.png"
50+
)
51+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.codandotv.streamplayerapp.feature_list_streams.profile.data
2+
3+
import com.codandotv.streamplayerapp.core_networking.handleError.NetworkResponse
4+
import com.codandotv.streamplayerapp.feature_list_streams.profile.data.model.ProfilesResponse
5+
import retrofit2.http.GET
6+
7+
interface ProfilePickerStreamService {
8+
@GET("profiles")
9+
suspend fun getProfiles(): NetworkResponse<ProfilesResponse>
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.codandotv.streamplayerapp.feature_list_streams.profile.data.model
2+
3+
data class ProfileStreamResponse(
4+
val id: String,
5+
val name: String,
6+
val profile_url: String,
7+
)
8+
9+
data class ProfilesResponse(
10+
val profiles: List<ProfileStreamResponse>
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.codandotv.streamplayerapp.feature_list_streams.profile.di
2+
3+
import com.codandotv.streamplayerapp.feature_list_streams.profile.data.ProfilePickerStreamRepository
4+
import com.codandotv.streamplayerapp.feature_list_streams.profile.data.ProfilePickerStreamRepositoryImpl
5+
import com.codandotv.streamplayerapp.feature_list_streams.profile.data.ProfilePickerStreamService
6+
import com.codandotv.streamplayerapp.feature_list_streams.profile.domain.ProfilePickerStreamUseCase
7+
import com.codandotv.streamplayerapp.feature_list_streams.profile.domain.ProfilePickerStreamUseCaseImpl
8+
import com.codandotv.streamplayerapp.feature_list_streams.profile.presentation.screens.ProfilePickerStreamViewModel
9+
import org.koin.androidx.viewmodel.dsl.viewModel
10+
import org.koin.dsl.module
11+
import retrofit2.Retrofit
12+
13+
object ProfilePickerStreamModule {
14+
val module = module {
15+
viewModel {
16+
ProfilePickerStreamViewModel(
17+
useCase = get()
18+
)
19+
}
20+
21+
factory<ProfilePickerStreamUseCase> {
22+
ProfilePickerStreamUseCaseImpl(
23+
profilePickerStreamRepository = get()
24+
)
25+
}
26+
27+
factory<ProfilePickerStreamRepository> {
28+
ProfilePickerStreamRepositoryImpl(
29+
service = get()
30+
)
31+
}
32+
33+
factory { get<Retrofit>().create(ProfilePickerStreamService::class.java) }
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.codandotv.streamplayerapp.feature_list_streams.profile.domain
2+
3+
import com.codandotv.streamplayerapp.feature_list_streams.profile.data.model.ProfilesResponse
4+
5+
fun ProfilesResponse.toProfiles(): List<ProfileStream> = this.profiles.map { profileResponse ->
6+
ProfileStream(
7+
id = profileResponse.id,
8+
name = profileResponse.name,
9+
imageUrl = profileResponse.profile_url,
10+
)
11+
}

0 commit comments

Comments
 (0)