Skip to content

Commit

Permalink
[FIX/#46] bottom navigation 클릭 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Jan 13, 2023
1 parent 6f00ac9 commit ac8999c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 46 deletions.
50 changes: 4 additions & 46 deletions app/src/main/java/com/keyneez/presentation/main/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.keyneez.presentation.main

import android.os.Bundle
import android.widget.ImageView
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
Expand All @@ -11,24 +10,24 @@ import com.keyneez.presentation.main.home.HomeFragment
import com.keyneez.presentation.main.id.IdFragment
import com.keyneez.presentation.main.like.LikeFragment
import com.keyneez.presentation.main.setting.SettingFragment
import com.keyneez.util.UiState
import com.keyneez.util.binding.BindingActivity
import com.keyneez.util.extension.setOnSingleClickListener
import com.keyneez.util.extension.showSnackbar
import com.lab.keyneez.R
import com.lab.keyneez.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val viewModel by viewModels<MainViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = viewModel

initBottomNavigationBar()
observeIdStateMessage()
initCardBackGround()
}

private fun initBottomNavigationBar() {
// 초기 프래그먼트 설정
val currentFragment = supportFragmentManager.findFragmentById(R.id.container_main)
Expand All @@ -42,51 +41,13 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
R.id.menu_character -> navigateTo<CharacterFragment>()
R.id.menu_setting -> navigateTo<SettingFragment>()
}
false
}
}

private fun observeIdStateMessage() {
viewModel.stateMessage.observe(this) {
when (it) {
is UiState.Success -> return@observe
is UiState.Failure -> showSnackbar(
binding.root,
getString(R.string.msg_id_null)
)
is UiState.Error -> showSnackbar(
binding.root,
getString(R.string.msg_server_error)
)
}
true
}
}

private fun initCardBackGround() {
binding.btnMainCard.setOnSingleClickListener {
navigateTo<IdFragment>()
when (viewModel.userData.value?.userCharacter?.rem(5)) {
// 문화인-파란색
1 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_blue)
}
// 진로탐색러-초록색
2 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_green)
}
// 탐험가-핑크색
3 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_pink)
}
// 경제인-빨간색
4 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_red)
}
// 봉사자-보라색
else -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_purple)
}
}
}
}

Expand All @@ -95,7 +56,4 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
replace<T>(R.id.container_main, T::class.java.canonicalName)
}
}

private fun ImageView.setImageDrawable(imgLikeBackground: Int) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MainViewModel @Inject constructor(
private val _userData = MutableLiveData<ResponseIdDto>()
val userData: LiveData<ResponseIdDto>
get() = _userData

private val _stateMessage = MutableLiveData<UiState>()
val stateMessage: LiveData<UiState>
get() = _stateMessage
Expand Down

0 comments on commit ac8999c

Please sign in to comment.