Skip to content

Commit

Permalink
[feat] mash-up-kr#111 HomeRoute 연결 및 기존 XML HomeFragment 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
JaesungLeee committed Jul 9, 2023
1 parent fd333a1 commit adc4a7c
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 74 deletions.
6 changes: 6 additions & 0 deletions buildSrc/src/main/java/dependencies/Dep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -19,42 +25,51 @@ import dagger.hilt.android.AndroidEntryPoint
* @created 2023/06/03
*/
@AndroidEntryPoint
class HomeActivity : BaseActivity<ActivityHomeBinding>(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<ActivityHomeBinding>(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)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<SignalUiModel>()

Expand Down Expand Up @@ -288,5 +298,8 @@ private fun SignalCardKeywordsChip(keyword: String) {
@Preview
@Composable
fun PreviewHomeScreen() {
HomeScreen()
HomeScreen(
navigateToSubscribeKeyword = {},
navigateToGuide = {}
)
}
Original file line number Diff line number Diff line change
@@ -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() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -18,15 +20,19 @@ 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(
navController = navController,
startDestination = startDestination,
modifier = modifier
) {
homeGraph(navController = navController)
homeGraph(
onSubscribeKeywordClick = navController::navigateToSubscribeKeywordRoute,
onGuideClick = navController::navigateToGuideRoute,
onClickBack = navController::navigateUp
)
signalGraph()
chatGraph() {

Expand Down

0 comments on commit adc4a7c

Please sign in to comment.