Skip to content

Commit

Permalink
[MIN-61] refactor : 네비게이션 액션바 메뉴 사라짐 이슈 수정 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDW03 committed Mar 29, 2023
1 parent 1f65d9e commit 8a1470a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
34 changes: 20 additions & 14 deletions app/src/main/java/com/najudoryeong/mineme/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
Expand All @@ -14,19 +13,19 @@ import androidx.navigation.ui.setupWithNavController
import com.najudoryeong.mineme.common_ui.MainActivityUtil
import com.najudoryeong.mineme.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import com.najudoryeong.mineme.home.ui.HomeFragment
import com.najudoryeong.mineme.setting.fragment.ui.SettingFragment
import com.najudoryeong.mineme.story.ui.StoryFragment
import com.najudoryeong.mineme.home.R.navigation.nav_home
import com.najudoryeong.mineme.story.R.navigation.nav_story
import com.najudoryeong.mineme.setting.R.navigation.nav_setting


// 하위 모듈이 MainViewModel 코드에 접근할 수 있게 MainViewModelUtil 상속 구현
@AndroidEntryPoint
class MainActivity : AppCompatActivity(), MainActivityUtil {

private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController
private val mainViewModel: MainViewModel by viewModels()
private lateinit var appBarConfiguration: AppBarConfiguration


override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -46,22 +45,29 @@ class MainActivity : AppCompatActivity(), MainActivityUtil {
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragment_containerView) as NavHostFragment
navController = navHostFragment.navController

// appbar 구성 요소 설정
// 바텀네비게이션과 연결하면 해당 프래그먼트에 네비게이션으로는 backButton x
appBarConfiguration = AppBarConfiguration(
setOf(R.id.nav_home, com.najudoryeong.mineme.story.R.id.storyFragment, R.id.nav_setting)
val inflater = navController.navInflater
val configuration = AppBarConfiguration(
setOf(
com.najudoryeong.mineme.home.R.id.homeFragment,
com.najudoryeong.mineme.setting.R.id.settingFragment
)
)
NavigationUI.setupActionBarWithNavController(this, navController,configuration)

// navController 와 actionbar 연결
// NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
NavigationUI.setupActionBarWithNavController(this, navController)
binding.bottomNavigationView.run {
setupWithNavController(navController)
itemIconTintList = null
}
}

binding.bottomNavigationView.setOnItemSelectedListener {
navHostFragment.navController.graph = when (it.itemId) {
R.id.nav_home -> inflater.inflate(nav_home)
R.id.nav_story -> inflater.inflate(nav_story)
else -> inflater.inflate(nav_setting)
}
true
}
}

private fun initAppBar() {
setSupportActionBar(binding.toolbar)
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@

</com.google.android.material.appbar.AppBarLayout>


<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_containerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_main" />

</LinearLayout>


Expand All @@ -56,6 +54,7 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:elevation="9dp">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/nav_story"
android:icon="@drawable/bottom_story_on_off"
android:title="" />

<item
android:id="@+id/nav_setting"
android:icon="@drawable/bottom_setting_on_off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class StoryFragment : BaseFragment<FragmentStoryBinding>(StoryFoundationInfo) {
private var nowView: Int = 0

override fun initView() {

(activity as AppCompatActivity).run {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.img_story_menu)
}

Expand All @@ -42,7 +42,6 @@ class StoryFragment : BaseFragment<FragmentStoryBinding>(StoryFoundationInfo) {
this.lifecycleOwner = viewLifecycleOwner
this.adapter = storyOutAdapter
this.viewModel = storyViewModel

this.swiperefreshlayout.setOnRefreshListener {
storyViewModel.raedStory {
swiperefreshlayout.isRefreshing = false
Expand Down

0 comments on commit 8a1470a

Please sign in to comment.