Skip to content

Commit

Permalink
[feat] #93 프래그먼트 이동시, 바텀네비게이션 아이콘 동기화
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook123 committed Aug 1, 2023
1 parent fd74b5f commit 84761a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class AuthInterceptor @Inject constructor(

companion object {
private const val HEADER_TOKEN = "userId"
const val USER_ID = "24"
const val USER_ID = "1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main

navigateTo<WineyFeedFragment>()
initBnvItemSelectedListener()
syncBottomNavigationSelection()
}

private fun initBnvItemSelectedListener() {
Expand All @@ -35,7 +36,23 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}
}

private inline fun <reified T : Fragment> navigateTo() {
fun syncBottomNavigationSelection() {
supportFragmentManager.addOnBackStackChangedListener {
syncBottomNavigation()
}
}

fun syncBottomNavigation() {
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_main)
when (currentFragment) {
is WineyFeedFragment -> binding.bnvMain.selectedItemId = R.id.menu_feed
is RecommendFragment -> binding.bnvMain.selectedItemId = R.id.menu_recommend
is MyPageFragment -> binding.bnvMain.selectedItemId = R.id.menu_mypage
// 다른 프래그먼트도 추가가능
}
}

inline fun <reified T : Fragment> navigateTo() {
supportFragmentManager.commit {
replace<T>(R.id.fcv_main, T::class.simpleName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import com.android.go.sopt.winey.R
import com.android.go.sopt.winey.databinding.FragmentWineyfeedNoGoalDialogBinding
import com.android.go.sopt.winey.presentation.main.mypage.MyPageFragment
import com.android.go.sopt.winey.util.binding.BindingDialogFragment
import com.google.android.material.bottomnavigation.BottomNavigationView

class WineyFeedDialogFragment :
BindingDialogFragment<FragmentWineyfeedNoGoalDialogBinding>(R.layout.fragment_wineyfeed_no_goal_dialog) {
private lateinit var bottomNav: BottomNavigationView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initButtonClickListener()
Expand All @@ -29,6 +31,8 @@ class WineyFeedDialogFragment :
parentFragmentManager.commit {
replace(R.id.fcv_main, MyPageFragment())
}
bottomNav = requireActivity().findViewById(R.id.bnv_main)
bottomNav.selectedItemId = R.id.menu_mypage
}

companion object {
Expand Down

0 comments on commit 84761a6

Please sign in to comment.