-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from JaesungLeee/feature/navigation-migration
#111 Home μ§μ μ΄ν νλ‘μ° Compose Navigation λ§μ΄κ·Έλ μ΄μ μμ
- Loading branch information
Showing
115 changed files
with
1,301 additions
and
869 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
presentation/src/main/java/com/mashup/presentation/KeyLinkApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.mashup.presentation | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.SnackbarDuration | ||
import androidx.compose.material.SnackbarHostState | ||
import androidx.compose.material.SnackbarResult | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import com.mashup.presentation.navigation.KeyLinkNavHost | ||
import com.mashup.presentation.ui.common.KeyLinkBottomBar | ||
import com.mashup.presentation.ui.common.KeyLinkSnackBar | ||
import com.mashup.presentation.ui.theme.Black | ||
|
||
/** | ||
* Ssam_D_Android | ||
* @author jaesung | ||
* @created 2023/07/04 | ||
*/ | ||
@Composable | ||
fun KeyLinkApp( | ||
appState: KeyLinkAppState = rememberKeyLinkAppState() | ||
) { | ||
val snackbarHostState = remember { SnackbarHostState() } | ||
|
||
Scaffold( | ||
bottomBar = { | ||
if (appState.isBottomBarVisible()) { | ||
KeyLinkBottomBar( | ||
destinations = appState.topLevelDestinations, | ||
onNavigateToDestination = appState::navigateToTopLevelDestination, | ||
currentDestination = appState.currentDestination, | ||
modifier = Modifier | ||
) | ||
} | ||
}, | ||
backgroundColor = Black, | ||
snackbarHost = { KeyLinkSnackBar(snackBarHostState = snackbarHostState) } | ||
) { innerPadding -> | ||
KeyLinkNavHost( | ||
appState = appState, | ||
modifier = Modifier.padding(innerPadding), | ||
onShowSnackbar = { message, action -> | ||
snackbarHostState.showSnackbar( | ||
message = message, | ||
actionLabel = action, | ||
duration = SnackbarDuration.Short | ||
) == SnackbarResult.ActionPerformed | ||
} | ||
) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
presentation/src/main/java/com/mashup/presentation/KeyLinkAppState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.mashup.presentation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.runtime.remember | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavGraph.Companion.findStartDestination | ||
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 | ||
import com.mashup.presentation.navigation.TopLevelDestination | ||
|
||
/** | ||
* Ssam_D_Android | ||
* @author jaesung | ||
* @created 2023/07/04 | ||
*/ | ||
|
||
@Composable | ||
fun rememberKeyLinkAppState( | ||
navController: NavHostController = rememberNavController() | ||
): KeyLinkAppState { | ||
return remember(navController) { | ||
KeyLinkAppState(navController) | ||
} | ||
} | ||
|
||
/** | ||
* KeyLinkAppStateμλ μ λ°μ μΈ μ΄ν리μΌμ΄μ μ체μ μνκ° ν¬ν¨λ©λλ€. | ||
* 1. Navigation Destination | ||
* 2. Multiple BackStack | ||
* 3. BottomNavigation Visibility | ||
* 4. NetworkMonitor(isOffline / isOnline) | ||
* 5. ... | ||
*/ | ||
@Stable | ||
class KeyLinkAppState( | ||
val navController: NavHostController | ||
) { | ||
val currentDestination: NavDestination? | ||
@Composable get() = navController.currentBackStackEntryAsState().value?.destination | ||
|
||
val topLevelDestinations: List<TopLevelDestination> = TopLevelDestination.values().toList() | ||
|
||
@Composable | ||
fun isBottomBarVisible(): Boolean { | ||
return when (currentDestination?.route) { | ||
KeyLinkNavigationRoute.HomeGraph.HomeRoute.route, | ||
KeyLinkNavigationRoute.ChatGraph.ChatRoute.route -> true | ||
else -> false | ||
} | ||
} | ||
|
||
/** | ||
* Home, Chat Routeλ‘ λ€μ λμμμΌ νλ κ²½μ° νΈμΆνλ λ©μλ | ||
* singleTopμΌλ‘ λμ λ° backstack μ μ§ | ||
*/ | ||
fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) { | ||
val topLevelNavOptions = navOptions { | ||
popUpTo(id = navController.graph.findStartDestination().id) { | ||
saveState = true | ||
} | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
when (topLevelDestination) { | ||
TopLevelDestination.HOME -> navController.navigateToHome(topLevelNavOptions) | ||
TopLevelDestination.SIGNAL -> navController.navigateToSignal(topLevelNavOptions) | ||
TopLevelDestination.CHAT -> navController.navigateToChat(topLevelNavOptions) | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
presentation/src/main/java/com/mashup/presentation/chat/ChatFragment.kt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
presentation/src/main/java/com/mashup/presentation/detail/chat/ChatDetailFragment.kt
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
presentation/src/main/java/com/mashup/presentation/detail/message/MessageDetailFragment.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
presentation/src/main/java/com/mashup/presentation/feature/chat/ChatViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.