Skip to content

Commit

Permalink
[feat] mash-up-kr#111 BottomBar에 채팅 Graph 연결 및 Multiple BackStack 유지
Browse files Browse the repository at this point in the history
  • Loading branch information
JaesungLeee committed Jul 10, 2023
1 parent abbde12 commit eb33bda
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.mashup.presentation.feature.chat.navigation.navigateToChat
import com.mashup.presentation.feature.home.navigation.navigateToHome
import com.mashup.presentation.feature.signal.navigation.navigateToSignal
import com.mashup.presentation.navigation.KeyLinkNavigationRoute
Expand Down Expand Up @@ -70,7 +71,7 @@ class KeyLinkAppState(
when (topLevelDestination) {
TopLevelDestination.HOME -> navController.navigateToHome(topLevelNavOptions)
TopLevelDestination.SIGNAL -> navController.navigateToSignal(topLevelNavOptions)
else -> {}
TopLevelDestination.CHAT -> navController.navigateToChat(topLevelNavOptions)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mashup.presentation.feature.chat

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/07/09
*/
@HiltViewModel
class ChatViewModel @Inject constructor() : ViewModel() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,38 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.mashup.presentation.R
import com.mashup.presentation.feature.chat.ChatViewModel
import com.mashup.presentation.ui.theme.*

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/06/27
*/
@Composable
fun ChatRoute(
onEmptyScreenButtonClick: () -> Unit,
onChatClick: () -> Unit,
modifier: Modifier = Modifier,
viewModel: ChatViewModel = hiltViewModel()
) {
ChatScreen(
modifier = modifier,
onEmptyScreenButtonClick = onEmptyScreenButtonClick,
onChatClick = onChatClick
)
}

@Composable
fun ChatScreen(
navigateToSendSignal: () -> Unit = {},
navigateToChatDetail: () -> Unit = {}
onEmptyScreenButtonClick: () -> Unit,
onChatClick: () -> Unit,
modifier: Modifier = Modifier
) {
Scaffold(
modifier = Modifier,
modifier = modifier,
backgroundColor = Black,
topBar = {
Column {
Expand All @@ -51,8 +68,8 @@ fun ChatScreen(
) { paddingValues ->
ChatContent(
isConnected = true,
navigateToSendSignal = { navigateToSendSignal() },
navigateToChatDetail = { navigateToChatDetail() },
onEmptyScreenButtonClick = onEmptyScreenButtonClick,
onChatClick = onChatClick,
modifier = Modifier.padding(paddingValues)
)
}
Expand All @@ -61,18 +78,18 @@ fun ChatScreen(
@Composable
fun ChatContent(
isConnected: Boolean,
navigateToSendSignal: () -> Unit,
navigateToChatDetail: () -> Unit,
onEmptyScreenButtonClick: () -> Unit,
onChatClick: () -> Unit,
modifier: Modifier = Modifier
) {
if (!isConnected) {
EmptyChatScreen(
onButtonClick = { navigateToSendSignal() },
onButtonClick = onEmptyScreenButtonClick,
modifier = modifier.fillMaxSize(),
)
} else {
ChatListScreen(
onMessageClick = { navigateToChatDetail() },
onMessageClick = onChatClick,
modifier = modifier
.fillMaxSize()
.padding(top = 8.dp)
Expand All @@ -84,7 +101,10 @@ fun ChatContent(
@Composable
private fun ChatScreenPreview() {
SsamDTheme(darkTheme = true) {
ChatScreen()
ChatScreen(
onEmptyScreenButtonClick = {},
onChatClick = {}
)
}
}

Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
package com.mashup.presentation.feature.chat.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.mashup.presentation.feature.chat.compose.ChatRoute
import com.mashup.presentation.navigation.KeyLinkNavigationRoute

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/07/04
*/
fun NavController.navigateToChat(navOptions: NavOptions? = null) {
navigate(
route = KeyLinkNavigationRoute.ChatGraph.ChatRoute.route,
navOptions = navOptions
)
}

fun NavGraphBuilder.chatGraph(
nestedGraphs: NavGraphBuilder.() -> Unit,
nestedGraphs: NavGraphBuilder.() -> Unit = {},
onChatClick: () -> Unit,
onMessageClick: () -> Unit
) {
navigation(
route = KeyLinkNavigationRoute.ChatGraph.route,
startDestination = KeyLinkNavigationRoute.ChatGraph.ChatRoute.route
) {
composable(route = KeyLinkNavigationRoute.ChatGraph.ChatRoute.route,) {
// ChatRoute
composable(route = KeyLinkNavigationRoute.ChatGraph.ChatRoute.route) {
ChatRoute(
onEmptyScreenButtonClick = {},
onChatClick = onChatClick
)
}

composable(route = KeyLinkNavigationRoute.ChatGraph.ChatDetailRoute.route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ fun KeyLinkNavHost(
navController = navController,
onBackClick = navController::navigateUp,
)
chatGraph() {

}
chatGraph(
onChatClick = {},
onMessageClick = {}
)
}
}
9 changes: 0 additions & 9 deletions presentation/src/main/res/layout/fragment_chat.xml

This file was deleted.

1 change: 0 additions & 1 deletion presentation/src/main/res/navigation/graph_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
android:id="@+id/action_chat_to_chatDetail"
app:destination="@id/chatDetailFragment" />
</fragment>
<include app:graph="@navigation/graph_signal" />
<fragment
android:id="@+id/chatDetailFragment"
android:name="com.mashup.presentation.feature.detail.chat.ChatDetailFragment"
Expand Down

0 comments on commit eb33bda

Please sign in to comment.