Skip to content

Commit

Permalink
removed hardcoded compose navigator from composable.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndroidPoet committed Oct 18, 2023
1 parent b4fdc4b commit 11c6494
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.getstream.whatsappclone.navigation
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import io.getstream.whatsappclone.calls.info.WhatsAppCallHistoryInfo
Expand All @@ -28,8 +27,7 @@ import io.getstream.whatsappclone.model.WhatsAppUser
import io.getstream.whatsappclone.ui.WhatsAppTabPager
import io.getstream.whatsappclone.ui.WhatsAppTopBar

fun NavGraphBuilder.whatsAppHomeNavigation(
) {
fun NavGraphBuilder.whatsAppHomeNavigation() {
composable(route = WhatsAppScreens.Home.name) {
Scaffold(topBar = { WhatsAppTopBar() }) { padding ->
WhatsAppTabPager(
Expand All @@ -44,9 +42,9 @@ fun NavGraphBuilder.whatsAppHomeNavigation(
) {
val channelId = it.arguments?.getString("channelId") ?: return@composable
WhatsAppMessages(
channelId = channelId,
channelId = channelId

)
)
}

composable(
Expand All @@ -57,7 +55,7 @@ fun NavGraphBuilder.whatsAppHomeNavigation(
?: return@composable

WhatsAppCallHistoryInfo(
whatsAppUser = whatsAppUser,
)
whatsAppUser = whatsAppUser
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import io.getstream.whatsappclone.designsystem.component.WhatsAppCloneBackground
import io.getstream.whatsappclone.designsystem.icon.WhatsAppIcons
import io.getstream.whatsappclone.designsystem.theme.WHITE200
import io.getstream.whatsappclone.designsystem.theme.getTabPrimaryColor
import io.getstream.whatsappclone.navigation.AppComposeNavigator
import io.getstream.whatsappclone.navigation.TOP_LEVEL_DESTINATIONS
import io.getstream.whatsappclone.navigation.WhatsAppPage
import io.getstream.whatsappclone.navigation.WhatsAppPagerContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun WhatsAppCalls(
@Composable
private fun WhatsAppCallsScreen(
whatsAppUsersUiState: WhatsAppUserUiState,
onHistoryItemClick: (WhatsAppUser) -> Unit,
onHistoryItemClick: (WhatsAppUser) -> Unit
) {
when (whatsAppUsersUiState) {
WhatsAppUserUiState.Loading -> WhatsAppLoadingColumn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import io.getstream.whatsappclone.navigation.AppComposeNavigator
import io.getstream.whatsappclone.navigation.WhatsAppScreens
import io.getstream.whatsappclone.uistate.WhatsAppUserExtensive
import io.getstream.whatsappclone.uistate.WhatsAppUserUiState
import javax.inject.Inject
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class WhatsAppCallsViewModel @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import io.getstream.whatsappclone.model.WhatsAppUser
import io.getstream.whatsappclone.navigation.AppComposeNavigator

@Composable
fun WhatsAppCallHistoryInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.hilt.navigation.compose.hiltViewModel
import com.skydoves.landscapist.glide.GlideImage
import io.getstream.whatsappclone.designsystem.R
import io.getstream.whatsappclone.designsystem.icon.WhatsAppIcons
Expand All @@ -41,7 +40,7 @@ import java.util.Date
@Composable
fun WhatsAppCallHistoryInfoBody(
modifier: Modifier,
whatsAppUser: WhatsAppUser,
whatsAppUser: WhatsAppUser

) {
ConstraintLayout(modifier = modifier.padding(12.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import androidx.compose.ui.unit.dp
import io.getstream.whatsappclone.calls.R
import io.getstream.whatsappclone.designsystem.icon.WhatsAppIcons
import io.getstream.whatsappclone.designsystem.theme.WhatsAppCloneComposeTheme
import io.getstream.whatsappclone.navigation.AppComposeNavigator
import io.getstream.whatsappclone.navigation.WhatsAppCloneComposeNavigator

@Composable
fun WhatsAppCallHistoryTopBar(
Expand All @@ -44,10 +42,10 @@ fun WhatsAppCallHistoryTopBar(
navigationIcon = {
Icon(
modifier = Modifier
.size(26.dp)
.clickable {
onBackClick()
},
.size(26.dp)
.clickable {
onBackClick()
},
imageVector = WhatsAppIcons.ArrowBack,
tint = MaterialTheme.colorScheme.tertiary,
contentDescription = null
Expand Down Expand Up @@ -93,7 +91,8 @@ private fun WhatsAppCallHistoryTopBarPreview() {
@Composable
private fun WhatsAppCallHistoryTopBarDarkPreview() {
WhatsAppCloneComposeTheme(darkTheme = true) {
WhatsAppCallHistoryTopBar(onBackClick = {}
WhatsAppCallHistoryTopBar(
onBackClick = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2023 Stream.IO, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.whatsappclone.calls.info

import androidx.lifecycle.ViewModel
Expand All @@ -10,7 +26,6 @@ class WhatsAppCallHistoryViewModel @Inject constructor(
private val composeNavigator: AppComposeNavigator
) : ViewModel() {


fun navigateUp() {
composeNavigator.navigateUp()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2023 Stream.IO, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.whatsappclone.chats.channels

import androidx.lifecycle.ViewModel
Expand All @@ -8,13 +24,10 @@ import javax.inject.Inject

@HiltViewModel
class WhatsChannelsViewModel @Inject constructor(
private val composeNavigator: AppComposeNavigator,
private val composeNavigator: AppComposeNavigator
) : ViewModel() {


fun navigateToMessages(channelId: String) {
composeNavigator.navigate(WhatsAppScreens.Messages.createRoute(channelId))
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ fun WhatsAppMessageTopBar(
messageUiState: WhatsAppMessageUiState,
onBackClick: () -> Unit
) {


SmallTopAppBar(
modifier = Modifier.fillMaxWidth(),
navigationIcon = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ import io.getstream.whatsappclone.chats.theme.WhatsAppChatTheme

@Composable
fun WhatsAppMessages(
channelId: String, whatsAppMessagesViewModel: WhatsAppMessagesViewModel = hiltViewModel()
channelId: String,
whatsAppMessagesViewModel: WhatsAppMessagesViewModel = hiltViewModel()
) {
val messageUiState by whatsAppMessagesViewModel.messageUiSate.collectAsStateWithLifecycle()

WhatsAppChatTheme {
Column(Modifier.fillMaxSize()) {
WhatsAppMessageTopBar(messageUiState = messageUiState,
onBackClick = { whatsAppMessagesViewModel.handleEvents(WhatsAppMessageEvent.NavigateUp) })
WhatsAppMessageTopBar(
messageUiState = messageUiState,
onBackClick = { whatsAppMessagesViewModel.handleEvents(WhatsAppMessageEvent.NavigateUp) }
)

MessagesScreen(channelId = channelId,
MessagesScreen(
channelId = channelId,
showHeader = false,
onBackPressed = { whatsAppMessagesViewModel.handleEvents(WhatsAppMessageEvent.NavigateUp) })
onBackPressed = { whatsAppMessagesViewModel.handleEvents(WhatsAppMessageEvent.NavigateUp) }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class WhatsAppMessagesViewModel @Inject constructor(
}
}
}


}

sealed interface WhatsAppMessageEvent {
Expand Down

0 comments on commit 11c6494

Please sign in to comment.