Skip to content

Commit

Permalink
✨ Feat: 모임 일정 편집 -> 친구 초대 화면 이동 시 이미 초대된 친구 표시해 주기
Browse files Browse the repository at this point in the history
- 화면 이동 시 참석자의 userId 목록 넘기기

Related to: #347
  • Loading branch information
nahy-512 committed Feb 14, 2025
1 parent 237442d commit c05b21c
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mongmong.namo.presentation.ui.community.moim.schedule

import android.text.Html
import android.util.Log
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.mongmong.namo.R
Expand All @@ -18,18 +19,29 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.

private val viewModel: FriendInviteViewModel by viewModels()

private lateinit var friendToInviteAdapter: FriendInvitePreparatoryRVAdapter
private lateinit var allFriendAdapter: FriendInviteRVAdapter
private var invitedFriendAdapter = FriendInviteRVAdapter(canEdit = false) // 초대한 친구
private lateinit var friendToInviteAdapter: FriendInvitePreparatoryRVAdapter // 초대할 친구
private var allFriendAdapter = FriendInviteRVAdapter(canEdit = true) // 모든 친구

override fun setup() {
binding.viewModel = viewModel

getDataFromScheduleScreen()
initClickListeners()
initObserve()
}

private fun getDataFromScheduleScreen() {
// moimScheduleId
intent.getLongExtra(MOIM_INVITE_KEY, 0L).let { moimScheduleId ->
viewModel.moimScheduleId = moimScheduleId
}

initClickListeners()
initObserve()
// 이미 초대된 참석자들의 id
intent.getLongArrayExtra(MOIM_PARTICIPANT_ID_KEY)?.let { memberIds ->
viewModel.invitedUserIdList = memberIds.toList()
binding.friendInviteInvitedFriendLl.visibility = View.VISIBLE
}
}

private fun initClickListeners() {
Expand All @@ -52,8 +64,21 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.

// 초대한 친구 현황 표시용
private fun setFriendSelectedNum() {
val totalCount = viewModel.remainFriendList.value?.size ?: viewModel.allFriendList.value?.size
// {초대할 친구 수} / {전체 친구 수}
binding.friendInviteSelectedNumTv.text = Html.fromHtml(String.format(resources.getString(R.string.moim_schedule_friend_invite_selected_num), viewModel.friendToInviteList.value?.size, viewModel.friendList.value?.size))
binding.friendInviteSelectedNumTv.text = Html.fromHtml(
String.format(resources.getString(R.string.moim_schedule_friend_invite_selected_num),
viewModel.friendToInviteList.value?.size,
totalCount)
)
}

// 초대된 친구 어댑터 설정
private fun setInvitedFriendAdapter() {
binding.friendInviteInvitedListRv.apply {
adapter = invitedFriendAdapter
layoutManager = LinearLayoutManager(context)
}
}

// 초대할 친구 어댑터 설정
Expand All @@ -77,7 +102,6 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.

// 모든 친구 어댑터 설정
private fun setAllFriendAdapter() {
allFriendAdapter = FriendInviteRVAdapter()
binding.friendInviteListRv.apply {
adapter = allFriendAdapter
layoutManager = LinearLayoutManager(context)
Expand All @@ -86,8 +110,10 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.
allFriendAdapter.setItemClickListener(object : FriendInviteRVAdapter.MyItemClickListener {
override fun onInviteButtonClick(isSelected: Boolean, position: Int) {
// 초대할 친구 목록에 추가
Log.d("FriendInviteACT", "onInviteButtonClick - isSelected: $isSelected, position: $position")
viewModel.updateSelectedFriend(isSelected, viewModel.friendList.value!![position])
// Log.d("FriendInviteACT", "onInviteButtonClick - isSelected: $isSelected, position: $position")
val friendToInvite = viewModel.remainFriendList.value?.let { it[position] }
?: viewModel.allFriendList.value!![position]
viewModel.updateSelectedFriend(isSelected, friendToInvite)
}

override fun onItemClick(position: Int) {
Expand All @@ -108,11 +134,16 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.
}

// 모든 친구
viewModel.friendList.observe(this) {
if (it.isNotEmpty()) {
viewModel.allFriendList.observe(this) { friendList ->
if (friendList.isNotEmpty()) {
setAllFriendAdapter()
}
allFriendAdapter.addFriend(it)
// 이미 초대된 친구
viewModel.setInvitedFriend()
setInvitedFriendAdapter()
invitedFriendAdapter.addFriend(viewModel.invitedFriendList)
// 모든 친구
allFriendAdapter.addFriend(viewModel.remainFriendList.value ?: friendList)
setFriendSelectedNum()
}

Expand All @@ -136,5 +167,6 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.

companion object {
const val MOIM_INVITE_KEY = "moim_invite_key"
const val MOIM_PARTICIPANT_ID_KEY = "moim_participant_id_key"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import androidx.lifecycle.viewModelScope
import com.mongmong.namo.domain.model.Friend
import com.mongmong.namo.domain.repositories.ScheduleRepository
import com.mongmong.namo.domain.usecases.friend.GetFriendsUseCase
import com.mongmong.namo.presentation.config.ApplicationClass.Companion.dsManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

@HiltViewModel
Expand All @@ -19,9 +22,18 @@ class FriendInviteViewModel @Inject constructor(
): ViewModel() {
var moimScheduleId: Long = 0L

var invitedUserIdList: List<Long>? = null

// 모든 친구 목록
private val _friendList = MutableLiveData<List<Friend>>()
val friendList: LiveData<List<Friend>> = _friendList
private val _allFriendList = MutableLiveData<List<Friend>>()
val allFriendList: LiveData<List<Friend>> = _allFriendList

// allFriend - invitedFriend
private val _remainFriendList = MutableLiveData<List<Friend>>()
val remainFriendList: LiveData<List<Friend>> = _remainFriendList

// 이미 초대된 친구
var invitedFriendList: List<Friend> = emptyList()

// 초대할 친구 목록
private val _friendToInviteList = MutableLiveData<ArrayList<Friend>>(ArrayList())
Expand All @@ -38,7 +50,7 @@ class FriendInviteViewModel @Inject constructor(
/** 친구 목록 조회 */
private fun getFriends() {
viewModelScope.launch {
_friendList.value = getFriendsUseCase.execute()
_allFriendList.value = getFriendsUseCase.execute()
}
}

Expand All @@ -51,6 +63,21 @@ class FriendInviteViewModel @Inject constructor(
}
}

// 초대된 친구 세팅
fun setInvitedFriend() {
if (invitedUserIdList.isNullOrEmpty()) return

// 초대된 친구
invitedFriendList = _allFriendList.value?.filter {
it.userId in invitedUserIdList!!
} ?: emptyList()

// 초대되고 남은 친구
_remainFriendList.value = _allFriendList.value?.filter {
it.userId !in invitedUserIdList!!
}
}

// 초대할 친구 선택 초기화
fun resetAllSelectedFriend() {
_friendToInviteList.value = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.mongmong.namo.presentation.ui.common.ConfirmDialog
import com.mongmong.namo.presentation.ui.common.ConfirmDialog.ConfirmDialogInterface
import com.mongmong.namo.presentation.ui.community.moim.MoimFragment.Companion.MOIM_CREATE_KEY
import com.mongmong.namo.presentation.ui.community.moim.schedule.FriendInviteActivity.Companion.MOIM_INVITE_KEY
import com.mongmong.namo.presentation.ui.community.moim.schedule.FriendInviteActivity.Companion.MOIM_PARTICIPANT_ID_KEY
import com.mongmong.namo.presentation.utils.PermissionChecker.hasImagePermission
import com.mongmong.namo.presentation.utils.converter.PickerConverter.setSelectedTime
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -116,8 +117,10 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.
binding.moimScheduleAddParticipantTv.setOnClickListener {
// 친구 추가하기 화면으로 이동
startActivity(
Intent(this, FriendInviteActivity::class.java)
.putExtra(MOIM_INVITE_KEY, viewModel.moimSchedule.value!!.moimId)
Intent(this, FriendInviteActivity::class.java).apply {
putExtra(MOIM_INVITE_KEY, viewModel.moimSchedule.value!!.moimId)
if (viewModel.getParticipantUserIdList().isNotEmpty()) putExtra(MOIM_PARTICIPANT_ID_KEY, viewModel.getParticipantUserIdList().toLongArray())
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.kakao.vectormap.LatLng
import com.mongmong.namo.domain.model.MoimScheduleDetail
import com.mongmong.namo.domain.model.Participant
import com.mongmong.namo.domain.model.SchedulePeriod
import com.mongmong.namo.domain.repositories.ScheduleRepository
import com.mongmong.namo.domain.usecases.image.UploadImageToS3UseCase
Expand Down Expand Up @@ -41,7 +40,6 @@ class MoimScheduleViewModel @Inject constructor(

var isCoverImageEdit: Boolean = false

//TODO: 참석자 수정
var participantIdsToAdd = ArrayList<Long>(arrayListOf()) // 스케줄에 추가할 유저 ID(userId)
var participantIdsToRemove = ArrayList<Long>(arrayListOf()) // 스케줄에서 삭제할 참가자 ID(participantId)

Expand Down Expand Up @@ -160,12 +158,6 @@ class MoimScheduleViewModel @Inject constructor(
)
}

fun updateMembers(selectedMember: List<Participant>) {
_moimSchedule.value = _moimSchedule.value!!.copy(
participants = selectedMember
)
}

// 시간 변경
fun updateTime(startDateTime: LocalDateTime?, endDateTime: LocalDateTime?) {
_moimSchedule.value = _moimSchedule.value?.copy(
Expand Down Expand Up @@ -215,6 +207,13 @@ class MoimScheduleViewModel @Inject constructor(
dsManager.getUserId().first() ?: 0L
}

// 모임 참석자들의 userId
fun getParticipantUserIdList(): List<Long> {
return _moimSchedule.value!!.participants.filter {
it.userId != getMyUserId() // 내 id 제외
}.map { it.userId }
}

companion object {
const val PREFIX = "cover"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.recyclerview.widget.RecyclerView
import com.mongmong.namo.databinding.ItemFriendInviteBinding
import com.mongmong.namo.domain.model.Friend

class FriendInviteRVAdapter: RecyclerView.Adapter<FriendInviteRVAdapter.ViewHolder>(){
class FriendInviteRVAdapter(
val canEdit: Boolean? = true
): RecyclerView.Adapter<FriendInviteRVAdapter.ViewHolder>(){

private var friendList = emptyList<Friend>()
private var isFriendSelectedList = mutableListOf<Boolean>()
Expand Down Expand Up @@ -75,6 +77,7 @@ class FriendInviteRVAdapter: RecyclerView.Adapter<FriendInviteRVAdapter.ViewHold
inner class ViewHolder(val binding: ItemFriendInviteBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(friend: Friend) {
binding.friend = friend
binding.canEdit = canEdit
}
}
}
37 changes: 34 additions & 3 deletions app/src/main/res/layout/activity_friend_invite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:visibility="@{viewModel.friendList.empty ? View.VISIBLE : View.GONE}"
android:visibility="@{viewModel.allFriendList.empty ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="@id/friend_invite_search_btn"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -174,6 +174,37 @@

</LinearLayout>

<!-- 초대된 친구 -->
<LinearLayout
android:id="@+id/friend_invite_invited_friend_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginHorizontal="25dp"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/friend_invite_reset_ll">

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/moim_schedule_invited_friend"
style="@style/content_bold"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/friend_invite_invited_list_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_friend_invite"
tools:itemCount="2"
app:layout_constraintTop_toBottomOf="@id/friend_search_et"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

</LinearLayout>

<!-- 모든 친구 -->
<LinearLayout
android:id="@+id/friend_invite_all_friend_ll"
Expand All @@ -182,7 +213,7 @@
android:layout_marginTop="20dp"
android:layout_marginHorizontal="25dp"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/friend_invite_reset_ll">
app:layout_constraintTop_toBottomOf="@id/friend_invite_invited_friend_ll">

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
Expand All @@ -195,7 +226,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:visibility="@{viewModel.friendList.empty ? View.GONE : View.VISIBLE}"
android:visibility="@{viewModel.allFriendList.empty ? View.GONE : View.VISIBLE}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_friend_invite"
app:layout_constraintTop_toBottomOf="@id/friend_search_et"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/item_friend_invite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
xmlns:tools="http://schemas.android.com/tools">

<data>
<import type="android.view.View"/>
<variable
name="canEdit"
type="Boolean" />
<variable
name="friend"
type="com.mongmong.namo.domain.model.Friend"/>
Expand Down Expand Up @@ -84,6 +88,7 @@
android:layout_height="28dp"
android:checked="false"
android:button="@null"
android:visibility="@{canEdit ? View.VISIBLE : View.GONE}"
android:background="@drawable/selector_invite"/>

</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
<string name="moim_schedule_invite_friend_reset">전체 선택 취소</string>
<string name="moim_schedule_friend_invite_selected_num"><![CDATA[<font color=\'#DA6022\'>%d</font> / %d]]></string> <!-- 선택 인원수 / 전체 친구 수 -->
<string name="moim_schedule_do_invite">초대하기</string>
<string name="moim_schedule_invited_friend">초대된 친구</string>
<string name="moim_schedule_all_friend">모든 친구</string>
<string name="moim_schedule_invite_friend_empty">아직 추가된 친구가 없어요.\n친구를 추가한 후 모임을 만들어보세요!</string>
<string name="moim_schedule_add_guest">게스트 초대하기</string>
Expand Down

0 comments on commit c05b21c

Please sign in to comment.