Skip to content

Commit

Permalink
feat: 바텀 네비게이션 visibility 설정, 툴바 네비게이션 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
juyoung0520 committed Nov 15, 2022
1 parent 54c7a5e commit 81be25e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
39 changes: 35 additions & 4 deletions presentation/src/main/java/com/gta/presentation/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
package com.gta.presentation.ui

import android.os.Bundle
import android.view.View
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.gta.presentation.R
import com.gta.presentation.databinding.ActivityMainBinding
import com.gta.presentation.ui.base.BaseActivity

class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::inflate) {
private val navHostFragment by lazy { supportFragmentManager.findFragmentById(R.id.fcv_main) as NavHostFragment }
private val navController by lazy { navHostFragment.navController }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fcv_home_fragment) as NavHostFragment
val navController = navHostFragment.navController
binding.bnvHomeBottomNav.setupWithNavController(navController)

setSupportActionBar(binding.tbMain)

setupWithBottomNavigation()

setupWithAppBar()
}

private fun setupWithAppBar() {
val appBarConfiguration = AppBarConfiguration(setOf(R.id.mapFragment, R.id.chattingFragment, R.id.myPageFragment))
setupActionBarWithNavController(navController, appBarConfiguration)
}

private fun setupWithBottomNavigation() {
binding.bnvMain.setupWithNavController(navController)

navController.addOnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
R.id.mapFragment, R.id.chattingFragment, R.id.myPageFragment -> showBottomNav()
else -> hideBottomNav()
}
}
}

private fun showBottomNav() {
binding.bnvMain.visibility = View.VISIBLE
}

private fun hideBottomNav() {
binding.bnvMain.visibility = View.GONE
}
}
14 changes: 10 additions & 4 deletions presentation/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
android:layout_height="match_parent"
tools:context=".ui.MainActivity">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/tb_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv_home_fragment"
android:id="@+id/fcv_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/bnv_home_bottom_nav"
app:layout_constraintBottom_toTopOf="@id/bnv_main"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/tb_main"
app:navGraph="@navigation/nav_main" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_home_bottom_nav"
android:id="@+id/bnv_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
6 changes: 3 additions & 3 deletions presentation/src/main/res/navigation/nav_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
<fragment
android:id="@+id/mapFragment"
android:name="com.gta.presentation.ui.map.MapFragment"
android:label="fragment_map"
android:label="@string/my_near"
tools:layout="@layout/fragment_map" />

<fragment
android:id="@+id/chattingFragment"
android:name="com.gta.presentation.ui.chatting.ChattingFragment"
android:label="fragment_chatting"
android:label="@string/chatting"
tools:layout="@layout/fragment_chatting" />

<fragment
android:id="@+id/myPageFragment"
android:name="com.gta.presentation.ui.mypage.MyPageFragment"
android:label="fragment_mypage"
android:label="@string/my_page"
tools:layout="@layout/fragment_mypage" />

</navigation>
2 changes: 1 addition & 1 deletion presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<string name="app_name">니차내차</string>
<string name="my_near">내주변</string>
<string name="my_near">내 주변</string>
<string name="chatting">채팅</string>
<string name="my_page">마이페이지</string>
</resources>

0 comments on commit 81be25e

Please sign in to comment.