Skip to content

Commit

Permalink
[ADD/#54] 선택된 아이템 개수 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Jul 19, 2023
1 parent 3046d39 commit 64c2474
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,19 @@ class OnBoardingViewModel @Inject constructor(
private val _studentIdResult: MutableLiveData<List<Int>> = MutableLiveData()
val studentIdResult: LiveData<List<Int>> = _studentIdResult


private val _friendState = MutableLiveData<FriendList>()
val friendState: LiveData<FriendList> = _friendState

var kakaoFriendList: List<String> = listOf()
var selectedFriendIdList : List<Long> = listOf()
var selectedFriendCount: Int = 0
var selectedFriendCount: MutableLiveData<Int> = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import com.yello.util.context.yelloSnackbar
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AddFriendFragment :
BindingFragment<FragmentAddfreindBinding>(R.layout.fragment_addfreind) {
class AddFriendFragment : BindingFragment<FragmentAddfreindBinding>(R.layout.fragment_addfreind) {

private var adapter: AddFriendAdapter? = null

Expand All @@ -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)
}
Expand All @@ -58,7 +57,6 @@ class AddFriendFragment :

private fun setConfirmBtnClickListener() {
binding.btnAddfriendNext.setOnSingleClickListener {
Log.d("sangho", "${selectedItemIdList}")
viewModel.selectedFriendIdList = selectedItemIdList
viewModel.navigateToNextPage()
}
Expand All @@ -85,8 +83,7 @@ class AddFriendFragment :
private fun addFriendListFromServer() {
viewModel.addFriendList(
FriendGroup(
viewModel.kakaoFriendList,
viewModel.groupId
viewModel.kakaoFriendList, viewModel.groupId
)
)
}
Expand All @@ -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()
}
}
Expand All @@ -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()
}
}

Expand Down

0 comments on commit 64c2474

Please sign in to comment.