diff --git a/app/src/main/java/com/yello/presentation/onboarding/activity/OnBoardingViewModel.kt b/app/src/main/java/com/yello/presentation/onboarding/activity/OnBoardingViewModel.kt index a963ffc42..1179c1e26 100644 --- a/app/src/main/java/com/yello/presentation/onboarding/activity/OnBoardingViewModel.kt +++ b/app/src/main/java/com/yello/presentation/onboarding/activity/OnBoardingViewModel.kt @@ -108,17 +108,19 @@ class OnBoardingViewModel @Inject constructor( private val _studentIdResult: MutableLiveData> = MutableLiveData() val studentIdResult: LiveData> = _studentIdResult + private val _friendState = MutableLiveData() val friendState: LiveData = _friendState var kakaoFriendList: List = listOf() var selectedFriendIdList : List = listOf() - var selectedFriendCount: Int = 0 + var selectedFriendCount: MutableLiveData = MutableLiveData(0) private var currentFriendPage: Int = -1 private var isFriendPagingFinish = false private var totalFriendPage = Int.MAX_VALUE + // TODO: throttle 및 페이징 처리 fun getSchoolList(search: String) { // if (isSchoolPagingFinish) return diff --git a/app/src/main/java/com/yello/presentation/onboarding/fragment/addfriend/AddFriendFragment.kt b/app/src/main/java/com/yello/presentation/onboarding/fragment/addfriend/AddFriendFragment.kt index ece19feb7..6cb2aa66f 100644 --- a/app/src/main/java/com/yello/presentation/onboarding/fragment/addfriend/AddFriendFragment.kt +++ b/app/src/main/java/com/yello/presentation/onboarding/fragment/addfriend/AddFriendFragment.kt @@ -18,8 +18,7 @@ import com.yello.util.context.yelloSnackbar import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class AddFriendFragment : - BindingFragment(R.layout.fragment_addfreind) { +class AddFriendFragment : BindingFragment(R.layout.fragment_addfreind) { private var adapter: AddFriendAdapter? = null @@ -46,10 +45,10 @@ class AddFriendFragment : friend.isSelected = !friend.isSelected if (friend.isSelected && friend.id !in selectedItemIdList) { selectedItemIdList.add(friend.id) - ++viewModel.selectedFriendCount + viewModel.selectedFriendCount.value = viewModel.selectedFriendCount.value?.plus(1) } else { selectedItemIdList.remove(friend.id) - --viewModel.selectedFriendCount + viewModel.selectedFriendCount.value = viewModel.selectedFriendCount.value?.minus(1) } adapter?.notifyItemChanged(position) } @@ -58,7 +57,6 @@ class AddFriendFragment : private fun setConfirmBtnClickListener() { binding.btnAddfriendNext.setOnSingleClickListener { - Log.d("sangho", "${selectedItemIdList}") viewModel.selectedFriendIdList = selectedItemIdList viewModel.navigateToNextPage() } @@ -85,8 +83,7 @@ class AddFriendFragment : private fun addFriendListFromServer() { viewModel.addFriendList( FriendGroup( - viewModel.kakaoFriendList, - viewModel.groupId + viewModel.kakaoFriendList, viewModel.groupId ) ) } @@ -98,10 +95,7 @@ class AddFriendFragment : super.onScrolled(recyclerView, dx, dy) if (dy > 0) { recyclerView.layoutManager?.let { layoutManager -> - if (!binding.rvFreindList.canScrollVertically(1) && - layoutManager is LinearLayoutManager && - layoutManager.findLastVisibleItemPosition() == adapter!!.itemCount - 1 - ) { + if (!binding.rvFreindList.canScrollVertically(1) && layoutManager is LinearLayoutManager && layoutManager.findLastVisibleItemPosition() == adapter!!.itemCount - 1) { addFriendListFromServer() } } @@ -116,7 +110,8 @@ class AddFriendFragment : friendsList = it.friendList adapter?.submitList(friendsList) selectedItemIdList.addAll(friendsList.map { friend -> friend.id }) - viewModel.selectedFriendCount += friendsList.size + viewModel.selectedFriendCount.value = viewModel.selectedFriendCount.value?.plus(friendsList.size) + adapter?.notifyDataSetChanged() } }