class FragmentPageAdapter(fragment: Fragment): FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 2
override fun createFragment(position: Int): Fragment {
return when(position) {
0 -> ReceivedFragment()
1 -> SentFragment()
else -> ReceivedFragment()
}
}
}
ReceiveFragment.kt
class ReceivedFragment : BaseFragment<FragmentReceivedBinding>(R.layout.fragment_received) {
private val viewModel by activityViewModels<ActiveViewModel>()
override fun setupObserve() {
viewModel.receivedList()
observeViewModel()
}
private fun observeViewModel() {
viewModel.receivedListData.observe(this, {
when(it.status) {
ResponseStatus.SUCCESS -> {
CLog.i("ReceivedFragment SUCCESS")
CLog.i("ReceivedFragment ${it.data.toString()}")
// binding.log.text = it.data.toString()
}
ResponseStatus.ERROR -> {
CLog.i("ReceivedFragment error ${it.message}")
}
ResponseStatus.LOADING -> {}
}
})
}
}
SentFragment.kt
class SentFragment : BaseFragment<FragmentSentBinding>(R.layout.fragment_sent) {
private val viewModel by activityViewModels<ActiveViewModel>()
override fun setupObserve() {
// 일단 보낸 메시지 확인
viewModel.sentList()
observeViewModel()
}
private fun observeViewModel() {
viewModel.sentListData.observe(this, {
when(it.status) {
ResponseStatus.SUCCESS -> {
CLog.i("SentListData SUCCESS")
CLog.i("SentListData ${it.data.toString()}")
// binding.log.text = it.data.toString()
}
ResponseStatus.ERROR -> {
CLog.i("SentListData error ${it.message}")
}
ResponseStatus.LOADING -> {}
}
})
}
}
'Study > Android' 카테고리의 다른 글
[Android] Coroutine, Retrofit을 활용한 비동기 네트워킹 처리 중 에러 핸들링 (0) | 2022.03.16 |
---|---|
JSON to Kotlin class 플러그인 으로 데이터 클래스 생성하기 (0) | 2022.03.11 |
코루틴 기본 개념 및 활용(CoroutineScope/GlobalScope/ViewModelScope/LifecycleScope) (1) | 2021.12.27 |
미디어 스토어 사진 가져오는 쿼리 (0) | 2021.11.30 |
앱 서명 jks -> pepk (0) | 2021.11.10 |