Skip to content

Commit

Permalink
Merge pull request #127 from JaesungLeee/feature/navigation-migration
Browse files Browse the repository at this point in the history
#111 Home μ§„μž… 이후 ν”Œλ‘œμš° Compose Navigation λ§ˆμ΄κ·Έλ ˆμ΄μ…˜ μž‘μ—…
  • Loading branch information
JaesungLeee authored Jul 11, 2023
2 parents 151b72b + 5f88a34 commit e2f757f
Show file tree
Hide file tree
Showing 115 changed files with 1,301 additions and 869 deletions.
18 changes: 16 additions & 2 deletions buildSrc/src/main/java/dependencies/Dep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ object Dep {
object AndroidX {
const val appCompat = "androidx.appcompat:appcompat:1.6.1"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:2.1.4"
const val constraintLayoutCompose = "androidx.constraintlayout:constraintlayout-compose:1.0.1"
const val constraintLayoutCompose =
"androidx.constraintlayout:constraintlayout-compose:1.0.1"

object Activity {
const val ktx = "androidx.activity:activity-ktx:1.2.3"
Expand All @@ -21,6 +22,7 @@ object Dep {
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel-ktx:$version"
const val savedState = "androidx.lifecycle:lifecycle-viewmodel-savedstate:$version"
const val runtime = "androidx.lifecycle:lifecycle-runtime-ktx:$version"
const val runtimeCompose = "androidx.lifecycle:lifecycle-runtime-compose:$version"
const val process = "androidx.lifecycle:lifecycle-process:$version"
const val livedata = "androidx.lifecycle:lifecycle-livedata-ktx:$version"
const val compiler = "androidx.lifecycle:lifecycle-compiler:$version"
Expand All @@ -43,6 +45,11 @@ object Dep {
object Core {
const val core = "androidx.core:core-ktx:1.7.0"
}

object Hilt {
const val hiltNavigation = "androidx.hilt:hilt-navigation-compose:1.0.0"
}

}

object Google {
Expand Down Expand Up @@ -123,7 +130,8 @@ object Dep {
private const val version = "4.13.2"
const val glide = "com.github.bumptech.glide:glide:$version"
const val compiler = "com.github.bumptech.glide:compiler:$version"
const val recyclerviewIntegration = "com.github.bumptech.glide:recyclerview-integration:$version"
const val recyclerviewIntegration =
"com.github.bumptech.glide:recyclerview-integration:$version"
const val okHttpIntegration = "com.github.bumptech.glide:okhttp3-integration:$version"
}

Expand Down Expand Up @@ -154,6 +162,12 @@ object Dep {
const val uiTooling = "androidx.compose.ui:ui-tooling:$version"
const val uiTestManifest = "androidx.compose.ui:ui-test-manifest:$version"
}

object Navigation {
private const val navigationVersion = "2.6.0"
const val navigationCompose =
"androidx.navigation:navigation-compose:$navigationVersion"
}
}

object Javax {
Expand Down
7 changes: 4 additions & 3 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ dependencies {
// lifecycle
implementation Dep.AndroidX.Lifecycle.viewModel
implementation Dep.AndroidX.Lifecycle.savedState
implementation Dep.AndroidX.Lifecycle.compose
implementation Dep.AndroidX.Lifecycle.runtimeCompose
kapt Dep.AndroidX.Lifecycle.compiler

// ViewModel utilities for Compose
implementation Dep.AndroidX.Lifecycle.Compose.viewModel
implementation Dep.AndroidX.Lifecycle.Compose.viewModel // μΆ”ν›„ 제거 ν•„μš”
implementation Dep.AndroidX.Hilt.hiltNavigation

// glide
implementation Dep.Glide.glide
Expand All @@ -71,7 +72,6 @@ dependencies {

// hilt
implementation Dep.Dagger.Hilt.hilt
implementation Dep.Dagger.Hilt.Compose.navigation
kapt Dep.Dagger.Hilt.compiler

// navigation
Expand All @@ -91,6 +91,7 @@ dependencies {
implementation Dep.Compose.preview
implementation Dep.Compose.material
implementation Dep.AndroidX.Activity.compose
implementation Dep.Compose.Navigation.navigationCompose
androidTestImplementation Dep.Compose.Test.ui
debugImplementation Dep.Compose.Debug.uiTooling
debugImplementation Dep.Compose.Debug.uiTestManifest
Expand Down
20 changes: 11 additions & 9 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

<application>
<activity
android:name=".home.HomeActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize" />
android:name=".navigation.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".onboarding.OnBoardingActivity"
android:name=".feature.onboarding.OnBoardingActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize" />

<activity
android:name=".login.LoginActivity"
android:name=".feature.login.LoginActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<activity
Expand Down
53 changes: 53 additions & 0 deletions presentation/src/main/java/com/mashup/presentation/KeyLinkApp.kt
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
}
)
}
}
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)
}
}
}

This file was deleted.

This file was deleted.

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
@@ -1,4 +1,4 @@
package com.mashup.presentation.chat.compose
package com.mashup.presentation.feature.chat.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -21,7 +21,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.mashup.presentation.R
import com.mashup.presentation.chat.model.Message
import com.mashup.presentation.feature.chat.model.Message
import com.mashup.presentation.ui.theme.*

/**
Expand Down
Loading

0 comments on commit e2f757f

Please sign in to comment.