From adc4a7cb7cb28ee3cbbd1e5da499a61a0513d26b Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sun, 9 Jul 2023 17:28:51 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#111=20HomeRoute=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=20=EB=B0=8F=20=EA=B8=B0=EC=A1=B4=20XML=20HomeFragment=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/src/main/java/dependencies/Dep.kt | 6 ++ presentation/build.gradle | 4 +- .../presentation/feature/home/HomeActivity.kt | 85 +++++++++++-------- .../presentation/feature/home/HomeFragment.kt | 24 ------ .../presentation/feature/home/HomeScreen.kt | 33 ++++--- .../feature/home/HomeViewModel.kt | 14 +++ .../feature/home/navigation/HomeNavigation.kt | 11 ++- .../presentation/navigation/KeyLinkNavHost.kt | 10 ++- 8 files changed, 113 insertions(+), 74 deletions(-) delete mode 100644 presentation/src/main/java/com/mashup/presentation/feature/home/HomeFragment.kt create mode 100644 presentation/src/main/java/com/mashup/presentation/feature/home/HomeViewModel.kt diff --git a/buildSrc/src/main/java/dependencies/Dep.kt b/buildSrc/src/main/java/dependencies/Dep.kt index bcf32a5c9..d626d032a 100644 --- a/buildSrc/src/main/java/dependencies/Dep.kt +++ b/buildSrc/src/main/java/dependencies/Dep.kt @@ -22,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" @@ -43,6 +44,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 { diff --git a/presentation/build.gradle b/presentation/build.gradle index cf35ee7d6..cff2d3f69 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -56,10 +56,12 @@ dependencies { // lifecycle implementation Dep.AndroidX.Lifecycle.viewModel implementation Dep.AndroidX.Lifecycle.savedState + 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 diff --git a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeActivity.kt b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeActivity.kt index 5dc88a8e9..560323dcd 100644 --- a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeActivity.kt +++ b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeActivity.kt @@ -1,16 +1,22 @@ package com.mashup.presentation.feature.home +import android.os.Bundle import android.view.LayoutInflater import android.view.View +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController import com.google.android.material.bottomnavigation.BottomNavigationItemView import com.google.android.material.bottomnavigation.BottomNavigationMenuView +import com.mashup.presentation.KeyLinkApp import com.mashup.presentation.R import com.mashup.presentation.common.base.BaseActivity import com.mashup.presentation.common.extension.addBadge import com.mashup.presentation.common.extension.removeBadge +import com.mashup.presentation.common.extension.setThemeContent import com.mashup.presentation.databinding.ActivityHomeBinding +import com.mashup.presentation.ui.theme.SsamDTheme import dagger.hilt.android.AndroidEntryPoint /** @@ -19,42 +25,51 @@ import dagger.hilt.android.AndroidEntryPoint * @created 2023/06/03 */ @AndroidEntryPoint -class HomeActivity : BaseActivity(R.layout.activity_home) { - private val navHostFragment by lazy { - supportFragmentManager.findFragmentById(binding.fcvHome.id) as NavHostFragment - } - private val navController by lazy { navHostFragment.navController } - - override fun initViews() { - initBottomNavigationView() - initDestinationChangeListener() - } +//class HomeActivity : BaseActivity(R.layout.activity_home) { +// private val navHostFragment by lazy { +// supportFragmentManager.findFragmentById(binding.fcvHome.id) as NavHostFragment +// } +// private val navController by lazy { navHostFragment.navController } +// +// override fun initViews() { +// initBottomNavigationView() +// initDestinationChangeListener() +// } +// +// private fun initBottomNavigationView() { +// binding.bnvHome.setupWithNavController(navController) +// addSignalIconItemView() +// binding.bnvHome.addBadge(this, 1000) +// } +// +// private fun initDestinationChangeListener() { +// navController.addOnDestinationChangedListener { _, destination, _ -> +// binding.bnvHome.visibility = when (destination.id) { +// /* 디자인 명세에 따라 수정 */ +// R.id.homeFragment -> View.VISIBLE +// R.id.chatFragment -> { +// binding.bnvHome.removeBadge() +// View.VISIBLE +// } +// else -> View.GONE +// } +// } +// } +// +// private fun addSignalIconItemView() { +// val navigationMenuView = binding.bnvHome.getChildAt(0) as BottomNavigationMenuView +// val navigationItemView = navigationMenuView.getChildAt(1) as BottomNavigationItemView +// val signalItemView = LayoutInflater.from(this) +// .inflate(R.layout.menu_bottom_navigation_signal, binding.bnvHome, false) +// navigationItemView.addView(signalItemView) +// } +//} +class HomeActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - private fun initBottomNavigationView() { - binding.bnvHome.setupWithNavController(navController) - addSignalIconItemView() - binding.bnvHome.addBadge(this, 1000) - } - - private fun initDestinationChangeListener() { - navController.addOnDestinationChangedListener { _, destination, _ -> - binding.bnvHome.visibility = when (destination.id) { - /* 디자인 명세에 따라 수정 */ - R.id.homeFragment -> View.VISIBLE - R.id.chatFragment -> { - binding.bnvHome.removeBadge() - View.VISIBLE - } - else -> View.GONE - } + setThemeContent { + KeyLinkApp() } } - - private fun addSignalIconItemView() { - val navigationMenuView = binding.bnvHome.getChildAt(0) as BottomNavigationMenuView - val navigationItemView = navigationMenuView.getChildAt(1) as BottomNavigationItemView - val signalItemView = LayoutInflater.from(this) - .inflate(R.layout.menu_bottom_navigation_signal, binding.bnvHome, false) - navigationItemView.addView(signalItemView) - } } \ No newline at end of file diff --git a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeFragment.kt b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeFragment.kt deleted file mode 100644 index c6a0c65e9..000000000 --- a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeFragment.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.mashup.presentation.feature.home - -import com.mashup.presentation.R -import com.mashup.presentation.common.base.BaseFragment -import com.mashup.presentation.common.extension.navigate -import com.mashup.presentation.common.extension.setThemeContent -import com.mashup.presentation.databinding.FragmentHomeBinding - -/** - * Ssam_D_Android - * @author jaesung - * @created 2023/06/04 - */ -class HomeFragment : BaseFragment(R.layout.fragment_home) { - - override fun initViews() { - binding.composeView.setThemeContent { - HomeScreen( - navigateToSubscribeKeyword = { navigate(R.id.action_home_to_subscribeKeyword)}, - navigateToGuide = {navigate(R.id.action_homeFragment_to_guideFragment)} - ) - } - } -} \ No newline at end of file diff --git a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeScreen.kt b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeScreen.kt index ecae9d1aa..ab9e51552 100644 --- a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeScreen.kt +++ b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeScreen.kt @@ -13,31 +13,41 @@ import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.* -import androidx.compose.ui.geometry.CornerRadius -import androidx.compose.ui.geometry.RoundRect -import androidx.compose.ui.graphics.* -import androidx.compose.ui.graphics.drawscope.drawIntoCanvas +import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel import com.mashup.presentation.R import com.mashup.presentation.common.extension.drawColoredShadow import com.mashup.presentation.common.extension.pxToDp import com.mashup.presentation.feature.home.model.SignalUiModel import com.mashup.presentation.ui.common.KeyLinkRoundButton import com.mashup.presentation.ui.theme.* -import java.util.concurrent.TimeUnit + +@Composable +fun HomeRoute( + onSubscribeKeywordClick: () -> Unit, + onGuideClick: () -> Unit, + modifier: Modifier = Modifier, + homeViewModel: HomeViewModel = hiltViewModel() +) { + HomeScreen( + navigateToSubscribeKeyword = onSubscribeKeywordClick, + navigateToGuide = onGuideClick, + modifier = modifier, + ) +} @Composable fun HomeScreen( - navigateToSubscribeKeyword: () -> Unit = {}, - navigateToGuide: () -> Unit = {} + navigateToSubscribeKeyword: () -> Unit, + navigateToGuide: () -> Unit, + modifier: Modifier = Modifier ) { val signals = emptyList() @@ -288,5 +298,8 @@ private fun SignalCardKeywordsChip(keyword: String) { @Preview @Composable fun PreviewHomeScreen() { - HomeScreen() + HomeScreen( + navigateToSubscribeKeyword = {}, + navigateToGuide = {} + ) } \ No newline at end of file diff --git a/presentation/src/main/java/com/mashup/presentation/feature/home/HomeViewModel.kt b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeViewModel.kt new file mode 100644 index 000000000..430b99382 --- /dev/null +++ b/presentation/src/main/java/com/mashup/presentation/feature/home/HomeViewModel.kt @@ -0,0 +1,14 @@ +package com.mashup.presentation.feature.home + +import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +/** + * Ssam_D_Android + * @author jaesung + * @created 2023/07/07 + */ +@HiltViewModel +class HomeViewModel @Inject constructor() : ViewModel() { +} \ No newline at end of file diff --git a/presentation/src/main/java/com/mashup/presentation/feature/home/navigation/HomeNavigation.kt b/presentation/src/main/java/com/mashup/presentation/feature/home/navigation/HomeNavigation.kt index 4720b969b..340a030b4 100644 --- a/presentation/src/main/java/com/mashup/presentation/feature/home/navigation/HomeNavigation.kt +++ b/presentation/src/main/java/com/mashup/presentation/feature/home/navigation/HomeNavigation.kt @@ -5,6 +5,8 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable import androidx.navigation.compose.navigation +import com.mashup.presentation.feature.home.HomeRoute +import com.mashup.presentation.feature.home.guide.GuideRoute import com.mashup.presentation.navigation.KeyLinkNavigationRoute /** @@ -34,14 +36,19 @@ fun NavController.navigateToProfileRoute(navOptions: NavOptions? = null) { } fun NavGraphBuilder.homeGraph( - navController: NavController + onSubscribeKeywordClick: () -> Unit, + onGuideClick: () -> Unit, + onClickBack: () -> Unit, ) { navigation( route = KeyLinkNavigationRoute.HomeGraph.route, startDestination = KeyLinkNavigationRoute.HomeGraph.HomeRoute.route ) { composable(route = KeyLinkNavigationRoute.HomeGraph.HomeRoute.route) { - // HomeRoute + HomeRoute( + onSubscribeKeywordClick = onSubscribeKeywordClick, + onGuideClick = onGuideClick, + ) } composable(route = KeyLinkNavigationRoute.HomeGraph.GuideRoute.route) { // GuideRoute diff --git a/presentation/src/main/java/com/mashup/presentation/navigation/KeyLinkNavHost.kt b/presentation/src/main/java/com/mashup/presentation/navigation/KeyLinkNavHost.kt index e6d5fc105..ebce18068 100644 --- a/presentation/src/main/java/com/mashup/presentation/navigation/KeyLinkNavHost.kt +++ b/presentation/src/main/java/com/mashup/presentation/navigation/KeyLinkNavHost.kt @@ -6,6 +6,8 @@ import androidx.navigation.compose.NavHost import com.mashup.presentation.KeyLinkAppState import com.mashup.presentation.feature.chat.navigation.chatGraph import com.mashup.presentation.feature.home.navigation.homeGraph +import com.mashup.presentation.feature.home.navigation.navigateToGuideRoute +import com.mashup.presentation.feature.home.navigation.navigateToSubscribeKeywordRoute import com.mashup.presentation.feature.signal.navigation.signalGraph /** @@ -18,7 +20,7 @@ fun KeyLinkNavHost( appState: KeyLinkAppState, onShowSnackbar: suspend (String, String?) -> Boolean, modifier: Modifier = Modifier, - startDestination: String = KeyLinkNavigationRoute.HomeGraph.HomeRoute.route + startDestination: String = KeyLinkNavigationRoute.HomeGraph.route ) { val navController = appState.navController NavHost( @@ -26,7 +28,11 @@ fun KeyLinkNavHost( startDestination = startDestination, modifier = modifier ) { - homeGraph(navController = navController) + homeGraph( + onSubscribeKeywordClick = navController::navigateToSubscribeKeywordRoute, + onGuideClick = navController::navigateToGuideRoute, + onClickBack = navController::navigateUp + ) signalGraph() chatGraph() {